4

This is a follow up to Numbers in tables: align by decimal point *and* flush right?.

In a tabular set with siunitx, I can give formatting options or in the \sisetup{} command or in the \begin{tabular} environment options. Why is that so? I would like to give global settings and still be able to modify single columns.

\documentclass{article}
\usepackage[
per-mode=symbol-or-fraction,
locale=DE,
sticky-per
]{siunitx} 
\usepackage{subcaption}
\usepackage[table]{xcolor}

\begin{document}

\begin{table}
    \caption{Comparing global and local settings}
    \sffamily
    \begin{subfigure}[t]{.48\linewidth}
    \caption{Global}
    \sffamily
    \sisetup{detect-family, table-number-alignment = right}
    \rowcolors{2}{white}{gray!20}
    \centering   
        \begin{tabular}{S[table-format=6.0] S[table-format=2.0] S[table-format=4.0]}\hline
        \multicolumn{1}{c|}{Foo} & \multicolumn{1}{c|}{$F$ in \si{\hertz}} & \multicolumn{1}{c}{$\sigma$ in \si{\newton\per\meter\squared}}\\ \hline
        123456 & 12 & 1234 \\ 
        12345 & 1 & 123 \\ 
        1234 & 0 & 12 \\ \hline
        \end{tabular} 
    \end{subfigure}%
    \hfill
    \begin{subfigure}[t]{.48\linewidth}
    \rowcolors{2}{white}{gray!20}
    \centering
    \caption{Local}
    \sffamily
    \sisetup{detect-family}
        \begin{tabular}{S[table-format=6.0, table-number-alignment = right] S[table-format=2.0, table-number-alignment = right] S[table-format=4.0, table-number-alignment = right]}\hline
        \multicolumn{1}{c|}{Foo} & \multicolumn{1}{c|}{$F$ in \si{\hertz}} & \multicolumn{1}{c}{$\sigma$ in \si{\newton\per\meter\squared}}\\ \hline
        123456 & 12 & 1234 \\ 
        12345 & 1 & 123 \\ 
        1234 & 0 & 12 \\ \hline
        \end{tabular} 
    \end{subfigure} 
\end{table}

\end{document}

Edit

If I just set an {S S S} tabular, the output would be correctly aligned, but sometimes I would like to change just one option for a single column. I think that not intuitive.

LaRiFaRi
  • 43,807
  • I'm not sure I understand your question: You are able to combine global options (set with \sisetup) and local options (set using S[...]), where the local options will override the global ones. Try setting table-number-alignment = left for the second column of the second table, for example. – Jake Jul 23 '13 at 15:11
  • @Jake Yes, that is giving no problems. But what happened to the right alignment of the first table? It seems like S[table-format=6.0] overrides \sisetup{table-number-alignment = right}. Solution: S[table-format=6.0, table-number-alignment = right] but thats a lot of text and not logical for my taste. – LaRiFaRi Jul 23 '13 at 15:15
  • 2
    Ah, yeah, I see. This doesn't seem to be a problem with mixing global and local options, but with the order in which table-number-alignment and table-format are provided: Try swapping the order of the options in the second table, and you'll see that table-format deactivates the table-number-alignment. – Jake Jul 23 '13 at 15:21
  • OK, I can reproduce that as well. Is that a bug? Definitely not very intuitive. The first table can just be set with much more writing. A global table-number-alignment for a table or document is not possible. – LaRiFaRi Jul 23 '13 at 15:42
  • 2
    @LaRiFaRi This is documented: table-format sets table-number-alignment = center, so any other alignment has to be given after table-format. – Joseph Wright Jul 23 '13 at 16:26
  • Sorry, haven't seen that in your documentation. Well, than I do a feature request here: I think, that should be changed as overwriting other options always confuses. Thx for all your effort and (by the way) my favourite package! – LaRiFaRi Jul 23 '13 at 17:31

1 Answers1

5

Setting table-format automatically sets table-number-alignment = center, as covered in the package documentation. Thus if you set table-format and want a different alignment you need to set it as well.

The reason for this is that 'out of the box' the settings include table-number-alignment = center-decimal-marker (as this is the 'safe' position). Thus without this auto-setting behaviour, you would see no change at all by setting table-format alone, which would be pretty confusing.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036