3

I'm having trouble aligning angle values in my document with siunitx. The numbers are only aligned properly if I don't use the \ang{} command from siunitx. I made a small, minimum working example that shows the issue:

enter image description here

\documentclass[
    12pt,                                   
    DIV=12,                                 
    paper=A4,                                                       
    parskip=half,                                           
]{scrreprt}

\usepackage{booktabs}                       
\usepackage{tabularx}                       

\usepackage{siunitx}
\sisetup{locale = DE}


\begin{document}
    
\begin{table}[h]
\caption{Align the following numbers}
    \begin{tabularx}{\textwidth}{S[table-format=+2.2]}
        \toprule
        \textbf{Values} \\
        \midrule
        \ang{70,50}     \\
        \ang{40,50}     \\
        \ang{20,50}     \\
        \ang{-4,40}     \\
        \ang{0,50}      \\
        \bottomrule
    \end{tabularx}
    \label{tab:Test1}
\end{table}

\begin{table}[h]
    \caption{Align the following numbers}
    \begin{tabularx}{\textwidth}{S[table-format=+2.2]}
        \toprule
        \textbf{Values} \\
        \midrule
        70,50           \\
        40,50           \\
        20,50           \\
        -4,40           \\
         0,50           \\
        \bottomrule
    \end{tabularx}
    \label{tab:Test2}
\end{table}
    
\end{document}

1 Answer 1

4

Something like this?

enter image description here

\documentclass[12pt]{scrreprt}
\usepackage{booktabs} 
\usepackage[locale = DE]{siunitx}

\begin{document}

\begin{tabular}{ @{} S[table-format = -1.2 \unit{\degree},
                       table-align-text-after = false] @{} }
  \toprule
  {\textbf{Values}} \\
  \midrule
  70,50 \unit{\degree} \\
  40,50 \unit{\degree} \\
  20,50 \unit{\degree} \\
  -4,40 \unit{\degree} \\
   0,5  \unit{\degree} \\
  \bottomrule
\end{tabular}

\end{document}
4
  • This is what i was looking for. Thank you very much!
    – mab0189
    Jul 29, 2023 at 19:33
  • I just noticed a problem with this solution that becomes visible if you use another unit. The space between the numeric value and the unit is not added automatically. You can fix this manually if you insert a \thinspace between the numeric value and the unit.
    – mab0189
    Jul 30, 2023 at 15:06
  • 1
    @mab0189 If the unit is common to all the entries, it should be in the column header; if the values have different units, they shouldn't be aligned at the decimal separator.
    – egreg
    Jul 30, 2023 at 15:09
  • @egreg This is a valid remark, but I would like to convince myself of the various possibilities.
    – mab0189
    Jul 30, 2023 at 15:43

You must log in to answer this question.

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