| 1 |
% |
| 2 |
%% User documentation and source for ltxtable package |
| 3 |
%% (C) 1995, 2021 David Carlisle |
| 4 |
% |
| 5 |
%% This file may be distributed under the terms of the LPPL. |
| 6 |
%% See 00readme.txt for details. |
| 7 |
% |
| 8 |
% Save this file as ltxtable.tex, then |
| 9 |
% latex ltxtable |
| 10 |
% |
| 11 |
% This will write the ltxtable.sty package file on to your system |
| 12 |
% and produce some rather terse typeset documentation. |
| 13 |
% |
| 14 |
\begin{filecontents}[overwrite]{ltx1.tex} |
| 15 |
\begin{longtable}{|cXX|} |
| 16 |
the & head& line\endhead |
| 17 |
the & foot& line\endfoot |
| 18 |
a&b&b\\ |
| 19 |
\multicolumn{2}{c}{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}&c\\ |
| 20 |
a&b&b b b b b b b b b b b b b b b b b b b b b b b b b b \\ |
| 21 |
a a& b b& c c\\ |
| 22 |
a a& b b& |
| 23 |
c c c c c c c c c c c c c c c c c c c c c c c c c c c c c cc cc\\ |
| 24 |
a a aaaa& b b& c ccccc\\ |
| 25 |
\end{longtable} |
| 26 |
\end{filecontents} |
| 27 |
|
| 28 |
\begin{filecontents}[overwrite]{ltxtable.sty} |
| 29 |
% |
| 30 |
%% ltxtable package (C) 1995, 2021 David Carlisle |
| 31 |
%% |
| 32 |
%% This file may be distributed under the terms of the LPPL. |
| 33 |
%% See 00readme.txt for details. |
| 34 |
% |
| 35 |
% User documentation is in the file ltxtable.tex |
| 36 |
% |
| 37 |
% \begin{macrocode} |
| 38 |
\NeedsTeXFormat{LaTeX2e} |
| 39 |
\ProvidesPackage{ltxtable} |
| 40 |
[2021/06/13 v0.4 longtable/tabularx merge (DPC)] |
| 41 |
% \end{macrocode} |
| 42 |
% |
| 43 |
% May as get these in, going to need them... |
| 44 |
% \begin{macrocode} |
| 45 |
\RequirePackage{tabularx,longtable} |
| 46 |
% \end{macrocode} |
| 47 |
% |
| 48 |
% \begin{macrocode} |
| 49 |
\def\LTXtable#1#2{% |
| 50 |
\begingroup |
| 51 |
\TX@target#1\relax |
| 52 |
\expandafter\TX@newcol\expandafter{\tabularxcolumn{\TX@col@width}}% |
| 53 |
\def\@elt##1{\global\value{##1}\the\value{##1}\relax}% |
| 54 |
\edef\TX@ckpt{\cl@@ckpt}% |
| 55 |
\let\@elt\relax |
| 56 |
\TX@old@table=\maxdimen |
| 57 |
\TX@col@width=\TX@target |
| 58 |
\global\TX@cols=\@ne |
| 59 |
\TX@typeout@ |
| 60 |
{\@spaces Table Width\@spaces Column Width\@spaces X Columns}% |
| 61 |
% \end{macrocode} |
| 62 |
% Need to modify |\TX@trial| so that |longtable| functions are |
| 63 |
% Subverted to do the measuring that |tabularx| normally does. |
| 64 |
% Also during the trial runs each `chunk' is not unboxed so it just |
| 65 |
% gets thrown away when the next chunk starts. |
| 66 |
% \begin{macrocode} |
| 67 |
\def\TX@trial##1{% |
| 68 |
\setbox\@tempboxa=\hbox{% |
| 69 |
% \end{macrocode} |
| 70 |
% |\multicolum| A sad tale, For now just stop |longtable| messing with |
| 71 |
% it, so that |tabularx| can mess with it. |
| 72 |
% \begin{macrocode} |
| 73 |
\let\LTmulticolumn\multicolumn |
| 74 |
% \end{macrocode} |
| 75 |
% |
| 76 |
% \begin{macrocode} |
| 77 |
\def\endlongtable{% |
| 78 |
\LT@echunk |
| 79 |
% from 2021 longtable uses an allocated box \LT@gbox not \box1 |
| 80 |
\global\setbox\LT@gbox\hbox{\unhbox\LT@gbox}% |
| 81 |
\kern\wd\LT@gbox |
| 82 |
\LT@get@widths% |
| 83 |
\endgroup}% |
| 84 |
% \end{macrocode} |
| 85 |
% |
| 86 |
% \begin{macrocode} |
| 87 |
\def\LT@ntabularcr{% |
| 88 |
\ifnum0=`{}\fi |
| 89 |
\LT@echunk |
| 90 |
\LT@get@widths |
| 91 |
\LT@bchunk}% |
| 92 |
% \end{macrocode} |
| 93 |
% |
| 94 |
% \begin{macrocode} |
| 95 |
\def\LT@argtabularcr[####1]{% |
| 96 |
\ifnum0=`{}\fi |
| 97 |
\ifdim ####1>\z@ |
| 98 |
\unskip\@xargarraycr{####1}\else \@yargarraycr{####1}\fi |
| 99 |
\LT@echunk |
| 100 |
\LT@get@widths |
| 101 |
\LT@bchunk}% |
| 102 |
% \end{macrocode} |
| 103 |
% |
| 104 |
% \begin{macrocode} |
| 105 |
% Any extra commands. This is used on the first run to count the number |
| 106 |
% of {\ttfamily X} columns. |
| 107 |
% \begin{macrocode} |
| 108 |
##1\relax |
| 109 |
% \end{macrocode} |
| 110 |
% Added at v1.05: dissable "\write"s during a trial run. This trick is |
| 111 |
% from the \TeX{}Book. |
| 112 |
% \begin{macrocode} |
| 113 |
\let\immediate=\relax\def\write####1####{{\afterassignment}\toks@=}% |
| 114 |
% \end{macrocode} |
| 115 |
% Turn off warnings (see appendix D). Also prevent them being turned |
| 116 |
% back on by setting the parameter names to be registers. |
| 117 |
% \begin{macrocode} |
| 118 |
\hbadness=\@M\hfuzz=\maxdimen |
| 119 |
\let\hbadness=\@tempcnta\let\hfuzz=\@tempdima |
| 120 |
% \end{macrocode} |
| 121 |
% Make the table, and finish the hbox. |
| 122 |
% Since v1.06, "\toks@" contains the preamble specification, |
| 123 |
% and possible optional argument, as well as the table body. |
| 124 |
% Well it does in |tabularx|, here the body is in an external file so |
| 125 |
% just input it. |
| 126 |
% \begin{macrocode} |
| 127 |
\input{#2}\unskip}% |
| 128 |
% \end{macrocode} |
| 129 |
% Since v1.05 reset all \LaTeX\ counters, by executing "\TX@ckpt". |
| 130 |
% \begin{macrocode} |
| 131 |
\TX@ckpt |
| 132 |
% \end{macrocode} |
| 133 |
% Print some statistics. |
| 134 |
% Added "\TX@align" in v1.05, to line up the columns. |
| 135 |
% \begin{macrocode} |
| 136 |
\TX@typeout@{\@spaces |
| 137 |
\expandafter\TX@align |
| 138 |
\the\wd\@tempboxa\space\space\space\space\space\@@ |
| 139 |
\expandafter\TX@align |
| 140 |
\the\TX@col@width\space\space\space\space\space\@@ |
| 141 |
\@spaces\the\TX@cols}}% |
| 142 |
% \end{macrocode} |
| 143 |
% \end{macro} |
| 144 |
\TX@trial{\def\NC@rewrite@X{% |
| 145 |
\global\advance\TX@cols\@ne\NC@find p{\TX@col@width}}}% |
| 146 |
\let\LT@make@row\LT@blank@row |
| 147 |
\loop |
| 148 |
\TX@arith |
| 149 |
\ifTX@ |
| 150 |
\TX@trial{}% |
| 151 |
\repeat |
| 152 |
% \end{macrocode} |
| 153 |
% On the last run, may as well run with |\setlongtables|. |
| 154 |
% \begin{macrocode} |
| 155 |
\let\LT@make@row\relax |
| 156 |
\input{#2}% |
| 157 |
\endgroup} |
| 158 |
% \end{macrocode} |
| 159 |
|
| 160 |
|
| 161 |
\end{filecontents} |
| 162 |
|
| 163 |
\documentclass{article} |
| 164 |
\setlength{\textheight}{5in} |
| 165 |
\usepackage{ltxtable} |
| 166 |
|
| 167 |
\tracingtabularx |
| 168 |
\begin{document} |
| 169 |
|
| 170 |
\title{ltxtable: longtable meets tabularx} |
| 171 |
\author{David Carlisle} |
| 172 |
\date{2021/06/13} |
| 173 |
\maketitle |
| 174 |
|
| 175 |
Since \texttt{tabularx} was put on the archives in 1992 or so I have |
| 176 |
had a constant stream of email messages asking for a merged |
| 177 |
\texttt{tabularx}/\texttt{longtable} package. |
| 178 |
|
| 179 |
Well here it is! (First draft, anyway.) |
| 180 |
|
| 181 |
Rules of the game: |
| 182 |
|
| 183 |
\begin{itemize} |
| 184 |
\item Put the \texttt{longtable} environment using \texttt{tabularx} |
| 185 |
style \texttt{X} column specifiers in a file \emph{file} on its |
| 186 |
own. (You can use the \texttt{filecontents} environment to include |
| 187 |
it back into the main document file, if you wish.) |
| 188 |
\item If you want to input the file at some point, using the |
| 189 |
\texttt{X} columns to force the table width to be \emph{width} wide, |
| 190 |
go \verb|\LTXtable{|\emph{width}\verb|}{|\emph{file}\verb|}|. |
| 191 |
\item \verb|\multicolumn|: If you read the \texttt{tabularx} and |
| 192 |
\texttt{longtable} docs you will find that both packages have a lot |
| 193 |
of fun with this command. In order to keep my sanity, for this |
| 194 |
merger I disable \texttt{longtable}'s version of \verb|\multicolumn|. |
| 195 |
This means that the column widths calculated are not always the same |
| 196 |
(not as good as) the widths that would be calculated by an |
| 197 |
equivalent \texttt{tabularx} environment. Perhaps one day I will do |
| 198 |
something about this. Perhaps. |
| 199 |
\end{itemize} |
| 200 |
|
| 201 |
\clearpage |
| 202 |
|
| 203 |
\centering |
| 204 |
|
| 205 |
|
| 206 |
A 300pt rule, just so can see the required width. |
| 207 |
|
| 208 |
\mbox{\vrule width 300pt height 1pt} |
| 209 |
|
| 210 |
First a tabularx |
| 211 |
|
| 212 |
|
| 213 |
\begingroup |
| 214 |
\renewenvironment{longtable}{\noindent\tabularx{300pt}}{\endtabularx} |
| 215 |
\def\endhead{\\}\def\endfoot{\rlap{ !!!}\\} |
| 216 |
\input{ltx1} |
| 217 |
\endgroup |
| 218 |
|
| 219 |
|
| 220 |
Then a longtable |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
\LTXtable{300pt}{ltx1} |
| 225 |
|
| 226 |
\end{document} |
| 227 |
|
| 228 |
1995/11/07 v0.1 first release |
| 229 |
1995/12/11 v0.2 (Petr Sojka) Typos fixed so the package works! |
| 230 |
(Initial release *always* read the same table file, |
| 231 |
ignoring the argument...) |
| 232 |
2001/06/12 v0.3 longtable now uses \LT@gbox not \box\@ne so change here to match. |
| 233 |
2021/06/13 v0.4 what year is it.... |