2

I have a column of numbers which I'd like to align on the decimal point, which in simpler circumstances I've achieved using the dcolumn package.

In this particular case, I have footnotes which are now distorting the layout, and I'd like to know how I can resolve this. A simplified version of my tabular environment is shown below, along with an image of the output with and without footnotes. Without the footnotes it displays fine, but with them the last number is shifted over.

Any assistance would be greatly appreciated.

\begin{tabular}{D{.}{.}{-1}}
    1.234 \textsuperscript{b}       \\
    -0.001 \textsuperscript{b}      \\
    -12.345 \textsuperscript{b}     \\
    123 \textsuperscript{c}         \\
\end{tabular}

Output

2

Issue the "footnote" with a zero-width right overlap:

enter image description here

\documentclass{article}
\usepackage{dcolumn}

\begin{document}

\begin{tabular}{D{.}{.}{-1} D{.}{.}{-1}}
    1.234 &   1.234 \textsuperscript{b} \\
   -0.001 &  -0.001 \textsuperscript{b} \\
  -12.345 & -12.345 \textsuperscript{b} \\
  123     & 123     \rlap{\textsuperscript{c}}
\end{tabular}

\end{document}

A LaTeX approach would be \makebox[0pt][l] instead of using \rlap.

  • Thank you for your help. I have used \rlap and it works fine. I am not familiar with the \rlap code though, and can't seem to find any documentation on it. Could you suggest somewhere I can learn more about what it does? – Ulysses Nov 11 '15 at 4:25
  • @Ulysses: \rlap is defined as \hbox to 0pt{#1 \hss}. You can issue \show\rlap to see the definition in your .log, as an example. If you want to know about overlapping, consider reading the adjustbox documentation. – Werner Nov 11 '15 at 7:26
  • I know \rlap{...} is easier to write, but I always recommend using \makebox[0pt][l]{...} (maybe hidden in a \tnote macro, following threeparttable). People not having deep knowledge of plain TeX might get very bad surprises from \rlap or \llap. – egreg Nov 11 '15 at 9:22
2

You may be interested to the threeparttable package that features a \tnote macro that just does what you want (and much more).

\documentclass{article}

\usepackage{threeparttable,booktabs,dcolumn}

\begin{document}

\begin{table}
\centering
\begin{threeparttable}

\caption{A very interesting table}\label{tab-interest}

\begin{tabular}{l D{.}{.}{-1} D{.}{.}{-1} D{.}{.}{-1}}
\toprule
& \multicolumn{1}{c}{A} & \multicolumn{1}{c}{B} & \multicolumn{1}{c}{C} \\
\midrule
Gnus           &   1.234 &   4.567 &   1.234\tnote{a} \\
Gnats          &  -0.001 &   0.12  &   3.51\tnote{b} \\
Gnats and gnus & -12.34  &  -42    & -42\tnote{c} \\
\bottomrule
\end{tabular}

\begin{tablenotes}
\item[a] Fried
\item[b] Stuffed
\item[c] Boiled
\end{tablenotes}

\end{threeparttable}
\end{table}

\end{document}

enter image description here

A different way of doing the same thing, with some more facilities, is with siunitx:

\documentclass{article}

\usepackage{threeparttable,booktabs,siunitx}

\begin{document}

\begin{table}[htp]
\centering
\begin{threeparttable}

\caption{A very interesting table}\label{tab-interest1}

\begin{tabular}{
 l
 S[table-format=-2.3]
 S[table-format=-2.3]
 S[table-format=-2.3]
}
\toprule
& {A} & {B} & {C} \\
\midrule
Gnus           &   1.234 &   4.567 &   1.234\tnote{a} \\
Gnats          &  -0.001 &   0.12  &   3.51\tnote{b} \\
Gnats and gnus & -12.34  &  -42    & -42\tnote{c} \\
\bottomrule
\end{tabular}

\begin{tablenotes}
\item[a] Fried
\item[b] Stuffed
\item[c] Boiled
\end{tablenotes}

\end{threeparttable}
\end{table}

\begin{table}[htp]
\centering
\begin{threeparttable}

\caption{A very interesting table}\label{tab-interest2}

\begin{tabular}{
 l
 S[table-format=-2.3]
 S[table-format=-2.3]
 S[table-format=-2.3,table-align-text-post = false]
}
\toprule
& {A} & {B} & {C} \\
\midrule
Gnus           &   1.234 &   4.567 &   1.234\tnote{a} \\
Gnats          &  -0.001 &   0.12  &   3.51\tnote{b} \\
Gnats and gnus & -12.34  &  -42    & -42\tnote{c} \\
\bottomrule
\end{tabular}

\begin{tablenotes}
\item[a] Fried
\item[b] Stuffed
\item[c] Boiled
\end{tablenotes}

\end{threeparttable}
\end{table}

\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.