7

I am trying to make a table with tabu and using the sunitx package to align and round the entries of my table. However I keep getting the following error:

! siunitx error: "unknown-option" ! ! Unknown option 'm'. ! ! See the siunitx documentation for further information.

My MNWE (minimal not-working example)

\documentclass[a4paper]{scrreprt}             
\usepackage{siunitx,booktabs}
\usepackage{tabu}
\usepackage[]{xcolor}

\begin{document}
\newcolumntype Z{ XS[m,
 tight-spacing=true,round-mode=places,
                          round-precision=2] }
\begin{table} 
\centering 
\small
\caption{Caption}\label{tab:exAll}
\begin{tabu}{X[m,l] ZZZZZZZZ}  
\toprule
{}&{A}&{B}&{C}&{D}&{E}&{F}&{G}&{H}\\
\midrule
case 1&0.038941&    10.793553&  10.793553&  2.660292&   5.364928&   0.287945&   4.950661&   1.017396\\
case 2&0.051109&    10.416524&10.416524&    2.699890&5.236410&  0.348350&   5.528117&   0.835394\\
case 3&0.042755&    11.165675&11.165675&    2.845072&   6.585281&   0.279750&   5.059948&   0.920121\\
case 4&0.043165&    10.820561   &10.820561& 2.708484&   5.250033&   0.291793&   4.661221&   0.879731\\
case 5&0.042951&13.764616&13.764616&    2.643305&   5.608317&   0.278537&   5.080898&   0.871181\\
case 6&0.042078&    10.909180   &10.909180& 2.568346&   5.198260&   0.311224&   4.724302&   0.862366\\
\bottomrule
\end{tabu}
\end{table}

\end{document}

How can I solve this problem? I looked at similar questions here on tex.se but those didn't help me. I hope I am not overlooking something very simple.

3

2 Answers 2

12

Change your new column definition to

\newcolumntype{Z}{S[
 tight-spacing=true,round-mode=places,
                          round-precision=2] }

Full code:

\documentclass[a4paper]{scrreprt}
\usepackage{siunitx,booktabs}
\usepackage{tabu}
\usepackage[]{xcolor}

\begin{document}
\newcolumntype{Z}{S[
 tight-spacing=true,round-mode=places,
                          round-precision=2] }
\begin{table}
\centering
\small
\caption{Caption}\label{tab:exAll}
\begin{tabu}{X[m,l] ZZZZZZZZ}
\toprule
{}&{A}&{B}&{C}&{D}&{E}&{F}&{G}&{H}\\
\midrule
case 1&0.038941&    10.793553&  10.793553&  2.660292&   5.364928&   0.287945&   4.950661&   1.017396\\
case 2&0.051109&    10.416524&10.416524&    2.699890&5.236410&  0.348350&   5.528117&   0.835394\\
case 3&0.042755&    11.165675&11.165675&    2.845072&   6.585281&   0.279750&   5.059948&   0.920121\\
case 4&0.043165&    10.820561   &10.820561& 2.708484&   5.250033&   0.291793&   4.661221&   0.879731\\
case 5&0.042951&13.764616&13.764616&    2.643305&   5.608317&   0.278537&   5.080898&   0.871181\\
case 6&0.042078&    10.909180   &10.909180& 2.568346&   5.198260&   0.311224&   4.724302&   0.862366\\
\bottomrule
\end{tabu}
\end{table}

\end{document}

enter image description here

With round-precision=3, you get

enter image description here

1

Notice that in this solution (unlike the other one), the numbers are both aligned and centered in each column.

\documentclass{scrreprt}

\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{
%  locale = DE, % comma as decimal separator
  tight-spacing = true,
  round-mode = places
}

\def\precision{2} % change this value to suit your needs
\newcolumntype{Y}{S[table-format = 2.\precision, round-precision = \precision]}
\newcolumntype{Z}{S[table-format = 1.\precision, round-precision = \precision]}

\begin{document}

\begin{table}[htbp]
 \centering
 \small
  \caption{An extremely relevant caption.}
  \label{tab:exAll}
    \begin{tabular}{l @{\qquad} Z *{2}{Y} *{5}{Z}}
     \toprule
             & {A}      & {B}       & {C}       & {D}      & {E}      & {F}      & {G}      & {H}      \\
     \midrule
      Case~1 & 0.038941 & 10.793553 & 10.793553 & 2.660292 & 5.364928 & 0.287945 & 4.950661 & 1.017396 \\
      Case~2 & 0.051109 & 10.416524 & 10.416524 & 2.699890 & 5.236410 & 0.348350 & 5.528117 & 0.835394 \\
      Case~3 & 0.042755 & 11.165675 & 11.165675 & 2.845072 & 6.585281 & 0.279750 & 5.059948 & 0.920121 \\
      Case~4 & 0.043165 & 10.820561 & 10.820561 & 2.708484 & 5.250033 & 0.291793 & 4.661221 & 0.879731 \\
      Case~5 & 0.042951 & 13.764616 & 13.764616 & 2.643305 & 5.608317 & 0.278537 & 5.080898 & 0.871181 \\
      Case~6 & 0.042078 & 10.909180 & 10.909180 & 2.568346 & 5.198260 & 0.311224 & 4.724302 & 0.862366 \\
     \bottomrule
    \end{tabular}
\end{table}

\end{document}

output

All you have to do is choose the value of \precision and the table will automatically be typeset correct.

You must log in to answer this question.

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