8

I have a special problem concerning the column alignment of values which are an error range (separated by $\pm$ or ±). Since it usually does a great job at typesetting numbers and units, I'm using the siunitx package.

What I got:

Now I have two approaches to my problem divided here into Table 1 and Table 2 (see code). While Tab. 1 gets the centering but not the spacing right, it is reversed for Tab. 2. Tab. 1 is close to a solution, but I still prefer the Tab. 2 way, since it is better readable code, is less tweaking of options and I can directly see in SI{x.xx(xxx)}{} which values belong together. And since the data input works automated from R, I don't have to write SI{x.xx(xxx)}{} or actually the customized \ErrRange{x}{y} every time.

What I want:

1. If I use the S[table-format=x.x] @{\,\( \pm \)\,} S[table-format=x.x] to format my columns, I get the centering right. But how do I control space between values consistently? It is not straight forward and needs a lot of tweaking to get right. (See Tab. 1)

2. If I use SI{x.xx(xxx)}{} as an entry type, how do I get it to center primary around ± and secondary around x.xx as well as xxx? For this question, I got the impression that I have to tell siunitx somehow that I'm using a S column here even if I do!? (See Tab. 2)

What I found:

I tried to get more information on the siunitx package and its usage, but neither the manual nor other questions could help me (1,2,3). There was another question which discussed the spacing for the S column, but this adds nothing new to my solution. They always discuss exclusively one of both points but never both together.

The closest to my question came this post, from which I tried to add some \sisetup options like table-number-alignment=center and some S column options like S[separate-uncertainty,table-figures-uncertainty=1]. They did not change a thing. When I added table-figures-integer = 1 & table-figures-decimal = 2 (with respective values), this even made the alignment in Tab. 1 worse.

Please note in the picture below, how the first table has this weird space problem and how the second ignores the SI-centering:

My code:

\documentclass[]{article}

\usepackage{siunitx}
\usepackage{longtable}
\sisetup{separate-uncertainty, multi-part-units=single, bracket-numbers=false, range-phrase=--, range-units=single}
\newcommand{\ErrRange}[2]{\SI{#1(#2)}{}}

\begin{document}

%%%%%%%%%%%%%% TABLE 1 %%%%%%%%%%%%%%
\section*{Table with $\pm$ as column separator }
\begin{longtable}{
        >{\itshape}p{3.5cm}
        S[table-format=2.2]@{\,\( \pm \)\,}
        S[table-format=1.1]%
        S[table-format=3.2]@{\,\( \pm \)\,}
        S[table-format=2.2]% 
        S[table-format=2.1]@{\,\( \pm \)\,}
        S[table-format=2.1]%
    }
    \caption{The entries of this table are centered nicely, but the distances are awful to get right!}%
    \\ 
    \multicolumn{1}{l}{\textbf{Taxon}}      & 
    \multicolumn{2}{c}{\textbf{Height (m)}} &
    \multicolumn{2}{c}{\textbf{DBH (cm)}}   &
    \multicolumn{2}{c}{\textbf{Moss Cover (\%)}}\\
    \endfirsthead

 Acer pseudoplatanus &  14.8 & 4.1 &  35.33 & 20.19 & 11.5 & 16.8 \\ 
 Acer platanoides    &  14.4 & 4.2 & 100.33 & 15.28 & 18.0 & 20.8 \\ 
 Picea abies         &  14.8 & 3.8 &  32.44 & 13.37 &  0.3 &  0.8 \\ 
\end{longtable} 

%%%%%%%%%%%%%% TABLE 2 %%%%%%%%%%%%%%
\section*{Table with SI-range multicolumns}
\begin{longtable}{
        >{\itshape}p{3.5cm}
        *{3}S}
    \caption{Here the table's code is better readable, but the centering is incorrect.}%
    \\ 
    \multicolumn{1}{l}{\textbf{Taxon}}  & 
    \textbf{Height (m)} &
    \textbf{DBH (cm)}   &
    \textbf{Moss Cover (\%)}\\

 Acer pseudoplatanus & \ErrRange{14.8}{41}  & \ErrRange{35.33}{2019}  & \ErrRange{11.5}{168} \\ 
 Acer platanoides    & \ErrRange{14.4}{42}  & \ErrRange{100.33}{1528} & \ErrRange{18.0}{208} \\ 
 Picea abies         & \ErrRange{14.8}{38}  & \ErrRange{32.44}{1337}  & \ErrRange{0.3}{8} \\ 
\end{longtable} 

\end{document}

EDIT:

Based on the solutions by Zarko and samcarter, my problem now is clearer to me. After Zarko's explanation in the comments, one additional problem could be that the smallest value of a column is smaller than the errors of some other value of that column. However, contrary to the implication in the comments, some/most of these are realistic values.

As a short background information: These are data on different tree species of which I estimated the height, dbh (diameter at breast height) and the moss cover. Since I did this for well over a hundred individuals per species (disregarding the size and age), the variation should be quite large. And while it is true that I overemphasized some values, the moss cover values are all my real values. So, both Acer species are supposed to have way more mosses (and more variation in it) than the Picea species. That means that I probably cannot use the answer of Zarko but have to take a workaround like samcarter's

EDIT 2:

I guess you're right about one thing: I did not mean the standard error but the standard deviation. However, I need the same format and this should therefore not change anything.

1
  • from your eddits i can conclude, that you actualy like to present three values: minimal, maximal and average. this you can declare/present as accuracy of measurement.
    – Zarko
    Commented Mar 12, 2018 at 21:55

2 Answers 2

7

enter image description here

using features of siunitx at table setting and standard SI notation for uncertainty for numbers inputs:

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{separate-uncertainty,
         table-figures-uncertainty=2,
         table-number-alignment = center,
        }

\usepackage[active, floats, tightpage]{preview}
\setlength\PreviewBorder{1em}

\begin{document}
\begin{table}
\caption{Reserving space in \texttt{S} columns.}
\label{tab:S:space}
    \sisetup{
    table-figures-integer = 3,
    table-figures-decimal = 2,
    separate-uncertainty,
    table-figures-uncertainty = 1
  }
\centering
\begin{tabular}{
l
S[table-figures-decimal = 1]
S
S[table-figures-decimal = 1]
}
    \toprule
\textbf{Taxon}      & {\textbf{Height (m)}}
                                & {\textbf{DBH (cm)}}
                                                & {\textbf{Moss Cover (\%)}}    \\
    \midrule
Acer pseudoplatanus &  14.8(41) &  35.33(2019)  & 11.5(168)                     \\
Acer platanoides    &  14.4(42) & 100.33(1528)  & 18.0(208)                     \\
Picea abies         &  14.8(38) &  32.44(1337)  &  0.3(08)                      \\
    \bottomrule
\end{tabular}
    \end{table}
\end{document}

addendum:

in the case that you like to have anchored number at their decimal points and at tolerance sign (don't doing this, it is not in frame of SI standard) with explicit writing of \pm signs (what wouldn't do ever), than you have the mismatch at spaces. they in your solution arise from fact that content of two column cells are wider than natural width of spanned column. this you can solve on two ways:

  • make two column cells narrower, for example set them in two lines

\documentclass[]{article}
\usepackage{siunitx}
\usepackage{makecell, longtable}
\renewcommand\theadfont{\bfseries}
\newcommand\mcc[1]{\multicolumn{2}{c}{\thead[b]{#1}}}

\begin{document}
\section*{Table with $\pm$ as column separator }
\begingroup
\begin{longtable}{@{}
        >{\itshape}l
        S[table-format=2.1]@{$\,\pm\,$}S[table-format=1.1]%
        S[table-format=3.2]@{$\,\pm\,$}S[table-format=2.2]%
        S[table-format=2.1]@{$\,\pm\,$}S[table-format=2.1]%
                    @{}}
    \caption{The entries of this table are centered nicely, but the distances are awful to get right!}%
    \\
\thead{Taxon}           &
\mcc{Height\\ (m)}      &
\mcc{DBH\\ (cm)}        &
\mcc{Moss\\ Cover\\ (\%)} \\
    \endfirsthead
Acer pseudoplatanus &  14.8 & 4.1 &    35.33 & 20.19 & 11.5 & 16.8 \\
Acer platanoides    &  14.4 & 4.2 &   100.33 & 15.28 & 18.0 & 20.8 \\
Picea abies         &  14.8 & 3.8 &   32.44  & 13.37 &  0.3 &  0.8 \\r
    \end{longtable}
\end{document}

which gives:

enter image description here

  • or make S columns wider, for example with increase number of integer and decimal digits:

\documentclass[]{article}
    \usepackage{siunitx}
    \usepackage{longtable}
    \newcommand\mcc[1]{\multicolumn{2}{c}{\textbf{#1}}}

%------------- show page layout. don't use this in real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\section*{Table with $\pm$ as column separator }
\begingroup
%\setlength\tabcolsep{3pt}
\begin{longtable}{@{}
    >{\itshape}l
    S[table-format=4.1]@{$\,\pm\,$}S[table-format=1.4]%
    S[table-format=3.2]@{$\,\pm\,$}S[table-format=2.3]%
    S[table-format=6.1]@{$\,\pm\,$}S[table-format=2.6]%
                  @{}}
\caption{The entries of this table are centered nicely, but the distances are awful to get right!}%
    \\
\text{Taxon}            &
\mcc{Height (m)}        &
\mcc{DBH (cm)}          &
\mcc{Moss Cover (\%)}   \\
    \endfirsthead
Acer pseudoplatanus &  14.8 & 4.1 &    35.33 & 20.19 & 11.5 & 16.8 \\
Acer platanoides    &  14.4 & 4.2 &   100.33 & 15.28 & 18.0 & 20.8 \\
Picea abies         &  14.8 & 3.8 &   32.44  & 13.37 &  0.3 &  0.8 \\
    \end{longtable}
\end{document}

which gives:

enter image description here

(red lines indicate page layout)

off-topic:

after reading edited of question, i thought that the next solution would probably be more correct:

enter image description here

mwe for this suggestion is:

\documentclass{article}
\usepackage{geometry}
\usepackage{siunitx}
\usepackage{booktabs, longtable}
\newcommand\mcfour[1]{\multicolumn{4}{c}{\textbf{#1}}}

%------------- show page layout. don't use this in real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\section*{new version of table}
\begingroup
\small
\setlength\tabcolsep{0pt}
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\renewcommand\cmidrulekern{2pt}
\begin{longtable}{@{\extracolsep{\fill}}
    >{\itshape}l
    *{3}{S[table-format=2.1]
         S[table-format=3.1]
         S[table-format=2.1]
         S[table-format=2.2]}
                }
\caption{Results of observation,  numbers are dummy}     \\
    \toprule
    &   \mcfour{Height (m)}
    &   \mcfour{DBH (cm)}
    &   \mcfour{Moss Cover (\%)}        \\
    \cmidrule(lr){2-5}\cmidrule(lr){6-9}\cmidrule(lr){10-13}
\text{Taxon}
    & {min} & {max} & {mean}& {$\mu_{1/2}$}
    & {min} & {max} & {mean}& {$\mu_{1/2}$}
    & {min} & {max} & {mean}& {$\mu_{1/2}$}  \\
    \midrule
\endfirsthead
    \bottomrule
\endfoot
Acer pseudoplatanus
    & 10.0  & 18.39 & 14.8  & 15.5
    & 10.0  & 57.00 & 35.33 & 33,15
    &  0.0  & 28.32 & 10.5  & 16.8      \\

    \end{longtable}
\end{document}

(where $\mu_{1/2}$ means median).

6
  • 1
    +1, however the numbers in the last column are not aligned by their decimal markers Commented Mar 12, 2018 at 19:35
  • 1
    no. they not. siunitx doesn't support aligning at two markers. beside this all uncertainty in table is fragile (wrong). tolerances had not to be bigger than last defined digit in number. or today basing measurement rules doesn't valid anymore (why you for example say length is 14.8 m with tolerance 4 m? :-(. do i'm wrong?
    – Zarko
    Commented Mar 12, 2018 at 19:46
  • I totally agree that the number of significant figures does not make sense. Commented Mar 12, 2018 at 19:52
  • @bamphe, do you read addendum to my answer?
    – Zarko
    Commented Mar 12, 2018 at 21:53
  • Wow, thanks! That's a hell of an answer :) As I said, I would like the format like I have it in the question (in plant ecology it's not that much about precision of measurements since there are so many random environmental factors...) However, your addendum still gives me the possibility to tweak it to my liking and I would say it's a bit less messier than samcarter's solution ;) For all others with similar problems, the answer actually explains various underlying concepts. Very cool!
    – bamphe
    Commented Mar 13, 2018 at 15:23
2

Coincidently I was fighting with a similar problem today myself.

For now I use \makebox[0pt]{\textbf{DBH (cm)}} as a workaround. However this requires to manually add space between the columns...

\documentclass[]{article}

\usepackage{siunitx}
\usepackage{longtable}
\sisetup{separate-uncertainty, multi-part-units=single, bracket-numbers=false, range-phrase=--, range-units=single}
\newcommand{\ErrRange}[2]{\SI{#1(#2)}{}}


\begin{document}

%%%%%%%%%%%%%% TABLE 1 %%%%%%%%%%%%%%
\section*{Table with $\pm$ as column separator }
\begin{longtable}{
        >{\itshape}p{3.5cm}
        S[table-format=2.1]@{\,\( \pm \)\,}S[table-format=1.1]%
        p{0.2em}S[table-format=3.2]@{\,\( \pm \)\,}S[table-format=2.2]% 
        p{1em}S[table-format=2.1]@{\,\( \pm \)\,}S[table-format=2.1]%
    }
    \caption{The entries of this table are centered nicely, but the distances are awful to get right!}%
    \\ 
    \multicolumn{1}{l}{\textbf{Taxon}}      & 
    \multicolumn{2}{c}{\makebox[0pt]{\textbf{Height (m)}}} & &
    \multicolumn{2}{c}{\makebox[0pt]{\textbf{DBH (cm)}}}   & &
    \multicolumn{2}{c}{\makebox[0pt]{\textbf{Moss Cover (\%)}}}\\
    \endfirsthead

 Acer pseudoplatanus &  14.8 & 4.1 &&  35.33 & 20.19 & &11.5 & 16.8 \\ 
 Acer platanoides    &  14.4 & 4.2 && 100.33 & 15.28 & &18.0 & 20.8 \\ 
 Picea abies         &  14.8 & 3.8 &&  32.44 & 13.37 & & 0.3 &  0.8 \\ 
\end{longtable} 


\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .