ltablex.sty 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. %%
  2. %% This is file ltablex.sty (v1.0, November 1995)
  3. %%
  4. %%
  5. %% Author: Anil K. Goel (akgoel@uwaterloo.ca)
  6. %%
  7. %%
  8. %% Copyright (C) QNX Software Systems Ltd. 1995
  9. %% All rights reserved.
  10. %% Please send any comments/suggetions to: latex@qnx.com
  11. %%
  12. %% This system is distributed in the hope that it will be useful
  13. %% to others, but WITHOUT ANY WARRANTY; without even the implied
  14. %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. %%
  16. %%
  17. %% The file modifies the tabularx environment to
  18. %% combine the features of the tabularx package
  19. %% (auto-sized columns in a fixed width table)
  20. %% with those of the longtable package
  21. %% (multi-page tables).
  22. %%
  23. %% The tables are typeset using the tabularx environment
  24. %% and the longtable environment is used internally to
  25. %% handle multi-page tables. The \setlongtables feature
  26. %% is used, and, therefore, the document should be
  27. %% run through latex twice.
  28. %%
  29. %% Another feature that has been added is to treat the X
  30. %% columns like 'l' columns if the table contents would allow
  31. %% that to happen without exceeding the specified width of
  32. %% the table. In other words, the specified width is
  33. %% treated as the maximum allowed and not the exact width
  34. %% of the table. This feature is the default but can be
  35. %% disabled (or enabled) with \keepXColumns (or \convertXColumns).
  36. %%
  37. %% Caveats:
  38. %% . The document needs to be latexed a couple times in general.
  39. %% . In general, it is necessary to remove the .aux file before
  40. %% the first latex run on the document.
  41. %% . The table should not be larger than TeX's memory capacity
  42. %%
  43. %%
  44. %% Here is a a simple usage example:
  45. %%
  46. %%
  47. %% \documentclass{article}
  48. %%
  49. %% \usepackage{ltablex}
  50. %%
  51. %% \textheight=4in
  52. %%
  53. %% \begin{document}
  54. %%
  55. %% % we want a table that is \textwidth long, has 4 columns, columns 1
  56. %% % and 3 are auto sized with the 3rd columns being 3 times wider than
  57. %% % the first column.
  58. %% %
  59. %%
  60. %%
  61. %% \begin{tabularx}{\linewidth}%
  62. %% {|>{\setlength{\hsize}{.5\hsize}\raggedright\arraybackslash}X| % col 1; auto-sized ragged right
  63. %% c| % col 2; default centered
  64. %% >{\setlength{\hsize}{1.5\hsize}\raggedleft\arraybackslash}X|% col 3; auto-sized ragged left
  65. %% l|} % col 4; default left-justified
  66. %%
  67. %% \caption*{The Table Caption}\\
  68. %% \hline
  69. %% F-Head1 & F-Head2 & F-Head3 & F-Head4\\
  70. %% \hline
  71. %% \hline
  72. %% \endfirsthead
  73. %% \hline
  74. %% Head1 & Head2 & Head3 & Head4\\
  75. %% \hline
  76. %% \hline
  77. %% \endhead
  78. %%
  79. %% \hline
  80. %% \hline
  81. %% Foot1 & Foot2 & Foot3 & Foot4\\
  82. %% \hline
  83. %% \endfoot
  84. %%
  85. %%
  86. %% \hline
  87. %% \hline
  88. %% L-Foot1 & L-Foot2 & L-Foot3 & L-Foot4\\
  89. %% \hline
  90. %% \endlastfoot
  91. %%
  92. %% This is a very long sentence not likely to fit&
  93. %% not too long&
  94. %% This is another very long sentence not likely to fit&
  95. %% not long\\
  96. %%
  97. %% \hline
  98. %% filler & filler & filler & filler\\
  99. %%
  100. %% \hline
  101. %% This is a very long sentence not likely to fit&
  102. %% not too long&
  103. %% This is another very long sentence not likely to fit&
  104. %% not long\\
  105. %%
  106. %% \hline
  107. %% This is a very long sentence not likely to fit&
  108. %% not too long&
  109. %% This is another very long sentence not likely to fit&
  110. %% not long\\
  111. %%
  112. %% \hline
  113. %% This is a very long sentence not likely to fit&
  114. %% not too long&
  115. %% This is another very long sentence not likely to fit&
  116. %% not long\\
  117. %%
  118. %% \end{tabularx}
  119. %%
  120. %% \begin{tabularx}{\linewidth}{|c|X|c|}
  121. %% \hline
  122. %% a &convert X to l & b\\
  123. %% \hline
  124. %% \end{tabularx}
  125. %%
  126. %% \keepXColumns
  127. %% \begin{tabularx}{\linewidth}{|c|X|c|}
  128. %% \hline
  129. %% a &retain X & b\\
  130. %% \hline
  131. %% \end{tabularx}
  132. %%
  133. %% \convertXColumns
  134. %% \begin{tabularx}{\linewidth}{|c|X|c|}
  135. %% \hline
  136. %% a &convert X to l & b\\
  137. %% \hline
  138. %% \end{tabularx}
  139. %%
  140. %%
  141. %% \end{document}
  142. \NeedsTeXFormat{LaTeX2e}
  143. \ProvidesPackage{ltablex}[1995/11/06 v1.0 Modified tabularx]
  144. \RequirePackage{longtable}[1994/12/08]
  145. \RequirePackage{tabularx}[1994/02/03]
  146. \newif\ifTX@convertX@
  147. \TX@convertX@true
  148. \newcommand\keepXColumns{
  149. \TX@convertX@false
  150. }
  151. \newcommand\convertXColumns{
  152. \TX@convertX@true
  153. }
  154. \renewcommand\TX@endtabularx{%
  155. \expandafter\TX@newcol\expandafter{\tabularxcolumn{\TX@col@width}}%
  156. \let\verb\TX@verb
  157. \def\@elt##1{\global\value{##1}\the\value{##1}\relax}%
  158. \edef\TX@ckpt{\cl@@ckpt}%
  159. \let\@elt\relax
  160. \TX@old@table=\maxdimen
  161. \TX@col@width=\TX@target
  162. \global\TX@cols=\@ne
  163. \TX@typeout@
  164. {\@spaces Table Width\@spaces Column Width\@spaces X Columns}%
  165. %
  166. % define \endhead, etc. to be \\ so that in this part
  167. % of the process they are just rows
  168. %
  169. \let\savecaption\caption
  170. \def\caption{\\}
  171. \let\saveendhead\endhead
  172. \def\endhead{\\}
  173. \let\saveendfirsthead\endfirsthead
  174. \def\endfirsthead{\\}
  175. \let\saveendfoot\endfoot
  176. \def\endfoot{\\}
  177. \let\saveendlastfoot\endlastfoot
  178. \def\endlastfoot{\\}
  179. %
  180. %
  181. \ifTX@convertX@
  182. \TX@trial{\def\NC@rewrite@X{\NC@find l}}
  183. \ifdim\wd\@tempboxa<\TX@target
  184. \TX@newcol{l}
  185. \else
  186. \TX@convertX@false
  187. \fi
  188. \fi
  189. \ifTX@convertX@
  190. \relax
  191. \else
  192. \TX@trial{\def\NC@rewrite@X{%
  193. \global\advance\TX@cols\@ne\NC@find p{\TX@col@width}}}%
  194. \loop
  195. \TX@arith
  196. \ifTX@
  197. \TX@trial{}%
  198. \repeat
  199. \fi
  200. {\let\@footnotetext\TX@ftntext\let\@xfootnotenext\TX@xftntext
  201. % we may as well set \LTchunksize to be \maxdimen as the whole
  202. % thing is already in memory anyway so we may as well do it in one
  203. % chunk. if it is too big for one chunk we are already dead..
  204. \LTchunksize\maxdimen
  205. %
  206. % restore \endhead, etc.
  207. %
  208. \let\caption\savecaption
  209. \let\endhead\saveendhead
  210. \let\endfirsthead\saveendfirsthead
  211. \let\endfoot\saveendfoot
  212. \let\endlastfoot\saveendlastfoot
  213. %
  214. \expandafter\longtable
  215. \the\toks@
  216. \endlongtable
  217. }%
  218. \global\TX@ftn\expandafter{\expandafter}\the\TX@ftn
  219. \ifnum0=`{\fi}%
  220. \end{tabularx}
  221. }
  222. %
  223. % activate column width reading from the .aux file
  224. %
  225. \setlongtables