Debian Codegraph @

latex/misc/multirow2.sty

raw
1 %%
2 %% multirowii.sty V1.6 version (5-May-2004)
3 %%
4 %% Author: Jerry Leichter <[email protected]>
5 %% Piet van Oostrum <[email protected]>
6 %%
7 %% This file may be distributed under the terms of the LaTeX Project Public
8 %% License, as described in lppl.txt in the base LaTeX distribution.
9 %% Either version 1 or, at your option, any later version.
10 %%
11 %% V1.0 was distributed anonymously, based on a Usenet posting that was
12 %% not intended for stand-alone use.
13 %% V1.1 was modified by Piet van Oostrum <[email protected]> to allow it to
14 %% work without bigstrut.sty.
15 %% V1.2 was modified by Jerry Leichter for the same goal, but using a
16 %% different approach which will work properly in conjunction with
17 %% bigstrut.sty.
18 %% V1.2a was modified by Piet van Oostrum <[email protected]> to use \vskip
19 %% instead of \raise in positioning, avoiding making rows too high
20 %% when the adjustment is large.
21 %% V1.3 was modified by Piet van Oostrum to work properly in a p{} column
22 %% (\leavevmode added)
23 %% V1.4 was modified by Piet van Oostrum to check for the special case that
24 %% the width is given as an *. In this case the natural
25 %% width of the text argument will be used and the argument
26 %% is processed in LR-mode.
27 %% V1.5 was modified by Piet van Oostrum: Added a % after \hbox{#5}\vfill}.
28 %% Added \struts around #5 for better vertical positioning.
29 %% Additional coding for negative value of nrows.
30 %% V1.6 was modified by Piet van Oostrum: Replace a space by \relax after
31 %% \advance\@tempdima#4.
32 %%
33 % Make an entry that will span multiple rows of a table.
34 %
35 % \multirowii[pos]{nrows}[bigstruts]{width}[fixup]{text}
36 %
37 % pos specifies the vertical position of text. 'p' at the top of the box,
38 % 'm' in the middle (default), 'b' at the bottom.
39 %
40 % nrows is the number of rows to span. It's up to you to leave the other
41 % rows empty, or the stuff created by \multirowii will over-write it.
42 % With a positive value of nrows the spanned colomns are this row and
43 % (nrows-1) rows below it. With a negative value of nrows they are
44 % this row and (1-nrows) above it.
45 %
46 % bigstruts is mainly used if you've used bigstrut.sty. In that case it
47 % is the total number of uses of \bigstrut within the rows being
48 % spanned. Count 2 uses for each \bigstrut, 1 for each \bigstrut[x]
49 % where x is either t or b. The default is 0.
50 %
51 % width is the width to which the text is to be set, or * to indicate that
52 % the text argument's natural width is to be used.
53 %
54 % text is the actual text. If the width was set explicitly, the text will
55 % be set in a parbox of that width; you can use \\ to force linebreaks
56 % where you like.
57 %
58 % If the width was given as * the text will be set in LR mode. If you
59 % want a multiline entry in this case you should use a tabular or array
60 % in the text parameter.
61 %
62 % The text is centered vertically within the range spanned by nrows.
63 %
64 % fixup is a length used for fine tuning: The text will be raised (or
65 % lowered, if fixup is negative) by that length above (below) wherever
66 % it would otherwise have gone.
67 %
68 % For example (using both multirowii and bigstrut)
69 %
70 % \newcommand{\minitab}[2][l]{\begin{tabular}{#1}#2\end{tabular}}
71 % \begin{tabular}{|c|c|}
72 % \hline
73 % \multirowii{4}{1in}{Common g text} & Column g2a\\
74 % & Column g2b \\
75 % & Column g2c \\
76 % & Column g2d \\
77 % \hline
78 % \multirowii{3}[6]*{Common g text} & Column g2a\bigstrut\\\cline{2-2}
79 % & Column g2b \bigstrut\\\cline{2-2}
80 % & Column g2c \bigstrut\\
81 % \hline
82 % \multirowii{4}[8]{1in}{Common g text} & Column g2a\bigstrut\\\cline{2-2}
83 % & Column g2b \bigstrut\\\cline{2-2}
84 % & Column g2c \bigstrut\\\cline{2-2}
85 % & Column g2d \bigstrut\\
86 % \hline
87 % \multirowii{4}*{\minitab[c]{Common \\ g text}} & Column g2a\\
88 % & Column g2b \\
89 % & Column g2c \\
90 % & Column g2d \\
91 % \hline
92 % \end{tabular}
93 %
94 % If any of the spanned rows are unusually large, or if you're using
95 % bigstrut.sty and \bigstrut's are used assymetrically about the centerline of
96 % the spanned rows, the vertical centering may not come out right. Use the
97 % fixup argument in this case.
98 %
99 % Just before "text" is expanded, the \multirowiisetup macro is expanded to
100 % set up any special environment. Initially, \multirowiisetup contains just
101 % \raggedright. It can be redefined with \renewcommand.
102 %
103 % Bugs: It's just about impossible to deal correctly with descenders. The
104 % text will be set up centered, but it may then have a baseline that doesn't
105 % match the baseline of the stuff beside it, in particular if the stuff
106 % beside it has descenders and "text" does not. This may result in a small
107 % missalignment. About all that can be done is to do a final touchup on
108 % "text", using the fixup optional argument. (Hint: If you use a measure
109 % like .1ex, there's a reasonable chance that the fixup will still be correct
110 % if you change the point size.)
111 %
112 % \multirowii is mainly designed for use with table, as opposed to array,
113 % environments. It will not work well in an array environment since the lines
114 % have an extra \jot of space between them which it won't account for. Fixing
115 % this is difficult in general, and doesn't seem worth it. The bigstruts
116 % argument can be used to provide a semi-automatic fix: First set
117 % \bigstrutjot to .5\jot. Then simply repeat nrows as the bigstruts argument.
118 % This will be close, but probably not exact; you can use the fixup argument
119 % to refine the result. (If you do this repeatedly, you'll probably want to
120 % wrap these steps up in a simple macro. Note that the modified \bigstrutjot
121 % value will not give reasonable results if you have bigstruts and use this
122 % argument for its intended purpose elsewhere. In that case, you might want
123 % to set it locally.)
124 %
125 % If you use \multirowii with the colortbl package you have to take
126 % precautions if you want to color the column that has the \multirowii in it.
127 % colortbl works by coloring each cell separately. So if you use \multirowii
128 % with a positive nrows value, colortbl will first color the top cell, then
129 % \multirowii will typeset nrows cells starting with this cell, and later
130 % colortbl will color the other cells, effectively hiding the text in that
131 % area. This can be solved by putting the \multirowii is the last row with a
132 % negative nrows value.
133 % Example:
134 %
135 % \begin{tabular}{l>{\columncolor{yellow}}l}
136 % aaaa & \\
137 % cccc & \\
138 % dddd & \multirowii{-3}*{bbbb}\\
139 % \end{tabular}
140 %
141 \def\multirowiisetup{\raggedright\vskip1pt}
142 \def\vfillsetup#1{%
143 \if#1m\let\vfillup=\vfill\let\vfilldn=\vfill\else%
144 \if#1p\let\vfillup=\relax\let\vfilldn=\vfill\else%
145 \if#1b\let\vfillup=\vfill\let\vfilldn=\relax\else%
146 \let\vfillup=\vfill\let\vfilldn=\vfill \fi\fi\fi}
147
148 \def\multirowii{\@ifnextchar [{\@multirowiiv}{\vfillsetup{m}\@multirowiim}}
149 \def\@multirowiiv[#1]{\vfillsetup{#1}\@multirowiim}
150
151 \def\@multirowiim#1{\relax\@ifnextchar
152 [{\@multirowii{#1}}{\@multirowii{#1}[0]}}
153 \def\@multirowii#1[#2]#3{\@ifnextchar [{\@xmultirowii{#1}[#2]{#3}}%
154 {\@xmultirowii{#1}[#2]{#3}[0pt]}}
155 \long\def\@xmultirowii#1[#2]#3[#4]#5{\@tempcnta=#1%
156 \@tempdima\@tempcnta\ht\@arstrutbox
157 \advance\@tempdima\@tempcnta\dp\@arstrutbox
158 \ifnum\@tempcnta<0\@tempdima=-\@tempdima\fi
159 \advance\@tempdima#2\bigstrutjot
160 \if*#3\setbox0\vtop to \@tempdima{\vfillup\multirowiisetup
161 \hbox{\strut#5\strut}\vfilldn}%
162 \ht0\z@\dp0\z@
163 \else
164 \dimen0=#3\relax
165 \ifdim\dimen0<\z@
166 \dimen0=-\dimen0
167 \let\footnotemark\relax
168 \fi
169 \setbox0\vbox{\hsize\dimen0\@parboxrestore\multirowiisetup\strut#5\strut}%
170 \dimen0=\ht0
171 \advance\dimen0\dp0\relax
172 \ifdim\dimen0>\@tempdima
173 \divide\dimen0\@tempcnta
174 \ifnum\dimen0<0%
175 \dimen0=-\dimen0
176 \fi
177 \ifdim#3<\z@
178 \setbox0\vbox{}%
179 \fi
180 \ht0\dimen0\dp0\z@
181 \else
182 \ifdim#3<\z@
183 \setbox0\vbox{}%
184 \fi
185 \setbox0\vtop to \@tempdima{\vfillup\unvbox0\vfilldn}%
186 \ht0\z@\dp0\z@
187 \fi
188 \fi
189 \ifnum\@tempcnta<0\advance\@tempdima-\dp\@arstrutbox
190 \else\@tempdima=\ht\@arstrutbox
191 \ifnum#2>0 \advance\@tempdima\bigstrutjot \fi
192 \fi
193 \advance\@tempdima#4\relax\leavevmode\vtop{\vskip-\@tempdima\box0\vss}}
194 \@ifundefined{bigstrutjot}{\newdimen\bigstrutjot \bigstrutjot\jot}{}
195