Graphics, Figures & Tablessiunitx {S} in tabular with multirow

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
zoparrat
Posts: 4
Joined: Fri Sep 24, 2010 3:43 pm

siunitx {S} in tabular with multirow

Post by zoparrat »

I'm trying to use the column type S defined by the siunitx package inside a tabular environment. I also have some row spanning multiple lines with the multirow package. It looks like decimals aren't getting aligned whenever there's a multirow in the same column. Below is a screenshot of the output (see 3rd and 4th cols) and a working example.

Am I doing something wrong? or should I avoid mixing multirow with siunitx? Is there a workaround or some other way of doing this?

Code: Select all

\documentclass{report}

\usepackage{booktabs,multirow,rccol}
\usepackage{siunitx}
\usepackage{graphicx}

\begin{document}

\begin{table}[htbp]
  \centering
     \caption{Mean and Standard Deviation of stuff.}   
      \footnotesize
      \resizebox{\textwidth}{!}{%
    \begin{tabular}{@{}cccSSS@{}}
    \addlinespace
    \toprule         
          &       &   \multicolumn{2}{c}{}    & \multicolumn{2}{c}{stats} \\
          &       & \multicolumn{2}{c}{line1} & \multicolumn{2}{c}{method} \\
          &       & \multicolumn{2}{c}{line2} & \multicolumn{2}{c}{length, } \\
          &       &  \multicolumn{2}{c}{(segments)}   & \multicolumn{2}{c}{100 samples)} \\
      \cmidrule(lr{0.75em}){3-4}
      \cmidrule(lr{0.75em}){5-6}
    \multirow{2}[0]{*}{Case} & Distribution of & \multicolumn{1}{c}{$\mu$} & \multicolumn{1}{c}{$\sigma$} & \multicolumn{1}{c}{$\mu$} & \multicolumn{1}{c}{$\sigma$} \\
          & segments & \multicolumn{1}{c}{(unit)} & \multicolumn{1}{c}{(unit)} & \multicolumn{1}{c}{(unit)}& \multicolumn{1}{c}{(unit)} \\
               \midrule
    somestuff & (2 parameter) & 233.476 & 12.232 & 2.9534 & 13.300 \\
               \midrule
    stuff1  & \multirow{4}{*}{some shared par.} & \multirow{4}{*}{23.10533} & \multirow{4}{*}{1.345} & 234.094 & 2321.000 \\
      stuff2  &     &    &    & 259.106 & 1.022 \\
      stuff3    &    &    &    & 58.662 & 0.89523 \\
      stuff4    &     &    &    & 259.59 & 0.547 \\
    \bottomrule
    \end{tabular}}%
  \label{tab:stuff}%
\end{table}%
\end{document}

Edit by localghost: Preferably no external links (see Board Rules). Attachments go onto the forum server there possible.
Attachments
The table as it looks right now.
The table as it looks right now.
table-current.jpg (32.07 KiB) Viewed 7115 times
Last edited by zoparrat on Thu Apr 21, 2011 3:21 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Re: siunitx {S} in tabular with multirow

Post by josephwright »

The latest version of siunitx, v2.2, was sent to CTAN within the last hour. It includes a new macro, \tablenum, which is intended for this situation. However, there seems to be something up when it's used inside an S column: expect a workable version of what you want in a day or so!
Joseph Wright
josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

siunitx {S} in tabular with multirow

Post by josephwright »

This will now work once v2.2 hits CTAN:

Code: Select all

    \documentclass{report}

    \usepackage{booktabs,multirow,rccol}
    \usepackage{siunitx}
    \usepackage{graphicx}

    \begin{document}

    \begin{table}[htbp]
      \centering
         \caption{Mean and Standard Deviation of stuff.}   
          \footnotesize
          \resizebox{\textwidth}{!}{%
        \begin{tabular}{@{}cccSSS@{}}
        \addlinespace
        \toprule         
              &       &   \multicolumn{2}{c}{}    & \multicolumn{2}{c}{stats} \\
              &       & \multicolumn{2}{c}{line1} & \multicolumn{2}{c}{method} \\
              &       & \multicolumn{2}{c}{line2} & \multicolumn{2}{c}{length, } \\
              &       &  \multicolumn{2}{c}{(segments)}   & \multicolumn{2}{c}{100 samples)} \\
          \cmidrule(lr{0.75em}){3-4}
          \cmidrule(lr{0.75em}){5-6}
        \multirow{2}[0]{*}{Case} & Distribution of & \multicolumn{1}{c}{$\mu$} & \multicolumn{1}{c}{$\sigma$} & \multicolumn{1}{c}{$\mu$} & \multicolumn{1}{c}{$\sigma$} \\
              & segments & \multicolumn{1}{c}{(unit)} & \multicolumn{1}{c}{(unit)} & \multicolumn{1}{c}{(unit)}& \multicolumn{1}{c}{(unit)} \\
                   \midrule
        somestuff & (2 parameter) & 233.476 & 12.232 & 2.9534 & 13.300 \\
                   \midrule
        stuff1  & 
          \multirow{4}{*}{some shared par.} & 
          \multirow{4}{*}{\tablenum{23.10533}} & 
          \multirow{4}{*}{\tablenum{1.345}} & 234.094 & 2321.000 \\
          stuff2  &     &    &    & 259.106 & 1.022 \\
          stuff3    &    &    &    & 58.662 & 0.89523 \\
          stuff4    &     &    &    & 259.59 & 0.547 \\
        \bottomrule
        \end{tabular}}%
      \label{tab:stuff}%
    \end{table}%
    \end{document}
Joseph Wright
zoparrat
Posts: 4
Joined: Fri Sep 24, 2010 3:43 pm

Re: siunitx {S} in tabular with multirow

Post by zoparrat »

Updated to the new siunitx and that works! Many thanks.
Post Reply