3

It's never ending story about that -> previous post. Simply, I just want to align to 'pm' sign my number columns. I've already tried replacing headers {l | l *{2}{>{\centering\arraybackslash}X}} with {l | l l l *{2}{>{\centering\arraybackslash}X} and than to check one column with siunitx: {l | l S[table-align-uncertainty, separate-uncertainty=true] l l *{2}{>{\centering\arraybackslash}X} but it doesn't work at all.

MWE:

\documentclass{article}
\usepackage{float, enumitem, amsmath}
\usepackage{rotating}  
\usepackage{booktabs, makecell, multirow, tabularx, threeparttable}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{} 
\usepackage{colortbl, color} %I preffer that instead of xcolor because xcolor give me errors with beamer
\usepackage{caption}
\captionsetup{belowskip=-5pt}
\captionsetup[table]{justification=raggedright,singlelinecheck=off}

\begin{document}

   \begin{table} 
    \centering
    \settowidth\rotheadsize{\theadfont Description 3 }
    \renewcommand\arraystretch{1.1}
\caption{Simple caption.}
\label{tab:setTag}
\begin{tabularx}{\linewidth}{l | l *{2}{>{\centering\arraybackslash}X}}
    \Xhline{1pt}
    & \thead[l]{Results} 
        & \thead{Method 1} & \thead{Method 2}           \\
    \Xhline{0.7pt}
    &   & \multicolumn{2}{c}{First section}             \\ 
    \Xcline{3-4}{0.6pt}
\multirow{3}{*}{\rothead{Description 1}}
    &Very long name & $11,5 \pm 0,5$ & $444,34 \pm 71,9$ \\
    & Very long name & $109,2 \pm 75,3$ & $2,8 \pm 664,36$ \\
    & Very long name& $9438 \pm 8$ & $256,0 \pm 98,1$ \\
    & Very long name & $11,5 \pm 0,5$ & $444,34 \pm 71,9$ \\
    & Very long name & $109,2 \pm 75,3$ & $2,8 \pm 664,36$ \\
    & Very long name & $9438 \pm 8$ & $256,0 \pm 98,1$ \\
    \end{tabularx}
    \end{table}
\end{document}

enter image description here


I've changed header to \begin{tabularx}{\linewidth}{l | X S[table-align-uncertainty, separate-uncertainty=true] S[table-align-uncertainty, separate-uncertainty=true]*{2}{>{\centering\arraybackslash}}} and data from first row to 11,5(5) & 444,34(719 and I get that result (strange Methods headers):

enter image description here


I've now had errors with array package '>{}' at wrong position. Can someone please tell me which one is the correct one? And another one with 'missing # inserted in alignment preamble' and the third one 'missing $ inserted' but I don't know why because it shows line with \end{tabularx}.

New part of the code:

\begin{tabularx}{\linewidth}{l | X S[table-align-uncertainty, separate-uncertainty=true] S[table-align-uncertainty, separate-uncertainty=true]*{2}{>{\centering\arraybackslash}}}
    \Xhline{1pt}
    & \thead[l]{Results} 
        & {\thead{Method 1}} & {\thead{Method 2}}           \\
    \Xhline{0.7pt}
    &   & \multicolumn{2}{c}{First section}             \\ 
    \Xcline{3-4}{0.6pt}
\multirow{3}{*}{\rothead{Description 1}}
    &Very long name & $11,5(5)$ & $444,34(719)$ \\
    & Very long name & $109,2(753)$ & $2,8(63)$ \\
    & Very long name& $9438(8)$ & $256,0(981)$ \\
    &Very long name & $11,5(5)$ & $444,34(719)$ \\
    & Very long name & $109,2(753)$ & $2,8(63)$ \\
    & Very long name& $9438(8)$ & $256,0(981)$ \\
    \end{tabularx}

It shows (which is obviously not align):

enter image description here


enter image description here

14
  • If you want 11,5 \pm 0,5 as the output in an S type columns of the table, you should use 11,5(5) as the input in the S type column.
    – leandriis
    Commented Jun 2, 2020 at 18:49
  • Why do you use tabularx here? Your table is already narrow enough to fit into the textwidth. By using tabularx here you only stretch the table introducing unneccessary white space.
    – leandriis
    Commented Jun 2, 2020 at 18:53
  • @leandriis my whole table is much wider (the name of the columns etc.) but for the MWE and just align operation it is not necessary to provide the whole one (in the previous post I showed how huge the table is) :)
    – Dominika
    Commented Jun 2, 2020 at 18:55
  • I see. Thanks for the explanation. I was a bit confused since the dummy text you included in your previous example is something entirely different than numbers with their uncertainties which you showed in this example code.
    – leandriis
    Commented Jun 2, 2020 at 19:00
  • I know, so sorry - just learning how to quick describe problem with as much information as I can gave. So, my 'real table' has very long 'Results' section and in some of the 'First section'/'Second section' etc. a lot of numbers data.
    – Dominika
    Commented Jun 2, 2020 at 19:03

2 Answers 2

3

The following should work:

\documentclass{article}
\usepackage{float, enumitem, amsmath}
\usepackage{rotating}  
\usepackage{booktabs, makecell, multirow, tabularx, threeparttable}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{} 
\usepackage{colortbl, color} %I preffer that instead of xcolor because xcolor give me errors with beamer

\usepackage{caption}
\captionsetup{belowskip=-5pt}
\captionsetup[table]{justification=raggedright,singlelinecheck=off}

\usepackage{siunitx}
\begin{document}

\sisetup{table-align-uncertainty, separate-uncertainty=true}
\begin{tabularx}{\linewidth}{l | X S[table-format=4.1(3)] S[table-format=3.2(5)]}
    \Xhline{1pt}
    & \thead[l]{Results} 
        & {\thead{Method 1}} & {\thead{Method 2}}           \\
    \Xhline{0.7pt}
    &   & \multicolumn{2}{c}{First section}             \\ 
    \Xcline{3-4}{0.6pt}
\multirow{3}{*}{\rothead{Description 1}}
    & Very long name & 11,5(5)    & 444,34(7190) \\
    & Very long name & 109,2(753) & 2,80(66436)  \\
    & Very long name & 9438(8)    & 256,0(981)   \\
    & Very long name & 11,5(5)    & 444,34(7190) \\
    & Very long name & 109,2(753) & 2,80(66436)  \\
    & Very long name & 9438(8)    & 256,0(981)   \\
    \end{tabularx}
\end{document}
7
  • yes, aligment works pretty well but rotated column looking very bad now (I've changed yours \multirow{3}{*}{\rothead{Description 1}} to \multirow{6}{*}{\rothead{Description 1}}, but it doesn't help
    – Dominika
    Commented Jun 2, 2020 at 21:23
  • besides rotating text issue I also putted in description example how some of the numbers looks like. The +/- symbol is too close to them - please take a look (last image).
    – Dominika
    Commented Jun 2, 2020 at 21:35
  • thank you so much, you also help me a lot with better understanding tables!
    – Dominika
    Commented Jun 2, 2020 at 21:47
  • If you want to add numbers with more than 1 decimal place into the first column, you will have to adjust the table-format option of this specific column accordingly. In order to add a short horizontal line in a S type column, use {--} instead of - -.
    – leandriis
    Commented Jun 2, 2020 at 22:12
  • Got it, but when I put S[table-format=4.10(5)] or S[table-format=4.1(100)] or S[table-format=400.1(5)] it's just ridiculous and nasty. How it works?
    – Dominika
    Commented Jun 2, 2020 at 22:15
3

just answering your comment under leandriis answer, you can simply rotate the text directly there is no need for a multirow, also as I commented previously in chat I would never use tabularx for a table of data like this, tabularx is all about tables of text and line breaking in columns.

enter image description here

\documentclass{article}
\usepackage{float, enumitem, amsmath}
\usepackage{rotating}  
\usepackage{booktabs, makecell, multirow, tabularx, threeparttable}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{} 
\usepackage{colortbl, color} %I preffer that instead of xcolor because xcolor give me errors with beamer

\usepackage{caption}
\captionsetup{belowskip=-5pt}
\captionsetup[table]{justification=raggedright,singlelinecheck=off}

\usepackage{siunitx}
\begin{document}

\sisetup{table-align-uncertainty, separate-uncertainty=true}
\centering
\begin{tabular}{l | l S[table-format=4.1(3)] S[table-format=3.2(5)]}
    \Xhline{1pt}
    & \thead[l]{Results} 
        & {\thead{Method 1}} & {\thead{Method 2}}           \\
    \Xhline{0.7pt}
\smash{\rotatebox[origin=r]{90}{\bfseries Description 1}}
    &   & \multicolumn{2}{c}{First section}             \\ 
    \Xcline{3-4}{0.6pt}
    & Very long name & 11,5(5)    & 444,34(7190) \\
    & Very long name & 109,2(753) & 2,80(66436)  \\
    & Very long name & 9438(8)    & 256,0(981)   \\
    & Very long name & 11,5(5)    & 444,34(7190) \\
    & Very long name & 109,2(753) & 2,80(66436)  \\
    & Very long name & 9438(8)    & 256,0(981)   \\
    \end{tabular}
\end{document}
10
  • I will be remember that, thank you for your time but I put Description 1 in multirow because I want to forced this text to be centered. In original table I have 16 rows (like my first post here, linked in description) so I think centered looks better
    – Dominika
    Commented Jun 2, 2020 at 21:39
  • @Dominika you can easily move it down, just put it in a later row or add an \hspace after the 1 multirow desn't force vertical centering Commented Jun 2, 2020 at 21:40
  • Of course - that's not a problem with odd number, but I will try. Once again thank you so much for your time and advices.
    – Dominika
    Commented Jun 2, 2020 at 21:42
  • @Dominika actually you should accept lenadriis answer that had better siunitx use than the answer I was going to give, which was your main question, I just stole the entire code from that answer to add this extra comment, I'll feel a bit bad if I steal the points as well:-) Commented Jun 2, 2020 at 21:44
  • Okay, right - I apologise. I've already changed, but thank you for your both :) Now I will try to use it in the much bigger table, hope it will work. Fingers crossed!
    – Dominika
    Commented Jun 2, 2020 at 21:49

You must log in to answer this question.

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