Newer
Older
Publications / ER_2000 / Final_version / multirow.sty
  1. %%
  2. %% multirow.sty V1.5 version (16-July-1999)
  3. %%
  4. %% Author: Jerry Leichter <jerrold.leichter@smarts.com>
  5. %% Piet van Oostrum <piet@cs.uu.nl>
  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 <piet@cs.uu.nl> 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 <piet@cs.uu.nl> 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. %
  31. % Make an entry that will span multiple rows of a table.
  32. %
  33. % \multirow{nrows}[bigstruts]{width}[fixup]{text}
  34. %
  35. % nrows is the number of rows to span. It's up to you to leave the other
  36. % rows empty, or the stuff created by \multirow will over-write it.
  37. % With a positive value of nrows the spanned colomns are this row and
  38. % (nrows-1) rows below it. With a negative value of nrows they are
  39. % this row and (1-nrows) above it.
  40. %
  41. % bigstruts is mainly used if you've used bigstrut.sty. In that case it
  42. % is the total number of uses of \bigstrut within the rows being
  43. % spanned. Count 2 uses for each \bigstrut, 1 for each \bigstrut[x]
  44. % where x is either t or b. The default is 0.
  45. % width is the width to which the text is to be set, or * to indicate that
  46. % the text argument's natural width is to be used.
  47. %
  48. % text is the actual text. If the width was set explicitly, the text will
  49. % be set in a parbox of that width; you can use \\ to force linebreaks
  50. % where you like.
  51. %
  52. % If the width was given as * the text will be set in LR mode. If you
  53. % want a multiline entry in this case you should use a tabular or array
  54. % in the text parameter.
  55. %
  56. % The text is centered vertically within the range spanned by nrows.
  57. %
  58. % fixup is a length used for fine tuning: The text will be raised (or
  59. % lowered, if fixup is negative) by that length above (below) wherever
  60. % it would otherwise have gone.
  61. %
  62. % For example (using both multirow and bigstrut)
  63. %
  64. % \newcommand{\minitab}[2][l]{\begin{tabular}{#1}#2\end{tabular}}
  65. % \begin{tabular}{|c|c|}
  66. % \hline
  67. % \multirow{4}{1in}{Common g text} & Column g2a\\
  68. % & Column g2b \\
  69. % & Column g2c \\
  70. % & Column g2d \\
  71. % \hline
  72. % \multirow{3}[6]*{Common g text} & Column g2a\bigstrut\\\cline{2-2}
  73. % & Column g2b \bigstrut\\\cline{2-2}
  74. % & Column g2c \bigstrut\\
  75. % \hline
  76. % \multirow{4}[8]{1in}{Common g text} & Column g2a\bigstrut\\\cline{2-2}
  77. % & Column g2b \bigstrut\\\cline{2-2}
  78. % & Column g2c \bigstrut\\\cline{2-2}
  79. % & Column g2d \bigstrut\\
  80. % \hline
  81. % \multirow{4}*{\minitab[c]{Common \\ g text}} & Column g2a\\
  82. % & Column g2b \\
  83. % & Column g2c \\
  84. % & Column g2d \\
  85. % \hline
  86. % \end{tabular}
  87. %
  88. % If any of the spanned rows are unusually large, or if you're using
  89. % bigstrut.sty and \bigstrut's are used assymetrically about the centerline of
  90. % the spanned rows, the vertical centering may not come out right. Use the
  91. % fixup argument in this case.
  92. %
  93. % Just before "text" is expanded, the \multirowsetup macro is expanded to
  94. % set up any special environment. Initially, \multirowsetup contains just
  95. % \raggedright. It can be redefined with \renewcommand.
  96. %
  97. % Bugs: It's just about impossible to deal correctly with descenders. The
  98. % text will be set up centered, but it may then have a baseline that doesn't
  99. % match the baseline of the stuff beside it, in particular if the stuff
  100. % beside it has descenders and "text" does not. This may result in a small
  101. % missalignment. About all that can be done is to do a final touchup on
  102. % "text", using the fixup optional argument. (Hint: If you use a measure
  103. % like .1ex, there's a reasonable chance that the fixup will still be correct
  104. % if you change the point size.)
  105. %
  106. % \multirow is mainly designed for use with table, as opposed to array,
  107. % environments. It will not work well in an array environment since the lines
  108. % have an extra \jot of space between them which it won't account for. Fixing
  109. % this is difficult in general, and doesn't seem worth it. The bigstruts
  110. % argument can be used to provide a semi-automatic fix: First set
  111. % \bigstrutjot to .5\jot. Then simply repeat nrows as the bigstruts argument.
  112. % This will be close, but probably not exact; you can use the fixup argument
  113. % to refine the result. (If you do this repeatedly, you'll probably want to
  114. % wrap these steps up in a simple macro. Note that the modified \bigstrutjot
  115. % value will not give reasonable results if you have bigstruts and use this
  116. % argument for its intended purpose elsewhere. In that case, you might want
  117. % to set it locally.)
  118. %
  119. % If you use \multirow with the colortbl package you have to take
  120. % precautions if you want to color the column that has the \multirow in it.
  121. % colortbl works by coloring each cell separately. So if you use \multirow
  122. % with a positive nrows value, colortbl will first color the top cell, then
  123. % \multirow will typeset nrows cells starting with this cell, and later
  124. % colortbl will color the other cells, effectively hiding the text in that
  125. % area. This can be solved by putting the \multirow is the last row with a
  126. % negative nrows value.
  127. % Example:
  128. %
  129. % \begin{tabular}{l>{\columncolor{yellow}}l}
  130. % aaaa & \\
  131. % cccc & \\
  132. % dddd & \multirow{-3}*{bbbb}\\
  133. % \end{tabular}
  134. %
  135. \def\multirowsetup{\raggedright}
  136. \def\multirow#1{\relax\@ifnextchar
  137. [{\@multirow{#1}}{\@multirow{#1}[0]}}
  138. \def\@multirow#1[#2]#3{\@ifnextchar [{\@xmultirow{#1}[#2]{#3}}%
  139. {\@xmultirow{#1}[#2]{#3}[0pt]}}
  140. \def\@xmultirow#1[#2]#3[#4]#5{\@tempcnta=#1%
  141. \@tempdima\@tempcnta\ht\@arstrutbox
  142. \advance\@tempdima\@tempcnta\dp\@arstrutbox
  143. \ifnum\@tempcnta<0\@tempdima=-\@tempdima\fi
  144. \advance\@tempdima#2\bigstrutjot
  145. \if*#3\setbox0\vtop to \@tempdima{\vfill\multirowsetup
  146. \hbox{\strut#5\strut}\vfill}%
  147. \else
  148. \setbox0\vtop to \@tempdima{\hsize#3\@parboxrestore
  149. \vfill \multirowsetup \strut#5\strut\par\vfill}%
  150. \fi
  151. \ht0\z@\dp0\z@
  152. \ifnum\@tempcnta<0\advance\@tempdima-\dp\@arstrutbox
  153. \else\@tempdima=\ht\@arstrutbox
  154. \ifnum#2>0 \advance\@tempdima\bigstrutjot \fi
  155. \fi
  156. \advance\@tempdima#4 \leavevmode\vtop{\vskip-\@tempdima\box0\vss}}
  157. \@ifundefined{bigstrutjot}{\newdimen\bigstrutjot \bigstrutjot\jot}{}