# Align different operators in table

I like to align table cells on the \pm with "D{;}{\pm}{1}", but this looks ugly if I have cells without a \pm.

In the following example case A and B would be data that I measured, while case C is a set where I have missing data, and case D is a set where I fixed a variable for fitting. How could I align the - with the \pm or the * with the \pm or further symbols?

\documentclass[a4paper,12pt]{book}
\usepackage{dcolumn}
\usepackage{booktabs}
\begin{document}
\begin{table}
\center
\caption{Hi}
\begin{tabular}{l D{,}{\pm}{1}}
\toprule
set    & data\\
\midrule
case A & 112,11\\
case B & 320,20\\
case C & -\\
fixed  & 100\textsuperscript{*}\\
\bottomrule
\end{tabular}
\end{table}
\end{document}

• unrelated but \center is not intended to be used as a command (it is part of the internal implementation of the center environment, use \centering – David Carlisle Dec 31 '18 at 14:47

I suggest using siunitx, rather than dcolumn: the spacing is much better.

About aligning the “missing data” symbol to \pm, I'd discourage it. Use an em-dash or an en-dash; siunitx will center it on the column.

Use \centering, rather than \center.

\documentclass[a4paper,12pt]{book}
\usepackage{siunitx}
\usepackage{booktabs}

\sisetup{separate-uncertainty}
\newcommand{\zwast}{\makebox[0pt][l]{$^*$}}

\begin{document}

\begin{table}
\centering

\caption{Hi}

\begin{tabular}{l S[table-format=3.0(2),table-align-text-post=false]}
\toprule
set    & {data} \\
\midrule
case A & 112\pm11\\
case B & 320\pm20\\
case C & {---}\\
fixed  & 100\zwast\\
\bottomrule
\end{tabular}

\end{table}

\end{document}


With dcolumn:

\documentclass[a4paper,12pt]{book}
\usepackage{dcolumn}
\usepackage{booktabs}

\newcommand{\zwast}{\makebox[0pt][l]{$^*$}}

\begin{document}
\begin{table}
\centering

\caption{Hi}

\begin{tabular}{l D{,}{{}\pm{}}{2}}
\toprule
set    & \multicolumn{1}{c}{data}\\
\midrule
case A & 112,11\\
case B & 320,20\\
case C & \multicolumn{1}{D{,}{{}-{}}{2}}{{},{}}\\
fixed  & 100\zwast\\
\bottomrule
\end{tabular}

\end{table}

\end{document}


• perhaps it is magnification but the caption looks much closer to the rule than at bottom of table hence an unbalanced impression... – user4686 Dec 31 '18 at 14:37
• @jfbu That's the standard behavior of article (where the caption is supposed to be at the bottom). – egreg Dec 31 '18 at 14:41
• ah indeed, simply loading the caption package would use \abovecaptionskip (10pt) below the caption perhaps (well I tested it now, and the spacing is too big, so best is to adjust manually) – user4686 Dec 31 '18 at 14:43