| 1 |
%% Documentation for colortab.tex/colortab.sty. |
| 2 |
%% |
| 3 |
%% The color commands \gray and \lightgray must be defined if you |
| 4 |
%% want to see the examples. pstricks.tex will be loaded for this |
| 5 |
%% purpose if it is found. Otherwise, you must load your own |
| 6 |
%% color commands. |
| 7 |
%% |
| 8 |
%% Change these if using different size paper. You can also include the |
| 9 |
%% twosided style option, if desired: |
| 10 |
|
| 11 |
\documentclass[12pt]{article} |
| 12 |
\usepackage [T1]{fontenc} |
| 13 |
\usepackage{mathpazo,fancybox,url} |
| 14 |
\usepackage{pstricks,colortab} |
| 15 |
\let\CTfv\fileversion |
| 16 |
\newgray{lightgray}{0.5} |
| 17 |
\newgray{gray}{1} |
| 18 |
\makeatletter |
| 19 |
% VERBATIM HACKS: |
| 20 |
\VerbatimFootnotes |
| 21 |
|
| 22 |
% Short meta (works in verbatim. Can't use < for other purposes. |
| 23 |
\catcode`\<=13 \def<#1>{{\rm\it #1\/}} % <meta> (works in verbatim) |
| 24 |
|
| 25 |
% Short verbatim. " can appear in verbatim environments. |
| 26 |
\def\temp{\Verb"} |
| 27 |
\expandafter\def\expandafter\dospecials\expandafter{\dospecials\do\"} |
| 28 |
\catcode`\"=13 |
| 29 |
\let"\temp |
| 30 |
|
| 31 |
\def\n#1{{\tt\string#1}} |
| 32 |
|
| 33 |
% Verbatim item: |
| 34 |
\newcommand\vitem{\SaveVerb[{\def\bf{}\item[\UseVerb{\MyTemp}]}]{\MyTemp}} |
| 35 |
|
| 36 |
% Verbatim section" |
| 37 |
|
| 38 |
% EXAMPLES: |
| 39 |
% 1. Save example verbatim to \jobname.tmp, |
| 40 |
% 2. Input verbatim with \catcode`\"=14 (" is a comment). |
| 41 |
% 3. Input again with \catcode\`"=9 (" is ignored). |
| 42 |
|
| 43 |
\renewcommand{\EveryVerbatimLine}[2]{} |
| 44 |
\renewcommand{\EveryVerbOutLine}[2]{} |
| 45 |
\newcommand\BeginExample{% |
| 46 |
\VerbatimEnvironment\begin{VerbatimOut}{\jobname.tmp}} |
| 47 |
\newcommand\EndExample{% |
| 48 |
\end{VerbatimOut}%. |
| 49 |
\renewcommand{\EveryVerbatimLine}{}% |
| 50 |
\renewcommand{\EveryVerbatimCodes}{\catcode`\"=14}% |
| 51 |
\LVerbatimInput{\jobname.tmp}% |
| 52 |
\catcode`\"=9} |
| 53 |
|
| 54 |
\iftrue% always using color |
| 55 |
\newenvironment{example}{\BeginExample}{\EndExample |
| 56 |
\begin{center}\leavevmode\input{\jobname.tmp}\end{center}} |
| 57 |
\else |
| 58 |
\newenvironment{example}{\VerbatimEnvironment\LVerbatim}{\endLVerbatim} |
| 59 |
\fi |
| 60 |
|
| 61 |
% END PREAMBLE: |
| 62 |
\makeatother |
| 63 |
\title{Documentation\thanks{Documentation revised by Herbert Vo\ss} for colortab:\\[5pt] |
| 64 |
Shading and coloring \TeX\ tables, v. \CTfv} |
| 65 |
\author{Timothy Van Zandt\\ \url{[email protected]}} |
| 66 |
\date{\today} |
| 67 |
|
| 68 |
\begin{document} |
| 69 |
|
| 70 |
\maketitle |
| 71 |
\tableofcontents |
| 72 |
|
| 73 |
\begin{quote} |
| 74 |
"colortab.tex/colortab.sty" contains macros that let you use your color |
| 75 |
commands for shading and coloring cells in tables and other alignment |
| 76 |
environments. It is compatible with most \TeX\ macro packages. |
| 77 |
\end{quote} |
| 78 |
|
| 79 |
\section{Introduction} |
| 80 |
|
| 81 |
Adding color to tables is fraught with difficulties, but as the examples in |
| 82 |
this file indicate, it can be done. In any case, consider this an advanced |
| 83 |
topic, and be aware that the commands in "colortab.tex" are not robust. |
| 84 |
|
| 85 |
This is meant to supplement your own color commands. There are many macro |
| 86 |
files that implement color for the various "dvi" drivers that can support |
| 87 |
color. E.g., the PSTricks package works with a variety of DVI-to-PS drivers. |
| 88 |
|
| 89 |
For example, suppose you have a macro that defines the color command "\gray". |
| 90 |
"colortab.tex" requires that one of the following produce a gray line: |
| 91 |
\begin{LVerbatim} |
| 92 |
{\gray \hrule} |
| 93 |
\gray{\hrule} |
| 94 |
\end{LVerbatim} |
| 95 |
if you want to use this command to color the cells in tables. |
| 96 |
This is probably the case if the one of the following produces gray text: |
| 97 |
\begin{LVerbatim} |
| 98 |
{\gray I am gray!} |
| 99 |
\gray{I am gray!} |
| 100 |
\end{LVerbatim} |
| 101 |
|
| 102 |
"colortab.tex" contains macros for \TeX's "\halign" primitive. Incorporating |
| 103 |
color into high-level macros based on the "\halign" primitive requires a |
| 104 |
case-by-case treatment. "colortab.tex" also contains macros for coloring cells |
| 105 |
\LaTeX's various array environments, and for the \LaTeX\ "longtable" |
| 106 |
environment that is defined in the "longtable" (or "longtabl") style option. |
| 107 |
These can serve as examples that can be accommodated to other table macros. |
| 108 |
See the code itself for happy hacking. |
| 109 |
|
| 110 |
\section{\TeX's halign primitive} |
| 111 |
|
| 112 |
To shade cells in an alignment, use |
| 113 |
\begin{LVerbatim} |
| 114 |
\coloralign |
| 115 |
\end{LVerbatim} |
| 116 |
instead of "\halign". Then, to color the columns in one or more rows, type |
| 117 |
\begin{LVerbatim} |
| 118 |
\CC |
| 119 |
<row of colors>\cr |
| 120 |
<rows to be colored>\cr |
| 121 |
\ECC |
| 122 |
\end{LVerbatim} |
| 123 |
For example: |
| 124 |
\begin{example} |
| 125 |
\setbox\strutbox=\hbox{\vrule height11.5pt |
| 126 |
depth6.5pt width0pt}% |
| 127 |
\vbox{\offinterlineskip |
| 128 |
\coloralign{% |
| 129 |
\vrule\strut\quad\hfil#\hfil\quad |
| 130 |
&\vrule\quad\hfil#\quad\vrule\cr |
| 131 |
\noalign{\hrule}% |
| 132 |
\CC |
| 133 |
\gray &\cr |
| 134 |
Tamarind&Chiplote\cr |
| 135 |
\ECC\noalign{\hrule}% |
| 136 |
\CC |
| 137 |
\lightgray &\gray\cr |
| 138 |
Lulu&Serrano\cr\noalign{\hrule}% |
| 139 |
Guanabana&Larga\cr |
| 140 |
\ECC\noalign{\hrule}% |
| 141 |
}} |
| 142 |
\end{example} |
| 143 |
|
| 144 |
"\CC" and "\ECC" stand for ``ColorCells'' and ``EndColorCells'', respectively. |
| 145 |
You cannot change the name of "\ECC" with "\let" or "\def" (without redefining |
| 146 |
"\CC"), because it is really just a delimiter. This is also true of the first |
| 147 |
"\cr", which marks the end of the row of color commands. |
| 148 |
Remember that only complete rows can go between "\CC" and "\ECC". Where you |
| 149 |
include horizontal lines is generally inconsequential. You can have nested |
| 150 |
"\coloralign" environments, but the nested environment must be enclosed in |
| 151 |
brackets "{}". There is no "\coloralign to" or "\coloralign spread" because |
| 152 |
the space inserted by "\tabskip" won't be shaded. |
| 153 |
|
| 154 |
These macros are not very robust. You can make best use of them by knowing how |
| 155 |
they work. "\coloralign" just saves the preamble, and otherwise is identical |
| 156 |
to "\halign". "\CC" finds the height of the rows that have to be colored, and |
| 157 |
then "\CC" draws a rectangle using \TeX's line-drawing primitives in each |
| 158 |
cell, colored by the color commands included in the first line that follows |
| 159 |
"\CC". E.g., |
| 160 |
\begin{LVerbatim} |
| 161 |
\yellow &&\red \cr |
| 162 |
\end{LVerbatim} |
| 163 |
draws a yellow rectangle in column 1, nothing in column 2, and a red rectangle |
| 164 |
in column 3. Then "\CC" goes back up the height of the rectangle, so that |
| 165 |
\TeX's current point is back where it was when "\CC" started. At this point, |
| 166 |
"\CC" has finished its work. When the next rows of the alignment environment |
| 167 |
are processed by "\halign", they are put down on top of the rectangles, and |
| 168 |
hence have colored backgrounds. |
| 169 |
|
| 170 |
"\CC" finds the height of the rows to be colored by putting the rows into an |
| 171 |
"\halign" environment, using the preamble that was saved by "\coloralign", and |
| 172 |
then measuring the height of the resulting box. |
| 173 |
|
| 174 |
\section{\LaTeX\ array environments} |
| 175 |
|
| 176 |
Cells can be colored in a \LaTeX\ array without using a special array |
| 177 |
environment (i.e., there is no \LaTeX\ analog to "\coloralign"). Use "\LCC" |
| 178 |
instead of "\CC", and use "\\" to end the row of color commands instead of |
| 179 |
"\cr". For example: |
| 180 |
\begin{example} |
| 181 |
\def\arraystretch{1.5}% |
| 182 |
\begin{tabular}{|l|c|}\hline |
| 183 |
\LCC |
| 184 |
\gray & \\ |
| 185 |
Tamarind & Chiplote \\ \hline |
| 186 |
\ECC |
| 187 |
\LCC |
| 188 |
\lightgray & \gray\\ |
| 189 |
Lulu & Serrano\\ \hline |
| 190 |
Guanabana & Larga\\ \hline |
| 191 |
\ECC |
| 192 |
\end{tabular} |
| 193 |
\end{example} |
| 194 |
The same caveats apply as with the "\coloralign" environment. |
| 195 |
|
| 196 |
When \n\LCC\ and \n\ECC\ are used with Frank Mittelbach's "array.sty", nested |
| 197 |
array-type environments and "\multicolumn" commands wipe out information |
| 198 |
needed by \n\ECC\. Here is a workaround: Put "\SP" (``SavePreamble'') at the |
| 199 |
beginning of the array-type environment (right after the column declarations), |
| 200 |
and put "\RP" (``RestorePreamble'') at the end of each line containing a |
| 201 |
"\multicolumn" command or nested array-type environment (after the "\\", and |
| 202 |
before the \n\ECC). For example: |
| 203 |
\begin{LVerbatim} |
| 204 |
\begin{tabular}{|l|c|}\SP\hline |
| 205 |
\LCC |
| 206 |
\gray & \\ |
| 207 |
\multicolumn{2}{c}{Tamarind}\\ \RP \hline |
| 208 |
\ECC |
| 209 |
\end{tabular} |
| 210 |
\end{LVerbatim} |
| 211 |
Further nesting (e.g., an array within a "\multicolumn", or a "\multicolumn" |
| 212 |
or array within a nested array) sometimes works and sometimes doesn't. You |
| 213 |
will have to figure that one out for yourself. |
| 214 |
|
| 215 |
|
| 216 |
\section{longtable.sty} |
| 217 |
|
| 218 |
"longtable.sty", by David Carlisle, defines the "longtable" environment, for |
| 219 |
making multipage tables. "\LCC" will not work with "longtable". However, |
| 220 |
"colortab" contains other macros that will work, if you use "longtable.sty" in |
| 221 |
conjunction with Frank Mittelbach's "array.sty". These macros have been tested |
| 222 |
only briefly, with version 3.04 of "longtable.sty" and version 2.1b of |
| 223 |
"array.sty". |
| 224 |
|
| 225 |
Before every column identifier in the environment's argument (e.g., "c", "l", |
| 226 |
"r", "p", "m" or "b"), put |
| 227 |
\begin{description} |
| 228 |
\vitem"!{\LC}" If none of the below applies; |
| 229 |
\vitem"!{\LCi}" If the column is preceded by one or more vertical lines; |
| 230 |
\vitem"!{\LCii}" If the column is followed by two vertical lines; |
| 231 |
\vitem"!{\LCiii}" If the column is preceded by one or more vertical lines |
| 232 |
and followed by two vertical lines. |
| 233 |
\vitem"!{\LCz{<len1>}{<len2>}}" If "colortab" should back up by <len1> |
| 234 |
before drawing the background, and should draw the background <len2> shorter |
| 235 |
than the width of the column. |
| 236 |
\end{description} |
| 237 |
Remember that you have to do this for every column, not just the columns that |
| 238 |
you want to color. |
| 239 |
|
| 240 |
Then include |
| 241 |
\begin{LVerbatim} |
| 242 |
\LColors <color> & <color> & ... & <color>\\ |
| 243 |
\end{LVerbatim} |
| 244 |
in the first row of the environment, and later on as well if you wish to |
| 245 |
change the colors. Here also you have to include every column, but you can |
| 246 |
leave an entry blank if you don't want any background color in that column. |
| 247 |
|
| 248 |
The color comes out right, or at all, only after you have run the file enough |
| 249 |
times for "longtable.sty" to set the alignment correctly. |
| 250 |
|
| 251 |
Here is an example. The output will appear in this documentation only if |
| 252 |
"longtable.sty" or "longtabl.sty" is installed on your system. |
| 253 |
\begingroup |
| 254 |
\makeatletter |
| 255 |
\catcode`\<=12 |
| 256 |
% Modification Denis GIROU (CNRS/IDRIS - France) - <[email protected]> - 10 Sep. 1996 |
| 257 |
% Can't work with LaTeX 2e |
| 258 |
% \@input{longtable.sty}% |
| 259 |
% \@input{longtabl.sty}% |
| 260 |
% \@input{array.sty}% |
| 261 |
\@input{longtable.styX}% Avoid loading of longtable.sty... |
| 262 |
\@input{longtabl.sty}% |
| 263 |
\@input{array.styX}% Avoid loading of array.sty... |
| 264 |
\@testtrue |
| 265 |
\@ifundefined{c@LT@tables}{\@testfalse}{}% |
| 266 |
\@ifundefined{d@llarbegin}{\@testfalse}{}% |
| 267 |
\if@test\else |
| 268 |
\renewenvironment{example}{\VerbatimEnvironment\LVerbatim}{\endLVerbatim}% |
| 269 |
\fi |
| 270 |
\makeatother |
| 271 |
\begin{example} |
| 272 |
\LARGE |
| 273 |
\begin{longtable}{|!{\LCiii}l||!{\LCi}c|!{\LCi}c|}\hline |
| 274 |
\LColors \gray & & \\ |
| 275 |
Tamarind & Chiplote & Galanga\\ \hline |
| 276 |
\LColors \lightgray & & \gray\\ |
| 277 |
Lulu & & Serrano\\ \hline |
| 278 |
Guanabana & Larga &\\ \hline |
| 279 |
\end{longtable} |
| 280 |
\end{example} |
| 281 |
\endgroup |
| 282 |
|
| 283 |
\section{Coloring lines} |
| 284 |
|
| 285 |
Let's begin with the "\halign" environment. Changing the color of lines is |
| 286 |
easy, because if you write, say, "{\gray\hrule}", then the line comes out |
| 287 |
gray. For example: |
| 288 |
\begin{example} |
| 289 |
% Thicker lines and wider spacing give better view: |
| 290 |
\setbox\strutbox=\hbox{% |
| 291 |
\vrule height15.5pt depth8.5pt width0pt}% |
| 292 |
\def\Hrule{\hrule height 2.5pt}% |
| 293 |
\def\Vrule{\vrule width 2.5pt}% |
| 294 |
% Now the table: |
| 295 |
\vbox{\offinterlineskip |
| 296 |
\halign{% |
| 297 |
{\lightgray\Vrule}\strut\quad\hfil#\hfil\quad |
| 298 |
&{\gray\Vrule}\quad\hfil#\quad\Vrule\cr |
| 299 |
\noalign{\Hrule}% |
| 300 |
Tamarind& Chiplote\cr\noalign{{\darkgray\Hrule}}% |
| 301 |
Lulu& Serrano\cr\noalign{\Hrule}% |
| 302 |
Guanabana& Larga\cr\noalign{{\lightgray\Hrule}}% |
| 303 |
}} |
| 304 |
\end{example} |
| 305 |
|
| 306 |
With \LaTeX, you can add an entry like |
| 307 |
\begin{LVerbatim} |
| 308 |
@{\hspace{\tabcolsep}{\gray\vrule}\hspace{\tabcolsep}} |
| 309 |
\end{LVerbatim} |
| 310 |
to the argument of the alignment environment, instead of "|", if you want to |
| 311 |
color the vertical line that is drawn. If using "array.sty", you can try: |
| 312 |
\begin{LVerbatim} |
| 313 |
!{{\gray\vrule}} |
| 314 |
\end{LVerbatim} |
| 315 |
|
| 316 |
To color horizontal lines with \LaTeX, don't bother trying |
| 317 |
\begin{LVerbatim} |
| 318 |
{\gray\hline} |
| 319 |
\end{LVerbatim} |
| 320 |
because it won't work. You write your own version of "\hline" and "\cline", or |
| 321 |
use the non-aligned color commands described in the next section. |
| 322 |
|
| 323 |
\section{Non-aligned color with PSTricks} |
| 324 |
|
| 325 |
Here are a few other commands that can be useful for adding color to tables. |
| 326 |
{\bf They only work with PSTricks, v0.93 or later.} <color> in this case is |
| 327 |
the name of the color, without the backslash. These fudge the color commands |
| 328 |
so that they do not have to be balanced with respect to \TeX\ grouping. You |
| 329 |
can achieve the same thing using "\special{<raw postscript>}" and "\noalign", |
| 330 |
if you know what you are doing. These should work with just about any |
| 331 |
alignment macro, include "\halign" and \LaTeX's "tabular" environment. |
| 332 |
|
| 333 |
\begin{description} |
| 334 |
|
| 335 |
\vitem"\AC{<color>} ... \EAC" \ |
| 336 |
|
| 337 |
These stand for "AlignColor" and "EndAlignColor", respectively. <color> is |
| 338 |
the name of the color, without a backslash, rather than a color command. This |
| 339 |
can be used within a cell, but they do not have to be within the same cell, |
| 340 |
nor do they have to be properly nested with respect to \TeX\ grouping. |
| 341 |
Generally, "\AC{<color>}" switches to <color>, and \n\EAC\ restores the color |
| 342 |
that would be in effect if the first \n\AC\ command were missing. |
| 343 |
|
| 344 |
\vitem"\NAC{<color>} ... \ENAC" \ |
| 345 |
|
| 346 |
These stand for "NoAlignColor" and "EndNoAlignColor", respectively. These |
| 347 |
are like \n\AC\ and \n\EAC, but the color commands are put inside a |
| 348 |
"\noalign". They can only appear at the end of a line, after "\\" or "\cr". |
| 349 |
|
| 350 |
\end{description} |
| 351 |
Actually, these do not even have to be used in pairs. |
| 352 |
|
| 353 |
Here is an example of how "\AC", etc., can be used. to color lines in \LaTeX\ |
| 354 |
arrays. The output will appear in this documentation only if PSTricks is |
| 355 |
installed on your system: |
| 356 |
\begingroup |
| 357 |
\ifx\PSTricksLoaded\endinput\else |
| 358 |
\renewenvironment{example}{\VerbatimEnvironment\LVerbatim}{\endLVerbatim} |
| 359 |
\fi |
| 360 |
\begin{example} |
| 361 |
\arrayrulewidth 1.5pt |
| 362 |
\begin{tabular}{|l|c|}\hline |
| 363 |
Tamarind& Chiplote\\ \NAC{gray}\hline\ENAC |
| 364 |
Lulu& Serrano\\ \cline{1-1} |
| 365 |
\NAC{lightgray}\cline{2-2}\ENAC |
| 366 |
Guanabana\AC{lightgray} & \EAC Larga\\ \hline |
| 367 |
\end{tabular} |
| 368 |
\end{example} |
| 369 |
\endgroup |
| 370 |
|
| 371 |
\end{document} |
| 372 |
%% END colortab.doc |