3
\def\FileDate{1997/03/28}
5
%% Documentation for colortab.tex/colortab.sty.
6
%% Run through LaTeX, with or without the NFSS.
8
%% You need the file fancybox.sty, available from Princeton.EDU:/pub/tvz
10
%% The color commands \gray and \lightgray must be defined if you
11
%% want to see the examples. pstricks.tex will be loaded for this
12
%% purpose if it is found. Otherwise, you must load your own
15
%% Change these if using different size paper. You can also include the
16
%% twosided style option, if desired:
18
\def\paperwidth{8.5in}
19
\def\paperheight{11in}
21
\documentstyle[12pt,fancybox]{article}
25
% Load pstricks.tex if it is found:
28
% Input colortab.tex here to check file version:
30
\ifx\FileVersion\fileversion\else
31
\@latexerr{colortab input file and documentation do not have the same
35
% DATES, VERSIONS AND TITLES:
37
\def\expanddate#1/#2/#3/{\year=19#1 \month=#2 \day=#3}
39
\expandafter\expanddate\filedate/
40
\xdef\thefiledate{\today}
43
\title{Documentation for colortab.tex/colortab.sty:\\[5pt]
44
Shading and coloring \TeX\ tables}
45
\author{Timothy Van Zandt\\ tvz@Princeton.EDU}
46
\date{Version \fileversion\\ \thefiledate}
50
{\Large\bf \@title \par}
51
\vskip 1.2em {\lineskip .5em
52
\begin{tabular}[t]{c}\@author\end{tabular}\par}
60
\pagestyle{myheadings}
62
\markboth{Documentation for colortab.tex/.sty}%
63
{Version \fileversion, \thefiledate}%
65
\markright{colortab.tex, Version \fileversion}
72
\def\tableofcontents{%
75
\begin{center} \Large\bf Contents \end{center}
76
\def\numberline##1{\hbox to 0pt{\hss##1\hskip 1em}}%
77
\let\oldaddvspace\addvspace
80
\oldaddvspace{.5\myskip}}
90
% Paragraphs are marked by large space rather than indentation:
92
\parskip 7pt plus 1pt minus 1pt
94
\setlength{\topmargin}{0pt}
95
\setlength{\headheight}{12pt} % height of running head
96
\setlength{\headsep}{30pt} % distance between header and text
97
\setlength{\textheight}{8.2in} % height of text on page
99
% Adjust margins for different paper size:
100
\@tempdima=\paperwidth
101
\advance\@tempdima-8.5in
102
\advance\oddsidemargin .5\@tempdima
103
\advance\evensidemargin .5\@tempdima
104
\@tempdima=\paperheight
105
\advance\@tempdima-11in
106
\advance\topmargin .5\@tempdima
112
% Short meta (works in verbatim. Can't use < for other purposes.
113
\catcode`\<=13 \def<#1>{{\rm\it #1\/}} % <meta> (works in verbatim)
115
% Short verbatim. " can appear in verbatim environments.
117
\expandafter\def\expandafter\dospecials\expandafter{\dospecials\do\"}
121
\def\n#1{{\tt\string#1}}
124
\newcommand{\vitem}{\SaveVerb[{\def\bf{}\item[\UseVerb{\MyTemp}]}]{\MyTemp}}
129
% 1. Save example verbatim to \jobname.tmp,
130
% 2. Input verbatim with \catcode`\"=14 (" is a comment).
131
% 3. Input again with \catcode\`"=9 (" is ignored).
133
\renewcommand{\EveryVerbatimLine}[2]{}
135
\renewcommand{\EveryVerbOutLine}[2]{}
137
\newcommand{\BeginExample}{%
138
\VerbatimEnvironment\begin{VerbatimOut}{\jobname.tmp}}
140
\newcommand{\EndExample}{%
142
\renewcommand{\EveryVerbatimLine}{}%
143
\renewcommand{\EveryVerbatimCodes}{\catcode`\"=14}%
144
\LVerbatimInput{\jobname.tmp}%
147
\@ifundefined{lightgray}{\@testfalse}%
148
{\@ifundefined{gray}{\@testfalse}{\@testtrue}}
152
\newenvironment{example}{\BeginExample}{\EndExample
153
\begin{center}\leavevmode\input{\jobname.tmp}\end{center}}
157
\newenvironment{example}{\VerbatimEnvironment\LVerbatim}{\endLVerbatim}
169
"colortab.tex/colortab.sty" contains macros that let you use your color
170
commands for shading and coloring cells in tables and other alignment
171
environments. It is compatible with most \TeX\ macro packages.
176
\section{Introduction}
178
Adding color to tables is fraught with difficulties, but as the examples in
179
this file indicate, it can be done. In any case, consider this an advanced
180
topic, and be aware that the commands in "colortab.tex" are not robust.
182
This is meant to supplement your own color commands. There are many macro
183
files that implement color for the various "dvi" drivers that can support
184
color. E.g., the PSTricks package works with a variety of DVI-to-PS drivers.
186
For example, suppose you have a macro that defines the color command "\gray".
187
"colortab.tex" requires that one of the following produce a gray line:
192
if you want to use this command to color the cells in tables.
193
This is probably the case if the one of the following produces gray text:
199
"colortab.tex" contains macros for \TeX's "\halign" primitive. Incorporating
200
color into high-level macros based on the "\halign" primitive requires a
201
case-by-case treatment. "colortab.tex" also contains macros for coloring cells
202
\LaTeX's various array environments, and for the \LaTeX\ "longtable"
203
environment that is defined in the "longtable" (or "longtabl") style option.
204
These can serve as examples that can be accommodated to other table macros.
205
See the code itself for happy hacking.
207
\section{\TeX's halign primitive}
209
To shade cells in an alignment, use
213
instead of "\halign". Then, to color the columns in one or more rows, type
217
<rows to be colored>\cr
222
\setbox\strutbox=\hbox{\vrule height11.5pt
223
depth6.5pt width0pt}%
224
\vbox{\offinterlineskip
226
\vrule\strut\quad\hfil#\hfil\quad
227
&\vrule\quad\hfil#\quad\vrule\cr
232
\ECC\noalign{\hrule}%
235
Lulu&Serrano\cr\noalign{\hrule}%
237
\ECC\noalign{\hrule}%
241
"\CC" and "\ECC" stand for ``ColorCells'' and ``EndColorCells'', respectively.
242
You cannot change the name of "\ECC" with "\let" or "\def" (without redefining
243
"\CC"), because it is really just a delimiter. This is also true of the first
244
"\cr", which marks the end of the row of color commands.
245
Remember that only complete rows can go between "\CC" and "\ECC". Where you
246
include horizontal lines is generally inconsequential. You can have nested
247
"\coloralign" environments, but the nested environment must be enclosed in
248
brackets "{}". There is no "\coloralign to" or "\coloralign spread" because
249
the space inserted by "\tabskip" won't be shaded.
251
These macros are not very robust. You can make best use of them by knowing how
252
they work. "\coloralign" just saves the preamble, and otherwise is identical
253
to "\halign". "\CC" finds the height of the rows that have to be colored, and
254
then "\CC" draws a rectangle using \TeX's line-drawing primitives in each
255
cell, colored by the color commands included in the first line that follows
260
draws a yellow rectangle in column 1, nothing in column 2, and a red rectangle
261
in column 3. Then "\CC" goes back up the height of the rectangle, so that
262
\TeX's current point is back where it was when "\CC" started. At this point,
263
"\CC" has finished its work. When the next rows of the alignment environment
264
are processed by "\halign", they are put down on top of the rectangles, and
265
hence have colored backgrounds.
267
"\CC" finds the height of the rows to be colored by putting the rows into an
268
"\halign" environment, using the preamble that was saved by "\coloralign", and
269
then measuring the height of the resulting box.
271
\section{\LaTeX\ array environments}
273
Cells can be colored in a \LaTeX\ array without using a special array
274
environment (i.e., there is no \LaTeX\ analog to "\coloralign"). Use "\LCC"
275
instead of "\CC", and use "\\" to end the row of color commands instead of
278
\def\arraystretch{1.5}%
279
\begin{tabular}{|l|c|}\hline
282
Tamarind & Chiplote \\ \hline
286
Lulu & Serrano\\ \hline
287
Guanabana & Larga\\ \hline
291
The same caveats apply as with the "\coloralign" environment.
293
When \n\LCC\ and \n\ECC\ are used with Frank Mittelbach's "array.sty", nested
294
array-type environments and "\multicolumn" commands wipe out information
295
needed by \n\ECC\. Here is a workaround: Put "\SP" (``SavePreamble'') at the
296
beginning of the array-type environment (right after the column declarations),
297
and put "\RP" (``RestorePreamble'') at the end of each line containing a
298
"\multicolumn" command or nested array-type environment (after the "\\", and
299
before the \n\ECC). For example:
301
\begin{tabular}{|l|c|}\SP\hline
304
\multicolumn{2}{c}{Tamarind}\\ \RP \hline
308
Further nesting (e.g., an array within a "\multicolumn", or a "\multicolumn"
309
or array within a nested array) sometimes works and sometimes doesn't. You
310
will have to figure that one out for yourself.
313
\section{longtable.sty}
315
"longtable.sty", by David Carlisle, defines the "longtable" environment, for
316
making multipage tables. "\LCC" will not work with "longtable". However,
317
"colortab" contains other macros that will work, if you use "longtable.sty" in
318
conjunction with Frank Mittelbach's "array.sty". These macros have been tested
319
only briefly, with version 3.04 of "longtable.sty" and version 2.1b of
322
Before every column identifier in the environment's argument (e.g., "c", "l",
323
"r", "p", "m" or "b"), put
325
\vitem"!{\LC}" If none of the below applies;
326
\vitem"!{\LCi}" If the column is preceded by one or more vertical lines;
327
\vitem"!{\LCii}" If the column is followed by two vertical lines;
328
\vitem"!{\LCiii}" If the column is preceded by one or more vertical lines
329
and followed by two vertical lines.
330
\vitem"!{\LCz{<len1>}{<len2>}}" If "colortab" should back up by <len1>
331
before drawing the background, and should draw the background <len2> shorter
332
than the width of the column.
334
Remember that you have to do this for every column, not just the columns that
339
\LColors <color> & <color> & ... & <color>\\
341
in the first row of the environment, and later on as well if you wish to
342
change the colors. Here also you have to include every column, but you can
343
leave an entry blank if you don't want any background color in that column.
345
The color comes out right, or at all, only after you have run the file enough
346
times for "longtable.sty" to set the alignment correctly.
348
Here is an example. The output will appear in this documentation only if
349
"longtable.sty" or "longtabl.sty" is installed on your system.
353
% Modification Denis GIROU (CNRS/IDRIS - France) - <Denis.Girou@idris.fr> - 10 Sep. 1996
354
% Can't work with LaTeX 2e
355
% \@input{longtable.sty}%
356
% \@input{longtabl.sty}%
357
% \@input{array.sty}%
358
\@input{longtable.styX}% Avoid loading of longtable.sty...
359
\@input{longtabl.sty}%
360
\@input{array.styX}% Avoid loading of array.sty...
362
\@ifundefined{c@LT@tables}{\@testfalse}{}%
363
\@ifundefined{d@llarbegin}{\@testfalse}{}%
365
\renewenvironment{example}{\VerbatimEnvironment\LVerbatim}{\endLVerbatim}%
370
\begin{longtable}{|!{\LCiii}l||!{\LCi}c|!{\LCi}c|}\hline
371
\LColors \gray & & \\
372
Tamarind & Chiplote & Galanga\\ \hline
373
\LColors \lightgray & & \gray\\
374
Lulu & & Serrano\\ \hline
375
Guanabana & Larga &\\ \hline
380
\section{Coloring lines}
382
Let's begin with the "\halign" environment. Changing the color of lines is
383
easy, because if you write, say, "{\gray\hrule}", then the line comes out
386
% Thicker lines and wider spacing give better view:
387
\setbox\strutbox=\hbox{%
388
\vrule height15.5pt depth8.5pt width0pt}%
389
\def\Hrule{\hrule height 2.5pt}%
390
\def\Vrule{\vrule width 2.5pt}%
392
\vbox{\offinterlineskip
394
{\lightgray\Vrule}\strut\quad\hfil#\hfil\quad
395
&{\gray\Vrule}\quad\hfil#\quad\Vrule\cr
397
Tamarind& Chiplote\cr\noalign{{\darkgray\Hrule}}%
398
Lulu& Serrano\cr\noalign{\Hrule}%
399
Guanabana& Larga\cr\noalign{{\lightgray\Hrule}}%
403
With \LaTeX, you can add an entry like
405
@{\hspace{\tabcolsep}{\gray\vrule}\hspace{\tabcolsep}}
407
to the argument of the alignment environment, instead of "|", if you want to
408
color the vertical line that is drawn. If using "array.sty", you can try:
413
To color horizontal lines with \LaTeX, don't bother trying
417
because it won't work. You write your own version of "\hline" and "\cline", or
418
use the non-aligned color commands described in the next section.
420
\section{Non-aligned color with PSTricks}
422
Here are a few other commands that can be useful for adding color to tables.
423
{\bf They only work with PSTricks, v0.93 or later.} <color> in this case is
424
the name of the color, without the backslash. These fudge the color commands
425
so that they do not have to be balanced with respect to \TeX\ grouping. You
426
can achieve the same thing using "\special{<raw postscript>}" and "\noalign",
427
if you know what you are doing. These should work with just about any
428
alignment macro, include "\halign" and \LaTeX's "tabular" environment.
432
\vitem"\AC{<color>} ... \EAC" \
434
These stand for "AlignColor" and "EndAlignColor", respectively. <color> is
435
the name of the color, without a backslash, rather than a color command. This
436
can be used within a cell, but they do not have to be within the same cell,
437
nor do they have to be properly nested with respect to \TeX\ grouping.
438
Generally, "\AC{<color>}" switches to <color>, and \n\EAC\ restores the color
439
that would be in effect if the first \n\AC\ command were missing.
441
\vitem"\NAC{<color>} ... \ENAC" \
443
These stand for "NoAlignColor" and "EndNoAlignColor", respectively. These
444
are like \n\AC\ and \n\EAC, but the color commands are put inside a
445
"\noalign". They can only appear at the end of a line, after "\\" or "\cr".
448
Actually, these do not even have to be used in pairs.
450
Here is an example of how "\AC", etc., can be used. to color lines in \LaTeX\
451
arrays. The output will appear in this documentation only if PSTricks is
452
installed on your system:
454
\ifx\PSTricksLoaded\endinput\else
455
\renewenvironment{example}{\VerbatimEnvironment\LVerbatim}{\endLVerbatim}
458
\arrayrulewidth 1.5pt
459
\begin{tabular}{|l|c|}\hline
460
Tamarind& Chiplote\\ \NAC{gray}\hline\ENAC
461
Lulu& Serrano\\ \cline{1-1}
462
\NAC{lightgray}\cline{2-2}\ENAC
463
Guanabana\AC{lightgray} & \EAC Larga\\ \hline