3

I have a table with a complex heading using multirow and multicol packages. I'd like to have the second column of the following table as S type from siunitx package for to align the numbers by its decimal separator, however I failed. Any help, please?

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{multirow,multicol}
\begin{document}

\begin{table}[htb]
\footnotesize
\centering
\caption{Example Table}
\begin{tabular}{ccSS}% <--- HERE
\midrule
\multirow{2}{*}{\textbf{Column 1}} & 
\multirow{2}{*}{\textbf{%
\begin{tabular}[c]
{@{}c@{}}Column 2\\
(\si{\g/\mL})
\end{tabular}}} &
\multicolumn{2}{c}{\textbf{Column 3 (\si{\ug/\L})}} \\
\cmidrule{3-4}& &
\textbf{Column 3.1} & \textbf{Column 3.2}\\
\midrule
AE1 &  3.45 & \multicolumn{ 2}{c}{Some text} \\ 
AE2 & 20.65 & 50 & 4.5 \\ 
AE3 & 12.67 & 20 & 7.5 \\ 
AE4 & 0.78 & 75 & 12.09 \\ 
AE5 & 3.098 & 100 & 14 \\
\midrule
\end{tabular}
\end{table}
\end{document}

enter image description here

6
  • second column doesn't use S column type. replace used c with S[table-format=2.3].
    – Zarko
    Sep 21, 2017 at 19:31
  • @Zarko Please help me to undestand this table-format number. I have seen different table-format numbers and I don't know the meaning of each number Sep 21, 2017 at 19:33
  • 2.3means 2 digits before the decimal dot and 3 decimal digits. Your second column has numbers with up to 2 digits for the integer part and up to 3 decimal digits.
    – Bernard
    Sep 21, 2017 at 19:35
  • I've tryed the @Zarko option and it didn't work. I get the following errors: Extra }, or forgotten $. \end{tabular}}} &, Missing control sequence inserted. \end{tabular}}} & and siunitx error: "invalid-number" Invalid numerical input '='. For immediate help type H <return>. \end{tabular}}} & Sep 21, 2017 at 19:42
  • you need enclose second multirow in curly braces. see my answer below.
    – Zarko
    Sep 21, 2017 at 19:43

2 Answers 2

3

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

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

\begin{document}

\begin{table}[htb]
\centering
%\footnotesize
\renewcommand\multirowsetup{\centering}% for centering text in multirow cells
\caption{Example Table}
\begin{tabular}{cS[table-format=2.3]
                 S[table-format=3.0]
                 S[table-format=2.2]}% <--- HERE added S column type
    \toprule
\multirow{2}{*}{\textbf{Column 1}} 
    &   {\multirow{2}{12ex}{\textbf{Column 2}\\(\si{\g/\mL})}} % enclosed in {...} 
                                                               % with defined width is possible write text in more lines
        &   \multicolumn{2}{c}{\textbf{Column 3 (\si{\ug/\L})}}     \\
    \cmidrule{3-4}& &
\textbf{Column 3.1} & \textbf{Column 3.2}   \\
    \midrule
AE1 &  3.45 & \multicolumn{2}{c}{Some text} \\
AE2 & 20.65 & 50 & 4.5                      \\
AE3 & 12.67 & 20 & 7.5                      \\
AE4 &  0.78 & 75 & 12.09                    \\
AE5 & 3.098 & 100 & 14                      \\
    \bottomrule
\end{tabular}
\end{table}
\end{document}
2

I don't think you should lower “Column 1”, because it has the same rank as the other headers in columns 2–4.

The \smash[b]{...} trick allows to pretend that the unit below the header doesn't take vertical space.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{siunitx}

\newcommand{\splitcell}[1]{%
  \smash[b]{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}}%
}

\begin{document}

\begin{table}[htb]
\centering

\caption{Example Table}

\footnotesize % <-- are you sure?
\begin{tabular}{
  @{}
  l
  S[table-format=2.3]
  S[table-format=3.0]
  S[table-format=2.2]
  @{}
}
\toprule
\textbf{Column 1} & 
  {\splitcell{\bfseries Column 2 \\ (\si{\g/\mL})}} &
  \multicolumn{2}{c}{\textbf{Column 3 (\si{\ug/\L})}} \\
\cmidrule(l){3-4}
&& \textbf{Column 3.1} & \textbf{Column 3.2}\\
\midrule
AE1 &  3.45 & \multicolumn{2}{c}{Some text} \\ 
AE2 & 20.65 & 50 & 4.5 \\ 
AE3 & 12.67 & 20 & 7.5 \\ 
AE4 & 0.78 & 75 & 12.09 \\ 
AE5 & 3.098 & 100 & 14 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

The top and bottom rules shouldn't be \midrule; if you don't like the default thickness of \toprule and \bottomrule, you can change the relevant parameter by adding

\setlength{\heavyrulewidth}{\lightrulewidth}

in the document preamble.

enter image description here

You must log in to answer this question.

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