1

Ok, I want to have the first row of my table bold faced: Make first row of table all bold, done! But my table has a lot of numbers so siunitx comes in handy with its column specifier S, then the first solution makes the S columns ragged left (why?).

Seems like Bold row in table aligned with dcolumn: A solution with package siunitx could be what I'm looking for, but no. The same thing happens with Heiko's proposal. This is obviously because of the text Header, but why is it happening and how can I get around it?

The following MWE incorporates both solutions and the compilation result is placed below.

\documentclass{standalone}
\usepackage{siunitx,array,booktabs,multirow}
\sisetup{output-decimal-marker={,}}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcolumntype{L}{%
  >{\rowstyle{\relax}}l%
}
\newcolumntype{B}{%
  >{\currentrowstyle}S[detect-weight]%
}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
  #1\ignorespaces
}

\begin{document}
\begin{tabular}{L^cBB}
    \toprule
    \rowstyle{\bfseries}
    \multirow{2}{*}{Day} & {Running time} & {Water bag weight} & {Frost formation rate} \\
 & [days] & \multicolumn{1}{c}{[\si{\gram}]} & \multicolumn{1}{c}{[\si{\gram\per\hour}]} \\
\midrule
    26.09.2016  &   4   &   1098,2  &   11,4    \\
    27.09.2016  &   1   &   329,8   &   13,5    \\
    28.09.2016  &   1   &   288,4   &   11,8    \\
    29.09.2016  &   1   &   291,7   &   11,9    \\
    \midrule
    \rowstyle{\bfseries}
    Average         &       &       &   12,2    \\
    \bottomrule
\end{tabular}

\begin{tabular}{$l^c^S^S}
    \toprule
    \rowstyle{\bfseries}
    \multirow{2}{*}{Day} & {Running time} & {Water bag weight} & {Frost formation rate} \\
 & [days] & \multicolumn{1}{c}{[\si{\gram}]} & \multicolumn{1}{c}{[\si{\gram\per\hour}]} \\
\midrule
    26.09.2016  &   4   &   1098,2  &   11,4    \\
    27.09.2016  &   1   &   329,8   &   13,5    \\
    28.09.2016  &   1   &   288,4   &   11,8    \\
    29.09.2016  &   1   &   291,7   &   11,9    \\
    \midrule
    \rowstyle{\bfseries}
    Average         &       &       &   12,2    \\
    \bottomrule
\end{tabular}
\end{document}

enter image description here

  • \multicolumn overrides the B column for those cells, so either try {...} around them as well (since it seems to work in the text headers), or add boldness and font weight to these cells manually – daleif Sep 30 '16 at 16:04
  • I have tried that already, even with the units without the \sicommand produce the same result, The headers are probably not actually centered, they just look centered because they are the biggest elements of the column. And ok, manually doing thing is pretty much always a solution, but that's not the point, is it? – Guilherme Zanotelli Sep 30 '16 at 16:40
2

The issue here is \relax. This is a 'do nothing' command in TeX but is non-expandable. The siunitx package takes this as being 'end of number' in a table cell: there's not reason to expect one in the middle of a number. As such, you need to arrange that \currentrowstyle is something else, for example an empty macro, when it's not 'active':

\documentclass{standalone}
\usepackage{siunitx,array,booktabs,multirow}
\sisetup{output-decimal-marker={,}}
\newcolumntype{$}{>{\global\let\currentrowstyle\empty}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcolumntype{L}{%
  >{\rowstyle{}}l%
}
\newcolumntype{B}{%
  >{\currentrowstyle}S[detect-weight]%
}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
  #1\ignorespaces
}

\begin{document}
\begin{tabular}{L^cBB}
    \toprule
    \rowstyle{\bfseries}
    \multirow{2}{*}{Day} & {Running time} & {Water bag weight} & {Frost formation rate} \\
 & [days] & \multicolumn{1}{c}{[\si{\gram}]} & \multicolumn{1}{c}{[\si{\gram\per\hour}]} \\
\midrule
    26.09.2016  &   4   &   1098,2  &   11,4    \\
    27.09.2016  &   1   &   329,8   &   13,5    \\
    28.09.2016  &   1   &   288,4   &   11,8    \\
    29.09.2016  &   1   &   291,7   &   11,9    \\
    \midrule
    \rowstyle{\bfseries}
    Average         &       &       &   12,2    \\
    \bottomrule
\end{tabular}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.