Debian Codegraph @

texmf-dist/source/latex/tabularborder/tabularborder.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) Johannes Fink
4 % -----------------------------------
5 %
6 % This file may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either version 1.2
8 % of this license or (at your option) any later version.
9 % The latest version of this license is in:
10 %
11 % http://www.latex-project.org/lppl.txt
12 %
13 % and version 1.2 or later is part of all distributions of LaTeX
14 % version 1999/12/01 or later.
15 %
16 % \fi
17 %
18 % \iffalse
19 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
20 %<package>\ProvidesPackage{tabularborder}
21 %<package> [2010/04/14 v1.0a Tabular without border]
22 %
23 %<*driver>
24 \documentclass{ltxdoc}
25 \usepackage{tabularborder}
26
27 \EnableCrossrefs
28
29 \CodelineIndex
30
31 \RecordChanges
32
33 %\OnlyDescription
34
35 \begin{document}
36 \DocInput{tabularborder.dtx}
37 \end{document}
38 %</driver>
39 % \fi
40 %
41 % \CheckSum{162}
42 %
43 % \CharacterTable
44 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
45 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
46 % Digits \0\1\2\3\4\5\6\7\8\9
47 % Exclamation \! Double quote \" Hash (number) \#
48 % Dollar \$ Percent \% Ampersand \&
49 % Acute accent \' Left paren \( Right paren \)
50 % Asterisk \* Plus \+ Comma \,
51 % Minus \- Point \. Solidus \/
52 % Colon \: Semicolon \; Less than \<
53 % Equals \= Greater than \> Question mark \?
54 % Commercial at \@ Left bracket \[ Backslash \\
55 % Right bracket \] Circumflex \^ Underscore \_
56 % Grave accent \` Left brace \{ Vertical bar \|
57 % Right brace \} Tilde \~}
58 %
59 %
60 % \changes{v1.0}{2010/04/03}{Initial version}
61 %
62 % \GetFileInfo{tabularborder.sty}
63 %
64 % \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ }
65 % \DoNotIndex{\@ne}
66 % \DoNotIndex{\advance,\begingroup,\catcode,\closein}
67 % \DoNotIndex{\closeout,\day,\def,\edef,\else,\empty,\endgroup}
68 % \DoNotIndex{\bgroup,\egroup,\newcommand}
69 % \DoNotIndex{\ifx,\fi}
70 % \DoNotIndex{\let}
71 %
72 % \title{The \textsf{tabularborder} package
73 % \thanks{This document corresponds to \textsf{tabularborder}~\fileversion,
74 % dated \filedate.}}
75 % \author{Johannes Fink\\
76 % \iffalse\texttt{[email protected]}\fi
77 % }
78 %
79 % \maketitle
80 %
81 % \begin{abstract}
82 % This package changes the space for horizontal lines
83 % at the left side and the right side of a |tabular| (but not |array|) to zero space.
84 %
85 % \end{abstract}
86 % \tableofcontents
87 % \section{Introduction}
88 % Usually, the |tabular| environment adds a space of |\tabcolsep| on the left side and on the right
89 % side of the text. For this reason a |\hline|, or a |\toprule|, etc. will exceed the text by
90 % the total length of 2 |\tabcolsep|.
91 % \tboff\vskip3ex
92 %
93 % \begin{tabular}{llll}
94 % \toprule
95 % col 1 & col 2 & col 3 & col4\\
96 % \multicolumn{2}{l}{multicol 1-2}
97 % & \multicolumn{2}{l}{multicol 3-4}\\
98 % \bottomrule
99 % \end{tabular}
100 %
101 % \begin{verbatim}
102 % \begin{tabular}{llll}
103 % \toprule
104 % col 1 & col 2 & col 3 & col4\\
105 % \multicolumn{2}{l}{multicol 1-2}
106 % & \multicolumn{2}{l}{multicol 3-4}\\
107 % \bottomrule
108 % \end{tabular}
109 % \end{verbatim}
110 %
111 %
112 % If some publishers, or authors, respectively, do
113 % not like these additional length of the horizontal lines, the |tabular| must be reformatted.
114 %
115 % \vskip3ex
116 %
117 % \begin{tabular}{@{}llll@{}}
118 % \toprule
119 % col 1 & col 2 & col 3 & col4\\
120 % \multicolumn{2}{@{}l}{multicol 1-2}
121 % & \multicolumn{2}{l@{}}{multicol 3-4}\\
122 % \bottomrule
123 % \end{tabular}
124 %
125 % \begin{verbatim}
126 % \begin{tabular}{@{}llll@{}}
127 % \toprule
128 % col 1 & col 2 & col 3 & col4\\
129 % \multicolumn{2}{@{}l}{multicol 1-2}
130 % & \multicolumn{2}{l@{}}{multicol 3-4}\\
131 % \bottomrule
132 % \end{tabular}
133 % \end{verbatim}
134 %
135 % Formatting is done with |@{}|, as shown above. Note that the |\multicolumn| commands must
136 % be formatted separately.
137 % In a longer project, such as a thesis or book,
138 % this reformatting may be a time consuming and a tedious task.
139 % In particular, if the supervisor of a thesis work changes his opinion about the layout several times
140 % in the course of correcting.
141 %
142 % This package changes the leading and trailing spaces automatically into zero without the need of inserting the |@{}|.
143 % \tbon\vskip3ex
144 % \begin{center}
145 % \begin{tabular}{llll}
146 % \toprule
147 % col 1 & col 2 & col 3 & col4\\
148 % \multicolumn{2}{l}{multicol 1-2}
149 % & \multicolumn{2}{l}{multicol 3-4}\\
150 % \bottomrule
151 % \end{tabular}
152 % \end{center}
153 %
154 %
155 % Of course, with such an arrangement, outer
156 % vertical lines do not make sense,
157 % and actually, they are displaced if tried anyway.
158 % By the way, we are using here the package |booktabs|.
159 %
160 %
161 %
162 % \section{Usage}
163 %
164 % Here are some examples:
165 % \subsection{Basic Example}
166 % \begin{center}
167 % \begin{tabular}{llll}
168 % \toprule
169 % col 1 & col 2 & col 3 & col4\\
170 % \multicolumn{2}{l}{multicol 1-2}
171 % & \multicolumn{2}{l}{multicol 3-4}\\
172 % \bottomrule
173 % \end{tabular}
174 % \end{center}
175 % %
176 % Source code:
177 % \begin{verbatim}
178 % \begin{tabular}{llll}
179 % \toprule
180 % col 1 & col 2 & col 3 & col4\\
181 % \multicolumn{2}{l}{multicol 1-2}
182 % & \multicolumn{2}{l}{multicol 3-4}\\
183 % \bottomrule
184 % \end{tabular}
185 % \end{verbatim}
186 %
187 % \subsection{Odd Example}
188 % Vertical lines look odd here:
189 %
190 % \begin{center}
191 % \begin{tabular}{|ll|ll|}
192 % \hline
193 % col 1 & col 2 & col 3 & col4\\
194 % \multicolumn{2}{l}{multicol 1-2}
195 % & \multicolumn{2}{l}{multicol 3-4}\\
196 % \hline
197 % \end{tabular}
198 % \end{center}
199 % %
200 % Source code:
201 % \begin{verbatim}
202 % \begin{tabular}{|ll|ll|}
203 % \hline
204 % col 1 & col 2 & col 3 & col4\\
205 % \multicolumn{2}{l}{multicol 1-2}
206 % & \multicolumn{2}{l}{multicol 3-4}\\
207 % \hline
208 % \end{tabular}
209 % \end{verbatim}
210 %
211 % \subsection{Improved Example}
212 % But we may switch off the |tabularborder| package with |\tboff|.
213 % \tboff
214 % \begin{center}
215 % \begin{tabular}{|ll|ll|}
216 % \hline
217 % col 1 & col 2 & col 3 & col4\\
218 % \multicolumn{2}{|l|}{multicol 1-2}
219 % & \multicolumn{2}{l|}{multicol 3-4}\\
220 % \hline
221 % \end{tabular}
222 % \end{center}
223 % %
224 % Source code:
225 % \begin{verbatim}
226 % \begin{tabular}{|ll|ll|}
227 % \hline
228 % col 1 & col 2 & col 3 & col4\\
229 % \multicolumn{2}{|l|}{multicol 1-2}
230 % & \multicolumn{2}{l|}{multicol 3-4}\\
231 % \hline
232 % \end{tabular}
233 % \end{verbatim}
234 % But we had still to manipulate the |\multicolumn| command.
235 % And now switch on again with |\tbon|. \tbon
236 % \subsection{Sophisticated Example}
237 %
238 % %
239 % \begin{center}
240 % \begin{tabular}{>{\sf}l|r@{}l}
241 % \toprule
242 % Article & \multicolumn{2}{c}{Price/[USD]} \\
243 % \midrule
244 % Beer & \hskip4ex 3&.40\\
245 % Whisky & 8&.20 \\
246 % \bottomrule
247 % \end{tabular}
248 % \end{center}
249 %
250 % Source code:
251 % \begin{verbatim}
252 % \begin{tabular}{>{\sf}l|r@{}l}
253 % \toprule
254 % Article & \multicolumn{2}{c}{Price/[USD]} \\
255 % \midrule
256 % Beer & \hskip4ex 3&.40\\
257 % Whisky & 8&.20 \\
258 % \bottomrule
259 % \end{tabular}
260 % \end{verbatim}
261 %
262 %
263 % \subsection{Example Using Helpers}
264 %
265 % \begin{tabular}
266 % {b{0.5\tabcolwidthii\hangindent2ex}%
267 % b{0.5\tabcolwidthii\hangindent2ex}}
268 % \toprule
269 % Article & Remark \\
270 % \midrule
271 % Beer & Note that this article
272 % can be sold only
273 % in special shops\\
274 % Whisky & --- \\
275 % \bottomrule
276 % \end{tabular}
277 % \vskip3ex
278 % Source code:
279 % \begin{verbatim}
280 % \begin{tabular}
281 % {b{0.5\tabcolwidthii\hangindent2ex}%
282 % b{0.5\tabcolwidthii\hangindent2ex}}
283 % \toprule
284 % Article & Remark \\
285 % \midrule
286 % Beer & Note that this article
287 % can be sold only
288 % in special shops\\
289 % Whisky & --- \\
290 % \bottomrule
291 % \end{tabular}
292 % \end{verbatim}
293 %
294 % \subsection{Example Using Helpers}
295 % \label{2010.04.03.17:45}
296 %
297 % \begin{tabular}
298 % {b{0.25\tabcolwidthiv\hangindent2ex}%
299 % b{0.25\tabcolwidthiv\hangindent2ex}%
300 % b{0.25\tabcolwidthiv\hangindent2ex}%
301 % b{0.25\tabcolwidthiv\hangindent2ex}}%
302 % \toprule
303 % Article &\hskip-2ex Code & \hskip-4ex Subcode & Remark\\
304 % \midrule
305 % Beer &B&12 & Note that this article
306 % can be sold only
307 % in special shops\\
308 % Whisky &W&10& --- \\
309 % \bottomrule
310 % \end{tabular}
311 % \vskip3ex
312 % Source code:
313 % \begin{verbatim}
314 % \begin{tabular}
315 % {b{0.25\tabcolwidthiv\hangindent2ex}%
316 % b{0.25\tabcolwidthiv\hangindent2ex}%
317 % b{0.25\tabcolwidthiv\hangindent2ex}%
318 % b{0.25\tabcolwidthiv\hangindent2ex}}%
319 % \toprule
320 % Article &\hskip-2ex Code & \hskip-4ex Subcode & Remark\\
321 % \midrule
322 % Beer &B&12 & Note that this article
323 % can be sold only
324 % in special shops\\
325 % Whisky &W&10& --- \\
326 % \bottomrule
327 % \end{tabular}
328 % \end{verbatim}
329 %
330 % \subsection{Array Example}
331 % The |array| environment is left as before:
332 % \[
333 % \begin{array}{lcr}
334 % \toprule
335 % x^2+y^2 &=& z^2\\
336 % \end{array}
337 % \]
338 % \vskip3ex
339 % Source code:
340 % \begin{verbatim}
341 % \[
342 % \begin{array}{lcr}
343 % \toprule
344 % x^2+y^2 &=& z^2\\
345 % \end{array}
346 % \]
347 % \end{verbatim}
348 % \subsection{Example Using Tabular Star Form}
349 %
350 % The following does not make sense:
351 % \vskip3ex
352 % \begin{tabular*}{0.5\textwidth}{@{}lr}
353 % \toprule
354 % first column & second column\\
355 % first column & next second column\\
356 % \bottomrule
357 % \end{tabular*}
358 %
359 % \vskip3ex
360 % Source code:
361 % \vskip3ex
362 %
363 %
364 % \begin{verbatim}
365 % \begin{tabular*}{0.5\textwidth}{@{}lr}
366 % \toprule
367 % first column & second column\\
368 % first column & next second column\\
369 % \bottomrule
370 % \end{tabular*}
371 % \end{verbatim}
372 %
373 %
374 %
375 % \subsection{Nested Tabular Example}
376 %
377 % A nested tabular:
378 % \vskip3ex
379 % \begin{tabular}{ll}
380 % \toprule
381 % first column & second column\\
382 % first column & next second column\\
383 % \bottomrule
384 % \multicolumn{2}{l}
385 % {\begin{tabular}{ll}
386 % \textsuperscript{a} & A nested tabular, longer in this field now \\
387 % \end{tabular}}\\
388 % \end{tabular}
389 %
390 % \vskip3ex
391 % Source code:
392 % \vskip3ex
393 %
394 %
395 % \begin{verbatim}
396 % \begin{tabular}{ll}
397 % \toprule
398 % first column & second column\\
399 % first column & next second column\\
400 % \bottomrule
401 % \multicolumn{2}{l}
402 % {\begin{tabular}{ll}
403 % \textsuperscript{a} & A nested tabular, longer in this field now \\
404 % \end{tabular}}\\
405 % \end{tabular}
406 % \end{verbatim}
407 %
408 %
409 %
410 %
411 %
412 %
413 % \StopEventually{\PrintIndex}
414 %
415 % \section{Implementation}
416 %
417 %\iffalse
418 %<*package>
419 %\fi
420 % \begin{macro}{\RequirePackage}
421 % This package has been tested based on the following package:
422 % \begin{macrocode}
423 \RequirePackage{booktabs}
424 \RequirePackage{array}[2003/12/17 v2.4a Tabular extension package (FMi)]
425 % \end{macrocode}
426 % However, the examples given here are working with version |v2.4c| too.
427 % \end{macro}
428 % \begin{macro}{\tb@ialign}
429 % We redefine |\ialign|, |\tabskip| into |-\col@sep|:
430 % \begin{macrocode}
431 \newcommand{\tb@ialign}{\everycr{}\tabskip-\col@sep\halign}
432 % \end{macrocode}
433 % Here we change definitions so that only the |tabular| is involved.
434 % \begin{macrocode}
435 \newcommand{\tb@tbtabarray}{\@ifnextchar[{\tb@array}{\tb@array[c]}}
436 \def\@tabular{%
437 \leavevmode
438 \hbox \bgroup $\col@sep\tabcolsep \let\d@llarbegin\begingroup
439 \let\d@llarend\endgroup
440 \@tb@tbtabarray}
441 % \end{macrocode}
442 % \end{macro}
443 % \begin{macro}{\tbon \tboff}
444 % The following allows to switch back to the original settings by |\tboff| and reactivate by |\tbon|.
445 % \begin{macrocode}
446 \newcommand{\@tb@tbtabarray}{}
447 \newcommand{\tbon}{\global\let\@tb@tbtabarray\tb@tbtabarray}
448 \tbon
449 \newcommand{\tboff}{\global\let\@tb@tbtabarray\@tabarray}
450 % \end{macrocode}
451 % \end{macro}
452 % \begin{macro}{\tb@array}
453 % We change the definition of the macro |\@@array| and rename it.
454 % Only three changes are needed, but we must place the full macro.
455 % \begin{macrocode}
456 \newcommand{\tb@array}{}
457 \def\tb@array[#1]#2{%
458 \@tempdima \ht \strutbox
459 \advance \@tempdima by\extrarowheight
460 \setbox \@arstrutbox \hbox{\vrule
461 \@height \arraystretch \@tempdima
462 \@depth \arraystretch \dp \strutbox
463 \@width \z@}%
464 % \end{macrocode}
465 % \begin{macrocode}
466 \begingroup
467 \@mkpream{#2}%
468 % \end{macrocode}
469 % Here we use |\tb@ialign|, and in the next line we reset the |\tabskip|.
470 % \begin{macrocode}
471 \xdef\@preamble{\noexpand \tb@ialign \@halignto
472 \bgroup \@arstrut \tabskip \z@skip \@preamble
473 % \end{macrocode}
474 % In the next line we are switching the |\tabskip| to
475 % |-\col@sep|.
476 % \begin{macrocode}
477 \tabskip-\col@sep \cr}%
478 % \end{macrocode}
479 % The rest of the macro is unchanged.
480 % \begin{macrocode}
481 \endgroup
482 \@arrayleft
483 \if #1t\vtop \else \if#1b\vbox \else \vcenter \fi \fi
484 \bgroup
485 \let \@sharp ##\let \protect \relax
486 \lineskip \z@
487 \baselineskip \z@
488 \m@th
489 \let\\\@arraycr \let\tabularnewline\\\let\par\@empty \@preamble}
490 % \end{macrocode}
491 % \end{macro}
492 %
493 % \subsection{Additional Helpers}
494 % Here are some additional definitions that facilitate the handling of a tabular.
495 % An example is given in section \ref{2010.04.03.17:45}.
496 % \begin{macrocode}
497 \ifdefined\tabcolwidthi\else\newlength{\tabcolwidthi}\fi
498 \ifdefined\tabcolwidthii\else\newlength{\tabcolwidthii}\fi
499 \ifdefined\tabcolwidthiii\else\newlength{\tabcolwidthiii}\fi
500 \ifdefined\tabcolwidthiv\else\newlength{\tabcolwidthiv}\fi
501 \setlength{\tabcolwidthi}{\textwidth}
502 \addtolength{\tabcolwidthi}{-0\tabcolsep}
503 \setlength{\tabcolwidthii}{\textwidth}
504 \addtolength{\tabcolwidthii}{-2\tabcolsep}
505 \setlength{\tabcolwidthiii}{\textwidth}
506 \addtolength{\tabcolwidthiii}{-4\tabcolsep}
507 \setlength{\tabcolwidthiv}{\textwidth}
508 \addtolength{\tabcolwidthiv}{-6\tabcolsep}
509 % \end{macrocode}
510 %\iffalse
511 %</package>
512 %\fi
513 % \PrintChanges
514 % \Finale
515 \endinput