3

Consider the following example:

enter image description here

\documentclass{article}
\usepackage{siunitx,collcell}
\sisetup{minimum-integer-digits=4}
\begin{document}

\begin{tabular}{S}
  {Header} \\
  1234 \\ 234 \\ 34 \\ 4
\end{tabular}
%
\qquad%
%
\begin{tabular}{>{\collectcell\num}c<{\endcollectcell}}
  \multicolumn{1}{c}{Header} \\
  1234 \\ 234 \\ 34 \\ 4
\end{tabular}

\end{document}

In the left tabular (the siunitx example), the Header column is centred around the "(missing) decimal point". In the right tabular (the collcell example), the Header is centred as expected (since we're using a c-type column).

The integer padding in both cases produces a leading 0. How can I modify this padding to be \phantom{0} (or something else altogether) so that the output resembles

enter image description here

\documentclass{article}
\begin{document}

\begin{tabular}{c}
  \multicolumn{1}{c}{Header} \\
  1234 \\ \phantom{0}234 \\ \phantom{0}\phantom{0}34 \\ \phantom{0}\phantom{0}\phantom{0}4
\end{tabular}

\end{document}

I am looking for a way to add the key integer-zero that I can specify to my liking (default is 0). A generalisation for decimal-zero (doesn't exist yet) would be equally awesome.

7
  • In essence, something has to be changed inside \@@_number_process_integer_digits.
    – Werner
    Dec 2 '14 at 1:09
  • So in essence some text \num{3} and more would be like some text $\hphantom{000}3$ and more. In any case, what's the use case?
    – Manuel
    Dec 2 '14 at 1:44
  • @Manuel: Essentially, yes. Use case would be "discussion on padding" (so that one can represent this with another symbol, say \cdot or \textvisiblespace or - or ...) and perhaps for horizontal alignment in certain cases.
    – Werner
    Dec 2 '14 at 1:51
  • Why are you doing this?
    – Joseph Wright
    Dec 5 '14 at 17:10
  • 1
    @Werner The edit is just a use of \tablenum, surely? (\num and \tablenum are semantically different.)
    – Joseph Wright
    Dec 5 '14 at 17:58
3

For the case of aligning numbers when not using a normal column situation, siunitx provides the \tablenum command.

\documentclass{article}
\usepackage{siunitx,collcell}
\begin{document}

\sisetup{table-format = 4.0}
\begin{tabular}{>{\collectcell\tablenum}c<{\endcollectcell}}
  \multicolumn{1}{c}{Header} \\
  1234 \\ 234 \\ 34 \\ 4
\end{tabular}

\end{document}

This is specifically there for creating alignment-compatible number formatting in non-standard situations.

In the case in the question, I don't think that is really even needed

\documentclass{article}
\usepackage{siunitx}
\begin{document}

\begin{tabular}{S[table-format = 4.0]}
  \multicolumn{1}{c}{Header} \\
  1234 \\ 234 \\ 34 \\ 4
\end{tabular}

\end{document}
1
  • 1
    Okay.... great! I can live with this (missed \tablenum as a macro in the documentation). Do you see any value for a changeable 0 in \num so you can also use it in inline discussions. As in "We use \num{234}... where * denotes..." that shows as "We use *234... where * denotes..."?
    – Werner
    Dec 5 '14 at 18:07
1

OTOH, If you aren't married to \num, you could use something like

\documentclass{article}
\begin{document}
\begin{tabular}{@{}r@{}}
1234\\
234\\
34\\
4
\end{tabular}
\end{document}

or

\documentclass{article}
\newcommand{\mynum}[1]{\phantom{0000}\llap{#1}}
\begin{document}
\mynum{1234}\par
\mynum{234}\par
\mynum{34}\par
\mynum{4}
\end{document}
1

Not an answer, but just playing around. If you don't need zeroes inside the number, then it's an answer; because it “replaces” every zero, doesn't matter if it's on the left or on the middle.

\documentclass{article}
\usepackage{siunitx,calc}
\sisetup{minimum-integer-digits=4}
\begin{document}
\begingroup\mathcode`\0="8000
\begingroup\lccode`\~=`\0\lowercase{\endgroup\def~}{\makebox[\widthof{0}]
 {\textvisiblespace}}
%{$\cdot$}}
\num{1234}\par
\num{234}\par
\num{34}\par
\num{4}    
\endgroup
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.