| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 1993-2025 |
| 4 |
% |
| 5 |
% The LaTeX Project and any individual authors listed elsewhere |
| 6 |
% in this file. |
| 7 |
% |
| 8 |
% This file is part of the Standard LaTeX `Tools Bundle'. |
| 9 |
% ------------------------------------------------------- |
| 10 |
% |
| 11 |
% It may be distributed and/or modified under the |
| 12 |
% conditions of the LaTeX Project Public License, either version 1.3c |
| 13 |
% of this license or (at your option) any later version. |
| 14 |
% The latest version of this license is in |
| 15 |
% https://www.latex-project.org/lppl.txt |
| 16 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 17 |
% version 2005/12/01 or later. |
| 18 |
% |
| 19 |
% The list of all files belonging to the LaTeX `Tools Bundle' is |
| 20 |
% given in the file `manifest.txt'. |
| 21 |
% |
| 22 |
% \fi |
| 23 |
% \iffalse |
| 24 |
%% File: dcolumn.dtx Copyright (C) 1992-1996 1999-2001 David Carlisle |
| 25 |
% |
| 26 |
%<*dtx> |
| 27 |
\ProvidesFile{dcolumn.dtx} |
| 28 |
%</dtx> |
| 29 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 30 |
%<package>\ProvidesPackage{dcolumn} |
| 31 |
%<driver>\ProvidesFile{dcolumn.drv} |
| 32 |
% \fi |
| 33 |
% \ProvidesFile{dcolumn.dtx} |
| 34 |
[2025/10/21 v1.06 decimal alignment package (DPC)] |
| 35 |
% |
| 36 |
% \iffalse |
| 37 |
%<*driver> |
| 38 |
\documentclass{ltxdoc} |
| 39 |
\usepackage{dcolumn} |
| 40 |
\DeleteShortVerb{\|} |
| 41 |
\begin{document} |
| 42 |
\DocInput{dcolumn.dtx} |
| 43 |
\end{document} |
| 44 |
%</driver> |
| 45 |
% \fi |
| 46 |
% |
| 47 |
% \GetFileInfo{dcolumn.dtx} |
| 48 |
% |
| 49 |
% \title{The \textsf{dcolumn} package\thanks{This file |
| 50 |
% has version number \fileversion, last |
| 51 |
% revised \filedate.}} |
| 52 |
% \author{David Carlisle} |
| 53 |
% \date{\filedate} |
| 54 |
% \author{David Carlisle} |
| 55 |
% \MaintainedByLaTeXTeam{tools} |
| 56 |
% \maketitle |
| 57 |
% |
| 58 |
% |
| 59 |
% \changes{v1.00}{1992/02/17}{Initial version} |
| 60 |
% \changes{v1.01}{1992/06/12}{Re-issue for the new doc and docstrip.} |
| 61 |
% \changes{v1.02}{1994/03/14}{Re-issue for LaTeX2e} |
| 62 |
% \changes{v1.03}{1996/02/28}{New feature, after tools/2093} |
| 63 |
% \changes{v1.05}{1999/07/05} |
| 64 |
% {Minor doc changes latex/3058} |
| 65 |
% \changes{v1.06}{2001/05/28} |
| 66 |
% {More doc changes (suggested by BNB, done by CAR) latex/3315} |
| 67 |
% \changes{v1.06}{2025/10/21} |
| 68 |
% {Minor doc changes gh/1769} |
| 69 |
% |
| 70 |
% |
| 71 |
% |
| 72 |
% \begin{abstract} |
| 73 |
% This package defines a system for defining columns of entries in an |
| 74 |
% \texttt{array} or \texttt{tabular} which are to be aligned on a |
| 75 |
% `decimal point'. |
| 76 |
% \end{abstract} |
| 77 |
% |
| 78 |
% \MakeShortVerb{\"} |
| 79 |
% |
| 80 |
% This package defines \texttt{D} to be a column specifier with three |
| 81 |
% arguments.\\ |
| 82 |
% "D{"\meta{sep.tex}"}{"\meta{sep.dvi}"}{"\meta{decimal |
| 83 |
% places}"}" |
| 84 |
% |
| 85 |
% \meta{sep.tex} should be a single character, this is used as the |
| 86 |
% separator in the \texttt{.tex} file. Thus it will usually be `\texttt{.}' or |
| 87 |
% `\texttt{,}'. |
| 88 |
% |
| 89 |
% \mbox{\meta{sep.dvi}} is used as the separator in the output, this may |
| 90 |
% be the same as the first argument, but may be any math-mode |
| 91 |
% expression, such as "\cdot". It should be noted that \texttt{dcolumn} |
| 92 |
% always uses math mode for the digits as well as the separator. |
| 93 |
% |
| 94 |
% \meta{decimal places} should be the maximum number of decimal places |
| 95 |
% in the column. If this is negative, any number of decimal places can |
| 96 |
% be used in the column, and all entries will be centred on |
| 97 |
% (the leading edge of) the |
| 98 |
% separator. Note that this can cause a column to be too wide, compare |
| 99 |
% the first two columns in the example below. If this argument is |
| 100 |
% positive, the column uses macros equivalent to "\rightdots" |
| 101 |
% "\endrightdots" commands used in an example in the documentation of |
| 102 |
% the \texttt{array} package. Otherwise the macros are |
| 103 |
% essentially equivalent to the "\centerdots" "\endcenterdots" |
| 104 |
% commands also described in the \texttt{array} package documentation. |
| 105 |
% |
| 106 |
% You may not want to use all three entries in the \texttt{array} or |
| 107 |
% \texttt{tabular} preamble, so you may define your own preamble specifiers |
| 108 |
% using "\newcolumntype". |
| 109 |
% |
| 110 |
% For example we may say: |
| 111 |
% |
| 112 |
% \noindent"\newcolumntype{d}[1]{D{.}{\cdot}{#1}}" |
| 113 |
% |
| 114 |
% \texttt{d} takes a single argument specifying the number of decimal |
| 115 |
% places, and the \texttt{.tex} file should use \texttt{.}, with $\cdot$ being |
| 116 |
% used in the output. |
| 117 |
% |
| 118 |
% \noindent"\newcolumntype{.}{D{.}{.}{-1}}" |
| 119 |
% |
| 120 |
% \texttt{.} specifies a column of entries to be centred on the~$.$. |
| 121 |
% |
| 122 |
% \noindent"\newcolumntype{,}{D{,}{,}{2}}" |
| 123 |
% |
| 124 |
% \texttt{,} specifies a column of entries with at most two decimal |
| 125 |
% places after a~$,$. |
| 126 |
% |
| 127 |
% \newcolumntype{d}[1]{D{.}{\cdot}{#1}} |
| 128 |
% \newcolumntype{.}{D{.}{.}{-1}} |
| 129 |
% \newcolumntype{,}{D{,}{,}{2}} |
| 130 |
% |
| 131 |
% The following table begins "\begin{tabular}{|d{-1}|d{2}|.|,|}" |
| 132 |
% |
| 133 |
% \begin{center} |
| 134 |
% \begin{tabular}{|d{-1}|d{2}|.|,|} |
| 135 |
% 1.2 & 1.2 &1.2 &1,2 \\ |
| 136 |
% 1.23 & 1.23 &12.5 &300,2 \\ |
| 137 |
% 1121.2& 1121.2&861.20 &674,29 \\ |
| 138 |
% 184 & 184 &10 &69 \\ |
| 139 |
% .4 & .4 & &,4 \\ |
| 140 |
% & &.4 & |
| 141 |
% \end{tabular} |
| 142 |
% \end{center} |
| 143 |
% |
| 144 |
% Note that the first column, which had a negative \meta{decimal places} |
| 145 |
% argument, is wider than the second column, so that the decimal point |
| 146 |
% appears in the middle of the column. |
| 147 |
% Also note that this package deals correctly with entries with no |
| 148 |
% decimal part, no integer part, and blank entries. |
| 149 |
% |
| 150 |
% If you have table headings (inserted with "\multicolumn{1}{c}{..}" |
| 151 |
% to over-ride the "D" column type) then it may be that neither of the |
| 152 |
% above `centred' or `right aligned' forms is quite what you want. |
| 153 |
% \begin{center}\small |
| 154 |
% \begin{tabular}[t]{|D..{-1}|D..{1}|D..{5.1}|} |
| 155 |
%\multicolumn{1}{|c|}{head}& |
| 156 |
%\multicolumn{1}{c|}{head}& |
| 157 |
%\multicolumn{1}{c|}{head}\\[3pt] |
| 158 |
% 1.2 & 1.2 &1.2 \\ |
| 159 |
% 11212.2& 11212.2&11212.2 \\ |
| 160 |
% .4 & .4 &.4 |
| 161 |
% \end{tabular} |
| 162 |
% \hfill |
| 163 |
% \begin{tabular}[t]{|D..{-1}|D..{1}|D..{1.1}|} |
| 164 |
%\multicolumn{1}{|c|}{wide heading}& |
| 165 |
%\multicolumn{1}{c|}{wide heading}& |
| 166 |
%\multicolumn{1}{c|}{wide heading}\\[3pt] |
| 167 |
% 1.2 & 1.2 &1.2 \\ |
| 168 |
% .4 & .4 &.4 |
| 169 |
% \end{tabular} |
| 170 |
% \end{center} |
| 171 |
% |
| 172 |
% In both of these tables the first column is set with "D{.}{.}{-1}" |
| 173 |
% to produce a column centered on the ".", and the second column is |
| 174 |
% set with "D{.}{.}{1}" to produce a right aligned column. |
| 175 |
% |
| 176 |
% The centered column produces columns that are wider than necessary |
| 177 |
% to fit in the numbers under a heading as it has to ensure that the |
| 178 |
% decimal point is centred. The right aligned column two does not have |
| 179 |
% this drawback, but under a wide heading a column of small right |
| 180 |
% aligned figures looks a bit odd. |
| 181 |
% |
| 182 |
% In version v1.03 a third possibility is introduced. The third |
| 183 |
% \meta{decimal places} argument may specify \emph{both} the number of |
| 184 |
% digits to the left and to the right of the decimal place. The third |
| 185 |
% column in the first table above is set with "D{.}{.}{5.1}" and in the |
| 186 |
% second table, "D{.}{.}{1.1}", to specify |
| 187 |
% `five places to the left and one to the right' and `one place to the |
| 188 |
% left and% one to the right' respectively. (You may use `,' or other |
| 189 |
% tokens, not necessarily `.' in this argument.) The column of figures |
| 190 |
% is then positioned such that a number with the specified numbers of |
| 191 |
% digits is centred in the column. |
| 192 |
% |
| 193 |
% This notation also enables columns that are centred on the mid-point |
| 194 |
% of the separator, rather than its leading edge; for example |
| 195 |
% "D{+}{\,\pm\,}{3,3}" will give nice, symmetric layout of up to three |
| 196 |
% digits on either side of a $\pm$ sign. |
| 197 |
% |
| 198 |
% \MaybeStop{} |
| 199 |
% |
| 200 |
% |
| 201 |
% \section{The Macros} |
| 202 |
% |
| 203 |
% \begin{macrocode} |
| 204 |
%<*package> |
| 205 |
% \end{macrocode} |
| 206 |
% |
| 207 |
% First we load \texttt{array.sty} if it is not already loaded. |
| 208 |
% \begin{macrocode} |
| 209 |
\RequirePackage{array} |
| 210 |
% \end{macrocode} |
| 211 |
% |
| 212 |
% The basic ideas behind these macros are explained in the documentation |
| 213 |
% for \texttt{array.sty}. However they use three |
| 214 |
% tricks which may be useful in other contexts. |
| 215 |
% \begin{itemize} |
| 216 |
% \item The separator is surrounded in extra "{ }", so that it is set |
| 217 |
% with "\mathord" spacing, otherwise, for instance a `,' would have |
| 218 |
% extra space after it. |
| 219 |
% \item The separator is not given its special definition by making it |
| 220 |
% active, as this would not work for an entry such as "& .5 &", as the |
| 221 |
% first token of an alignment entry is read {\em before\/} the preamble |
| 222 |
% part, in case it is an "\omit", in which case the preamble is to be |
| 223 |
% omitted. Instead we switch the mathcode to (hex) 8000, which makes the |
| 224 |
% token act as if it were active. |
| 225 |
% \item Although \verb|\mathcode`.="8000| makes \texttt{.} act as if it |
| 226 |
% were active, it is still not allowed in constructions such as |
| 227 |
% "\def.{}", even in math-mode, so we have to construct an active |
| 228 |
% version of the separator, this is done by making it the uppercase of |
| 229 |
% "~", and then using the construct\\ |
| 230 |
% "\uppercase{\def~}{"\meta{definition}"}".\\ |
| 231 |
% Note that the \meta{definition} is not uppercased, so the definition |
| 232 |
% can refer to the standard, non-active use of the separator. |
| 233 |
% \end{itemize} |
| 234 |
% |
| 235 |
% \begin{macro}{\DC@} |
| 236 |
% \changes{v1.03}{1996/02/28}{New feature, after tools/2093} |
| 237 |
% Set up uppercase tables as required, and then grab the first part of |
| 238 |
% the numerical argument into "\count@". |
| 239 |
% \begin{macrocode} |
| 240 |
\def\DC@#1#2#3{% |
| 241 |
\uccode`\~=`#1\relax |
| 242 |
\m@th |
| 243 |
\afterassignment\DC@x\count@#3\relax{#1}{#2}} |
| 244 |
% \end{macrocode} |
| 245 |
% \end{macro} |
| 246 |
% |
| 247 |
% \begin{macro}{\DC@x} |
| 248 |
% \changes{v1.03}{1996/02/28}{Macro added} |
| 249 |
% If "\count@" is negative, centre on the decimal point. If it is |
| 250 |
% positive either "#1" will be empty in which case pad out decimal |
| 251 |
% part to the number of digits specified by "\count@" or (new feature |
| 252 |
% in v1.03) it is none empty in which case "\count@" contains the |
| 253 |
% number of digits to the left of the point and "#1" contains a junk |
| 254 |
% token (probably ".") followed by the number of digits to the right |
| 255 |
% of the point. In either of these latter cases, "\DC@right" is used. |
| 256 |
% \begin{macrocode} |
| 257 |
\def\DC@x#1\relax#2#3{% |
| 258 |
\ifnum\z@>\count@ |
| 259 |
\expandafter\DC@centre |
| 260 |
\else |
| 261 |
\expandafter\DC@right |
| 262 |
\fi |
| 263 |
{#2}{#3}{#1}} |
| 264 |
% \end{macrocode} |
| 265 |
% \end{macro} |
| 266 |
% |
| 267 |
% \begin{macro}{\DC@centre} |
| 268 |
% If centering on the decimal point, just need to box up the two halves: |
| 269 |
% \begin{macrocode} |
| 270 |
\def\DC@centre#1#2#3{% |
| 271 |
\let\DC@end\DC@endcentre |
| 272 |
\uppercase{\def~}{$\egroup\setbox\tw@=\hbox\bgroup${#2}}% |
| 273 |
\setbox\tw@=\hbox{${\phantom{{#2}}}$}% |
| 274 |
\setbox\z@=\hbox\bgroup$\mathcode`#1="8000 } |
| 275 |
% \end{macrocode} |
| 276 |
% \end{macro} |
| 277 |
% |
| 278 |
% \begin{macro}{\DC@endcentre} |
| 279 |
% and then pad out the smaller of the two boxes so there is the same |
| 280 |
% amount of stuff either side of the point. |
| 281 |
% \begin{macrocode} |
| 282 |
\def\DC@endcentre{$\egroup |
| 283 |
\ifdim \wd\z@>\wd\tw@ |
| 284 |
\setbox\tw@=\hbox to\wd\z@{\unhbox\tw@\hfill}% |
| 285 |
\else |
| 286 |
\setbox\z@=\hbox to\wd\tw@{\hfill\unhbox\z@}\fi |
| 287 |
\box\z@\box\tw@} |
| 288 |
% \end{macrocode} |
| 289 |
% \end{macro} |
| 290 |
% |
| 291 |
% \begin{macro}{\DC@right} |
| 292 |
% \changes{v1.03}{1996/02/28}{Re-implemented, after tools/2093} |
| 293 |
% This deals with both the cases where a specified number of decimal |
| 294 |
% places is given. |
| 295 |
% \begin{macrocode} |
| 296 |
\def\DC@right#1#2#3{% |
| 297 |
\ifx\relax#3\relax |
| 298 |
% \end{macrocode} |
| 299 |
% If "#3" is empty, add "\hfill" to right align the column, and |
| 300 |
% just set "\DC@rl" to begin a group, so that nothing fancy is done with |
| 301 |
% the whole number part. |
| 302 |
% \begin{macrocode} |
| 303 |
\hfill |
| 304 |
\let\DC@rl\bgroup |
| 305 |
\else |
| 306 |
% \end{macrocode} |
| 307 |
% Otherwise set "\DC@rl" so that the whole number part is put in a |
| 308 |
% box "\count@" times as wide as a digit. |
| 309 |
% In order to share code with the other branch, move "#3" (the |
| 310 |
% number of decimal places) into "\count@" throwing away the `.' from |
| 311 |
% the user syntax. |
| 312 |
% \changes{v1.04}{1996/09/23}{Add \cs{hfill} so integer part |
| 313 |
% is still flush right if no decimal point used.} |
| 314 |
% \begin{macrocode} |
| 315 |
\edef\DC@rl{to\the\count@\dimen@ii\bgroup\hss\hfill}% |
| 316 |
\count@\@gobble#3\relax |
| 317 |
\fi |
| 318 |
% \end{macrocode} |
| 319 |
% |
| 320 |
% \begin{macrocode} |
| 321 |
\let\DC@end\DC@endright |
| 322 |
% \end{macrocode} |
| 323 |
% Box 2 contains the decimal part, set to "\dimen@" which is |
| 324 |
% calculated below to be "\count@" times the width of a digit, plus |
| 325 |
% the width of the `decimal point'. |
| 326 |
% \begin{macrocode} |
| 327 |
\uppercase{\def~}{$\egroup\setbox\tw@\hbox to\dimen@\bgroup${#2}}% |
| 328 |
\setbox\z@\hbox{$1$}\dimen@ii\wd\z@ |
| 329 |
\dimen@\count@\dimen@ii |
| 330 |
\setbox\z@\hbox{${#2}$}\advance\dimen@\wd\z@ |
| 331 |
\setbox\tw@\hbox to\dimen@{}% |
| 332 |
% \end{macrocode} |
| 333 |
% Box 0 contains the whole number part, either just at its natural |
| 334 |
% size for right aligned columns, or set to (the old value of) |
| 335 |
% "\count@" times the width of a digit. "\DC@rl" defined above |
| 336 |
% determines the two cases. |
| 337 |
% \begin{macrocode} |
| 338 |
\setbox\z@\hbox\DC@rl$\mathcode`#1="8000 } |
| 339 |
% \end{macrocode} |
| 340 |
% \end{macro} |
| 341 |
% |
| 342 |
% \begin{macro}{\DC@endright} |
| 343 |
% \changes{v1.03}{1996/02/28}{Re-implemented, after tools/2093} |
| 344 |
% Just finish off the second box, and then put out both boxes. |
| 345 |
% \begin{macrocode} |
| 346 |
\def\DC@endright{$\hfil\egroup\box\z@\box\tw@} |
| 347 |
% \end{macrocode} |
| 348 |
% \end{macro} |
| 349 |
% |
| 350 |
% \begin{macro}{D} |
| 351 |
% The user interface, define the \texttt{D} column to take three arguments. |
| 352 |
% For special purposes, you may need to directly access "\DC@" rather |
| 353 |
% than the "D" column, eg to get a bold version you could use |
| 354 |
%\begin{verbatim} |
| 355 |
% \newcolumntype{E}[3]{>{\boldmath\DC@{#1}{#2}{#3}}c<{\DC@end}} |
| 356 |
%\end{verbatim} |
| 357 |
% \begin{macrocode} |
| 358 |
\newcolumntype{D}[3]{>{\DC@{#1}{#2}{#3}}c<{\DC@end}} |
| 359 |
%</package> |
| 360 |
% \end{macrocode} |
| 361 |
% \end{macro} |
| 362 |
% |
| 363 |
% |
| 364 |
% \Finale |
| 365 |
\endinput |