% \iffalse META-COMMENT % % The rccol package for use with TeX / LaTeX % Copyright 2000 % Eckhart Guthoehrlein % e-mail % % This program may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either version 1.2 % of this license or (at your option) any later version. % The latest version of this license is in % http://www.latex-project.org/lppl.txt % and version 1.2 or later is part of all distributions of LaTeX % version 1999/12/01 or later. % % This program consists of the files 'rccol.dtx' and 'rccol.ins'. % % The package provides a special column type for tables. % Numbers are centered to the title and flush right to each other, % as well as rounded to a given accuracy. It needs the % array package (sould be part of your LaTeX-distribution) % and the fltpoint package (by the author, available from CTAN, % directory /tex-archive/macros/latex/contrib/supported/fltpoint). % % Run TeX over rccol.ins to produce the docstripped version % of the file. The documentation can be typeset by running % LaTeX over rccol.dtx. You can use the docstrip utility % with option 'driver' to generate a separate file for the % generation of the user guide. % % Comments and bug-reports are welcome under the above % e-mail address. % % E.W.G. % % % \fi ^^A end meta-comment % \CheckSum{314} % \CharacterTable % {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 % 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 % Digits \0\1\2\3\4\5\6\7\8\9 % Exclamation \! Double quote \" Hash (number) \# % Dollar \$ Percent \% Ampersand \& % Acute accent \' Left paren \( Right paren \) % Asterisk \* Plus \+ Comma \, % Minus \- Point \. Solidus \/ % Colon \: Semicolon \; Less than \< % Equals \= Greater than \> Question mark \? % Commercial at \@ Left bracket \[ Backslash \\ % Right bracket \] Circumflex \^ Underscore \_ % Grave accent \` Left brace \{ Vertical bar \| % Right brace \} Tilde \~} % % % ^^A The often-used and not very interesting example table... % \newcommand{\tabexample}{% % \hline % \multicolumn{1}{c}{Value 1} & \multicolumn{1}{c}{Value 2} & % \multicolumn{1}{c}{Value 3}\tabularnewline % \hline % 2345,765 & 1,6 & 21 \tabularnewline % 45,130 & 0,2 & 1,65\tabularnewline % 543,99 & 2 & 9,9 \tabularnewline % \hline % \end{tabular}} % % % \DoNotIndex{\def,\edef,\xdef,\gdef,\let,\global,\if,\ifx,\else,\fi, % \loop,\repeat,\noexpand,\expandafter,\newtoks,\newif,\ignorespaces, % \unskip,\setbox,\dimen,\count,\advance,\multiply,\divide,\wd, % \relax,\hskip,\the,\hfil,\hfill,\hbox,\ifnum, % \@ifnextchar,\tabularnewline,\documentclass,\usepackage, % \OnlyDescription,\AlsoImplementation,\EnableCrossrefs, % \DisableCrossrefs,\CodelineIndex,\RecordChanges,\DocInput, % \begin,\end,\NeedsTeXFormat,\DeclareOption,\ProvidesPackage, % \AtBeginDocument,\ProcessOptions,\RequirePackage, % \ar@getul,\ar@getll} % % \MakeShortVerb{\"} % % \changes{v1.0a}{2000/08/23}{First public release.} % \changes{v1.1a}{2000/09/05}{Minor corrections. % Better support for different decimal signs.} % % \GetFileInfo{rccol.sty} % \title{The \texttt{rccol} package\thanks{This % file has version number \fileversion{} dated \filedate.}} % \author{Eckhart Guth\"ohrlein\thanks{Send comments % or bug-reports to the author via e-mail \texttt{}.}} % \date{Printed \today} % \maketitle % % \begin{abstract} % This package provides a new % \lq right-centered\rq\ tabular column type \texttt{R}. Numbers % are centered with respect to other entries, but flushed right % to each other so that corresponding digits are vertically % aligned. Furthermore, numbers can be rounded % to the desired precision. % \end{abstract} % % % % \section{Introduction} % % It is often desirable to produce tables like the following. % \begin{center} % \begin{tabular}{R{4}{3}R{1}{1}R{2}{2}} % \tabexample % \end{center} % You can see what is ment by \lq right-centered\rq\ columns: % The center of the largest number is centered with % the title, while the numbers are aligned % with the corresponding digits. This is, at least to the author's % opinion, the most aesthetic way to typeset numbers in a table. % % This package provides a general and easy-to-use solution for this % problem. In addition, the numbers given as alignment entries can be % rounded to the given precision. % % The \texttt{rccol} package needs the \texttt{array}~\cite{array} % and the \texttt{fltpoint}~\cite{fltpoint} packages. % % % \section{User interface} % The new column type "R" is used as normally in the preamble of a % \LaTeX\ table. It takes two mandatory arguments: the number of % digits before and the number of digits after the decimal sign. % The example table above has been produced by % \begin{verbatim} % \begin{tabular}{R{4}{3}R{1}{1}R{2}{2}} % \hline % \multicolumn{1}{c}{Value 1} & \multicolumn{1}{c}{Value 2} & % \multicolumn{1}{c}{Value 3}\tabularnewline % \hline % 2345,765 & 1,6 & 21 \tabularnewline % 45,130 & 0,2 & 1,65\tabularnewline % 543,99 & 2 & 9,9 \tabularnewline % \hline % \end{tabular} % \end{verbatim} % % \DescribeMacro\rcRoundingtrue\DescribeMacro\rcRoundingfalse % By default, numbers are rounded to the given number of digits % after the decimal sign, and trailing zeros are appended if they are % missing in the input file. This behaviour can be toggled % with the switch "\rcRoundingtrue"/"\rcRoundingfalse", obeying % the normal grouping rules, and with the package options % \texttt{rounding} or \texttt{norounding} (see below.) % With "\rcRoundingfalse", the above input results into the following % result. Numbers are not rounded or altered in any way; trailing % zeros are not appended. % \begin{center} % \rcRoundingfalse % \begin{tabular}{R{4}{3}R{1}{1}R{2}{2}} % \tabexample % \end{center} % % The "R" column specifier also has takes optional arguments % (thanks go to Rolf Niepraschk for suggesting this and % encouraging me). The optional parameters % determine the characters used for the decimal sign in the % input (\texttt{.tex}) and the output file (\texttt{.dvi} or % perhaps \texttt{.pdf}), so the full syntax for the "R" column is % \begin{flushleft} % "\begin{tabular}{...R["\meta{character}"]["\meta{character}"]{"% % \meta{number}"}{"\meta{number}"}...}" % \end{flushleft} % For example, "R[,][.]{1}{1}" will produce a column centered for % numbers with one digit before and one after the decimal sign, which % is a comma in the input file, but a point in the output. % If only one optional parameter is given, this character will be used % for input and output, so "R[!]{1}{1}" is equivalent to % "R[!][!]{1}{1}". % % \DescribeMacro\rcDecimalSign\DescribeMacro\rcDecimalSignInput % \DescribeMacro\rcDecimalSignOutput % The decimal sign can be changed with the commands "\rcDecimalSign", % affecting both input and output. It can be changed separately % for input and output with % "\rcDecimalSignInput" and "\rcDecimalSignOutput". These commands % obey the normal grouping rules. Furthermore, there are some % package options for setting the defaults (see below). % To give an example, let's typeset the above table once again, but with % "\rcDecimalSignOutput{\cdot}". % \begin{center} % \rcDecimalSignOutput{\cdot} % \begin{tabular}{R{4}{3}R{1}{1}R{2}{2}} % \tabexample % \end{center} % % % \section{Package Options} % The \texttt{rccol} package can be loaded as any \LaTeX\ package via % \begin{flushleft} % "\usepackage["\meta{option list}"]{rccol}" % \end{flushleft} % with the following options. % \begin{description} % \item[rounding] Enable rounding, equivalent to % "\rcRoundingtrue" at the beginning of the document. % This is the default, so explicitly using this option is not % necessary. % \item[norounding] Disable rounding by default, equivalent to % "\rcRoundingfalse" at the beginning of the document. % \item[comma] Use a comma as the decimal sign, equivalent to % "\rcDecimalSign{,}" at the beginning of the document. This is % the default, so it is normally not necessary to explicitly % give this option. % \item[german] See comma. % \item[english] Use a point as the decimal sign, equivalent % to "\rcDecimalSign{.}" at the beginning of the document. % \item[USenglish] See english. % \item[point] See english. % \end{description} % % % \section{Additional hints and remarks} % % \begin{itemize} % \item Numbers are typeset in math mode, so a minus sign will % look correctly (`$-$', not `-'). The sign of the number does not % influence the width of the alignment entry, so the widest % entry will not be exactly centered if there are negative numbers. % (The number without the sign is centered.) % You can specify one more digit before the decimal sign than really % present to overcome this, if you want, shifting the numbers to the % right. See also one of the remarks below concerning this topic. % % \item Any tokens in the alignment entries which are not digits % are put in front of the alignment entry. This can be used % to switch to bold face or to add something like `$>$' before the % number. If the tokens have any width, it is your job % to correct this, e.\,g. by putting them into a "\makebox[0pt][r]". % You must enclose command with arguments inside an extra pair % of curly braces to keep them together, otherwise error messages % will occur. Example: % \begin{verbatim} % \begin{tabular}{R{4}{3}R{1}{1}R{2}{2}} % \hline % \multicolumn{1}{c}{Value 1} & \multicolumn{1}{c}{Value 2} & % \multicolumn{1}{c}{Value 3}\tabularnewline % \hline % 2345,765 & {\mathversion{bold}} 1,6 & 21 \tabularnewline % 45,130 & 0,2 & 1,65 \tabularnewline % 543,99 & {\makebox[0mm][r]{$>{}$}}2 & 9,9 \tabularnewline % \hline % \end{tabular} % \end{verbatim} % Result: % \begin{center} % \begin{tabular}{R{4}{3}R{1}{1}R{2}{2}} % \hline % \multicolumn{1}{c}{Value 1} & \multicolumn{1}{c}{Value 2} & % \multicolumn{1}{c}{Value 3}\tabularnewline % \hline % 2345,765 & {\mathversion{bold}} 1,6 & 21 \tabularnewline % 45,130 & 0,2 & 1,65 \tabularnewline % 543,99 & {\makebox[0mm][r]{$>{}$}}2 & 9,9 \tabularnewline % \hline % \end{tabular} % \end{center} % % \item Negative values are allowed as arguments for the \texttt{R} % column. This makes it possible to round to multiples of ten, for % example, by giving `\texttt{-2}' as the second mandatory argument. % In general, rounding is performed to a precision % of $10^{-n}$, if $n$ is the second mandatory argument of % \texttt{R}. % % \item The first mandatory argument of the \texttt{R} column % specifier does not need to be the real number of digits % before the decimal point. % You can shift the output to the left or to the right by % changing this value if you are not satisfied by the centered % result. Negative values are legal. % % \item As with any macro, single token arguments can be given without % braces. This means that `"R{4}{3}"' is equivalent to `"R43"'. Maybe % you will prefer the shorter alternative. % \end{itemize} % % \section{To do} % % \begin{itemize} % \item Print numbers with floating decimal point, e.\,g., % $1{,}54\mathrm{E}{-1}$ or $3{,}7\cdot 10^4$. However, this is % rather an issue for the \texttt{fltpoint} package. % \item A better interface for setting default parameters using % a key-value-processing for the package options, allowing to say % something like % \begin{flushleft} % "\usepackage[indecsign={,},outdecsign=.]{rccol}". % \end{flushleft} % \item Detection of packages \texttt{babel} and \texttt{german} % and automatic adaption of the decimal sign. % \end{itemize} % % \StopEventually{% % \begin{thebibliography}{1} % \bibitem{array} Frank Mittelbach, David Carlisle, ``A new % implementation of \LaTeX's \texttt{tabular} and \texttt{array} % environment'', v2.3m, last revised 1998/05/13. The % \texttt{array} package is part of the standard \LaTeX\ % distribution. % \bibitem{fltpoint} Eckhart Guth\"ohrlein, ``The \texttt{fltpoint} % package'', v1.0c, last revised 2000/09/05. The \texttt{fltpoint} % package is available from CTAN. % \end{thebibliography}% % } % % \section{Implementation} % % \subsection{DriverFile} % The \texttt{docstrip} utility can be used to generate % a driver file producing the documentation. % \begin{macrocode} %<*driver> \documentclass{ltxdoc} \usepackage{rccol} \OnlyDescription % typeset only user documentation %\AlsoImplementation % typeset implementation details %\EnableCrossrefs % disable if index is ready %\CodelineIndex % index using codeline numbers %\RecordChanges % keep change log \DisableCrossrefs % disable cross-references \begin{document} \DocInput{rccol.dtx} \end{document} % % \end{macrocode} % % \subsection{\LaTeX\ package info and options} % \begin{macrocode} %<*rcmain> \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{rccol}[2000/09/05 v1.1a right-centered columns] \DeclareOption{rounding}{\AtBeginDocument{\rcRoundingtrue}} \DeclareOption{norounding}{\AtBeginDocument{\rcRoundingfalse}} \DeclareOption{USenglish}{\AtBeginDocument{\rcDecimalSign.}} \DeclareOption{english}{\AtBeginDocument{\rcDecimalSign.}} \DeclareOption{point}{\AtBeginDocument{\rcDecimalSign.}} \DeclareOption{german}{\AtBeginDocument{\rcDecimalSign,}} \DeclareOption{comma}{\AtBeginDocument{\rcDecimalSign,}} \ProcessOptions*\relax % \end{macrocode} % \subsection{Require packages} % To work properly, \texttt{rccol} needs the \texttt{array} and % the \texttt{fltpoint} packages. An up-to-date version of % \texttt{fltpoint} is necessary. % \begin{macrocode} \RequirePackage{array} \RequirePackage{fltpoint}[2000/09/05] % \end{macrocode} % % % \subsection{Registers \& Co} % % \begin{macro}{\rc@digits} % \changes{v1.1a}{2000/09/95}{Read all digits into one register, % no more separation of pre- and afterpoint digits.} % \begin{macro}{\rc@othertoks} % \begin{macro}{\ifrcRounding} % \changes{v1.1a}{2000/09/05}{Rounding switch prefixed with `rc'.} % The token registers "\rc@digits" and "\rc@othertoks" are allocated. % Initialize "\ifrcRounding" as \texttt{true}. % \begin{macrocode} \newtoks\rc@digits \newtoks\rc@othertoks \newif\ifrcRounding \rcRoundingtrue % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % % % \subsection{Definition of the \texttt{R} column} % % \changes{v1.1a}{2000/09/05}{Optional parameters for the column % specifier.} % \begin{macro}{\NC@rewrite@R} % \begin{macro}{\rc@rewrite@} % \begin{macro}{\rc@rewrite@@} % \begin{macro}{\rc@rewrite@@@} % The "\newcolumntype" mechanism of \texttt{array.sty} is used % to set up the new column type. In order to have optional % parameters, the rewrite macro is redefined to take one or % two optional parameters, read by "\rc@rewrite@" and % "\rc@rewrite@@". The optional parameters are used % to change the decimal sign inside the column if this is % desired. An appropriate "\fpDecimalSign" is put into % the token registers "\rc@digits" (input) and "\rc@othertoks" % (output), which are somewhat misused for that purpose. % The macro "\rc@rewrite@@@" reads the two mandatory arguments % (the number of digits before and after the decimal point) % and appends everything to the preamble so far. At the % end "\NC@find" is called to continue the rewriting % process (see~\cite{array} for further details). % \begin{macrocode} \newcolumntype{R}{} \def\NC@rewrite@R{% \rc@digits{\fpDecimalSign\rc@decimalsigninput}% \rc@othertoks{\fpDecimalSign\rc@decimalsignoutput}% \@ifnextchar[{\rc@rewrite@}{\rc@rewrite@@@}} \def\rc@rewrite@[#1]{% \rc@digits{\fpDecimalSign#1}% \@ifnextchar[{\rc@rewrite@@}% {\rc@othertoks{\fpDecimalSign#1}\rc@rewrite@@@}} \def\rc@rewrite@@[#1]{% \rc@othertoks{\fpDecimalSign#1}\rc@rewrite@@@} \def\rc@rewrite@@@#1#2{% \edef\rc@rewrite@scratch{\the\@temptokena>{\the\rc@digits \noexpand\rc@begin}c<{\noexpand\rc@end\the\rc@othertoks \noexpand\rc@write{#1}{#2}}} \@temptokena\expandafter{\rc@rewrite@scratch}% \NC@find} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % % % \subsection{Macros for reading and processing the numbers} % % \begin{macro}{\rc@begin} % The macro "\rc@begin" is inserted in front of every "R" alignment % entry. It initializes the token registers "\rc@digits" and % "\rc@othertoks" and calls "\rc@getnexttok" to read the following % tokens. % \begin{macrocode} \def\rc@begin{% \rc@digits={}% \rc@othertoks={}% \rc@getnexttok } % \end{macrocode} % \end{macro} % % \begin{macro}{\rc@getnexttok} % \begin{macro}{\rc@savedigit} % \begin{macro}{\rc@savetok} % The macro "\rc@getnexttok" is used to read the alignment entry % token after token. The macros "\rc@savedigit" and "\rc@savetok" % are used to store digits and other tokens in the respective % token register ("\rc@sigits" or "\rc@othertoks"). % After processing the token, "\rc@next" is called % which has been "\let" equal to the appropriate next action. % \begin{macrocode} \def\rc@savedigit#1{\rc@digits=\expandafter{\the\rc@digits#1}} \def\rc@savetok#1{\rc@othertoks=\expandafter{\the\rc@othertoks#1}} \def\rc@getnexttok#1{% % \end{macrocode} % First, check if "\tabularnewline" or "\rc@end" follows. % \begin{macrocode} \ifx#1\tabularnewline \let\rc@next\tabularnewline \else \ifx#1\rc@end \let\rc@next\rc@end \else % \end{macrocode} % If not, further tokens have to be read. If the current token % is allowed by the syntax of fp numbers, save it in "\rc@digits", % otherwise and if it is neither "\ignorespaces" nor "\unskip", % save it in "\rc@othertoks". % \begin{macrocode} \let\rc@next\rc@getnexttok \ifx#10\rc@savedigit#1\else\ifx#11\rc@savedigit1\else\ifx#12% \rc@savedigit2\else\ifx#13\rc@savedigit3\else\ifx#14% \rc@savedigit4\else\ifx#15\rc@savedigit5\else\ifx#16% \rc@savedigit6\else\ifx#17\rc@savedigit7\else\ifx#18% \rc@savedigit8\else\ifx#19\rc@savedigit9\else% \ifx#1\fp@decimalsign\rc@savedigit\fp@decimalsign% \else\ifx#1-\rc@savedigit-\else\ifx#1+\rc@savedigit+% \else\ifx#1e\rc@savedigit e\else\ifx#1E\rc@savedigit E% \else \ifx#1\ignorespaces\else \ifx#1\unskip\else \rc@savetok{#1}% \fi \fi \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi \fi \fi % \end{macrocode} % Call "\rc@next". % \begin{macrocode} \rc@next } % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % % \begin{macro}{\rc@end} % This macro marks the end of the alignment entry and reads % the contents of "\rc@digits" into a \texttt{fltpoint} register. % \begin{macrocode} \def\rc@end{\fp@regread@raw{rc@temp}{\the\rc@digits}}% % \end{macrocode} % \end{macro} % % \begin{macro}{\rc@calcprewidth} % This macro calculates the width of $n$ digits % before the decimal sign (given as parameter % "#1"), taking into account the thousand separators. % \begin{macrocode} \def\rc@calcprewidth#1#2{% {% \setbox0=\hbox{0}% \dimen0=\wd0 \multiply\dimen0 by #1\relax \setbox0=\hbox{\fp@thousandsep}% \dimen1=\wd0 \count0=#1\relax \divide\count0 by 3 \multiply\dimen1 by \count0 \advance\dimen0 by \dimen1 \fp@setparam{\the\dimen0}% }% #2=\fp@param\relax } % \end{macrocode} % \end{macro} % % \begin{macro}{\rc@calcpostwidth} % This macro calculates the width of $n$ digits after the decimal % sign, including the decimal sign itself and the thousand separators. % Actually, only the width of the decimal sign has to be added to the % result of "\rc@calcprewidth", and only if $n>0$. % \begin{macrocode} \def\rc@calcpostwidth#1#2{% \rc@calcprewidth{#1}{#2}% \ifnum#1>0 \setbox0=\hbox{\fp@decimalsign}% \advance #2 by \wd0 \fi } % \end{macrocode} % \end{macro} % % \begin{macro}{\rc@write} % The macro "\rc@write" does the actual typesetting of the number. % It takes two parameters: the number of digits before and the number % of digits after the decimal point. % \begin{macrocode} \def\rc@write#1#2{% % \end{macrocode} % The number is saved in "\rc@output". If rounding is enabled, the % desired precision is passed to "\fp@regoutput" (see~\cite{fltpoint} % for further details). % \begin{macrocode} \ifrcRounding \fp@regoutput{rc@temp}[-#2](-#2){\rc@output}% \else \fp@regoutput{rc@temp}{\rc@output}% \fi % \end{macrocode} % Now, appropriate space is added before the number. % The width of the blank space is calculated by % computing the difference between the highest possible % and the actual number of digits before the decimal sign. % The space for possible thousand-separators is added. % Furthermore, if the number is smaller than zero, % its sign will be output, so a negative skip has to % be inserted in this case. % \begin{macrocode} \rc@calcprewidth{#1}{\dimen0}% \count0=\ar@getul{fp@out}% \advance\count0 by 1 \rc@calcprewidth{\count0}{\dimen1}% \advance\dimen0 by -\dimen1 \fp@regcomp{fp@out}{@0}% \if\fp@param<% \setbox0=\hbox{$-{}$}% \advance\dimen0 by -\wd0 \fi \edef\rc@output{\hskip\the\dimen0 \rc@output}% % \end{macrocode} % If rounding is enabled, nothing has to be done after the decimal % sign. If not, we have to append space for anything \lq missing\rq: % the decimal sign, digits, thousand-separators. % \begin{macrocode} \ifrcRounding\else \rc@calcpostwidth{#2}{\dimen0}% \rc@calcpostwidth{-\ar@getll{fp@out}}{\dimen1}% \advance\dimen0 by -\dimen1 \edef\rc@output{\rc@output\hskip\the\dimen0}% \fi % \end{macrocode} % The number is horizontally centered, overriding any "\hfil" possibly % left from the \texttt{tabular} environment. The tokens saved in % "\rc@othertoks" are put before the number. % \begin{macrocode} \hfill\the\rc@othertoks$\rc@output$\hfill% } % \end{macrocode} % \end{macro} % % % \subsection{Parameters and configuration} % % \begin{macro}{\rcDecimalSign} % \begin{macro}{\rcDecimalSignInput} % \begin{macro}{\rcDecimalSignOutput} % The macros "\rcDecimalSignInput" and "\rcDecimalSignOutput" can be % used to change the default use of a comma as the decimal sign. % This can be done separately for input and output. % "\rcDecimalSign" changes both. % \begin{macrocode} \def\rcDecimalSign#1{\rcDecimalSignInput{#1}\rcDecimalSignOutput{#1}} \def\rcDecimalSignInput#1{\let\rc@decimalsigninput#1} \def\rcDecimalSignOutput#1{\let\rc@decimalsignoutput#1} \rcDecimalSign{,} % % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % % \Finale % ^^A \PrintIndex % ^^A \PrintChanges % % \endinput