1

Like the title suggests, I'd like to use the S[table-format = xyz] form in my tables, while having the longer headers be wrapped.

\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}


\begin{table}[!h]
\centering
\caption{Pipettierschema Teilversuch 2}
\label{tab:ps2}
\begin{tabular}{@{} l S[table-format = 1.3] S[table-format = 3.0] c c c c @{}} 
\toprule
{nº} & {Pyruvatkonzentration} & {Bidestilliertes Wasser} & {Pyruvat} & {Imidazolpuffer} & {NADH} & {Lactat}\\ 
\midrule
  1 & 0,01 & 878 & 20 & 5 & 2 & 0 \\
  2 & 0,015 & 877 & 20 & 15 & 2 & 0 \\ 
  3 & 0,02 & 876 & 20 & 25 & 2 & 0 \\
\bottomrule
\end{tabular}
\end{table} 


\end{document}

The table is too wide using S mode

In this case, I'd like the "Pyruvatkonzentration" and/or "Bidestilliertes Wasser" to get wrapped, but for the numbers to retain the Siuntix appearance. Preferably, I'd love to set it up in the preamble, or within the code for the table itself, and have it wrap the words for me, and not manually set each hyphenation in each word.

2 Answers 2

1

You can use \multicolumn{1}{…}{…} to specify another column type for the heads, e.g.:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}

\newcommand*{\TableHead}[1]{\multicolumn{1}{p{4em}}{\centering\hskip0pt#1}}
  
\begin{table}[!h]
\centering
\caption{Pipettierschema Teilversuch 2}
\label{tab:ps2}
\begin{tabular}{@{} l S[table-format = 1.3] S[table-format = 3.0] c c c c @{}} 
\toprule
{nº} & \TableHead{Pyruvatkonzentration} & \TableHead{Bidestilliertes Wasser} & {Pyruvat} & \TableHead{Imidazolpuffer} & {NADH} & {Lactat}\\ 
\midrule
  1 & 0,01 & 878 & 20 & 5 & 2 & 0 \\
  2 & 0,015 & 877 & 20 & 15 & 2 & 0 \\ 
  3 & 0,02 & 876 & 20 & 25 & 2 & 0 \\
\bottomrule
\end{tabular}
\end{table} 


\end{document}

enter image description here

If you also need to specify the width of the some columns for the heads, you can define, e.g.

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}

\NewExpandableDocumentCommand{\TableHead}{O{4em}m}{\multicolumn{1}{p{#1}}{\centering\hskip0pt#2}}
  
\begin{table}[!h]
\centering
\caption{Pipettierschema Teilversuch 2}
\label{tab:ps2}
\begin{tabular}{@{} l S[table-format = 1.3] S[table-format = 3.0] c c c c @{}} 
\toprule
{nº} & \TableHead[6em]{Pyruvatkonzentration} & \TableHead[6em]{Bidestilliertes Wasser} & {Pyruvat} & \TableHead{Imidazolpuffer} & {NADH} & {Lactat}\\ 
\midrule
  1 & 0,01 & 878 & 20 & 5 & 2 & 0 \\
  2 & 0,015 & 877 & 20 & 15 & 2 & 0 \\ 
  3 & 0,02 & 876 & 20 & 25 & 2 & 0 \\
\bottomrule
\end{tabular}
\end{table} 

\end{document}

 
1

Simple is with tblr of tabularray package. No need to define command for column headers, text in column headers is hyphenate by adding cmd=\hskip0pt to specification for the first table row:

\documentclass{book}
\usepackage[ngerman]{babel}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document}
    \begin{table}[ht]
\begin{tblr}{colspec = {@{} c X[c, si={table-format=1.3}]
                              X[c, si={table-format=3.0}]
                         *{2}{X[c, si={table-format=2.0}]}
                         *{2}{X[c, si={table-format=1.0}]}
                        @{} },
             row{1}  = {guard, f, cmd=\hskip0pt} 
            }
    \toprule
nº  & Pyruvatkonzentration 
            & Bidestilliertes Wasser    
                    & Pyruvat   & Imidazolpuffer    
                                        & NADH  & Lactat    \\
    \midrule
  1 & 0,01  & 878   & 20        & 5     & 2     & 0         \\
  2 & 0,015 & 877   & 20        & 15    & 2     & 0         \\
  3 & 0,02  & 876   & 20        & 25    & 2     & 0         \\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

enter image description here

1
  • I like your solution, yet for me the table is still buggy. The only wrapped section is the "Bidestilliertes Wasser". The "Pyruvatkonzentration" and "Imidazolpuffer" go out of bounds: link
    – m0n74g3
    Commented May 18, 2023 at 9:23

You must log in to answer this question.

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