2

I try to place the three first description in a multirow enviroment and include a linebreak.

But I did not succed in doing this without creating an error. Do you have an idea how I could do this?

% page setup 
\documentclass[a4paper, 11pt]{article}
\usepackage[margin=2cm]{geometry}

% language
\usepackage[utf8]{inputenc} 

% graphics
\usepackage{array,multirow,graphicx} 

% units 
\usepackage{siunitx}

% chemistry 
\usepackage{ghsystem}
\usepackage[version=4]{mhchem} 

% tables
\usepackage{ragged2e} 
\usepackage{booktabs, tabularx}
%____________________________________________________________________________________________________________
\newcolumntype{B}[1]{>{\scriptsize\RaggedRight\hspace{0pt}}p{#1}}
\newcolumntype{L}{>{\scriptsize\RaggedRight\hspace{0pt}}X}
\newlength\colwidth
%____________________________________________________________________________________________________________
% figures 
\usepackage{float}
%____________________________________________________________________________________________________________

\begin{document}

\begin{table}[ht!]
\settowidth\colwidth{\textbf{Solution}} % <-- need to use \textbf to get correct measurement
\begin{tabularx}{\textwidth}{@{} B{\colwidth} *{8}{L} @{}} 
\toprule 
\multirow{2}{*}{\textbf{Solution}}   & \multirow{2}{*}{\textbf{\shortstack{Molar mass \\ [$\si{\gram\per\mol}$]}}}   & \multirow{2}{*}{\textbf{ V stock \\ [$\si{\milli\liter}$] }}&      \multicolumn{3}{c}{\textbf{Amount of substance [$\si{\milli\mol}$]}  }     &       \multicolumn{3}{c}{\textbf{Mass [$\si{\gram}$]}  }           \\
\cmidrule(lr){4-6} \cmidrule(lr){7-9}
 & & & $\ce{KH2PO4}$ & $\ce{Na2HPO4}$ & $\ce{NaCl}$ & $\ce{KH2PO4}$ & $\ce{Na2HPO4}$ & $\ce{NaCl}$\\
\midrule
$\ce{KH2PO4}$ stock     &  \num{150}  & $\num{1.5}$  & -                 & $\num{}$ &  $\num{}$ & -         & $\num{}$ \\
$\ce{Na2HPO4}$ stock    &  \num{100}  & -             & $\num{1}$      & $\num{}$ & -            &\num{}     & $\num{}$ \\
\bottomrule
\end{tabularx}
\endtabularx
\end{table}

\end{document}

here

4
  • 1
  • 1
    The problem is that some of your \` are followed by [` (with some spaces in between), but these are interpreted as an optional argument for \`. So write \\{}[...` instead. Apr 23, 2021 at 16:07
  • 1
    In your \multirows, why don't you use {=} in the place of {*} since they happen in fixed width columns?
    – Bernard
    Apr 23, 2021 at 16:13
  • 1
    What's the purpose of all the $ in your table? Neither \si not \ce needs math mode to function properly.
    – leandriis
    Apr 23, 2021 at 16:36

3 Answers 3

4

Here are two alternative suggestions:

enter image description here

\documentclass[a4paper, 11pt]{article}
\usepackage[margin=2cm]{geometry}

\usepackage{array,multirow} 
\usepackage{siunitx}

\usepackage[version=4]{mhchem} 
\usepackage{booktabs, tabularx}

\usepackage{makecell}
\renewcommand{\theadfont}{\bfseries}

\begin{document}

\begin{table}[ht!]
\setlength{\tabcolsep}{4.5pt}
\begin{tabularx}{\linewidth}{@{}XS[table-format=3] S[table-format=1.1] *{6}{c} @{}} 
\toprule 
\thead{Solution}   & {\thead{Molar mass\\{}  [\si{\gram\per\mol}]}}   & {\thead{ V stock\\{}  [\si{\milli\liter}]}} &      \multicolumn{3}{c}{\thead{Amount of substance\\{} [\si{\milli\mol}]}  }     &       \multicolumn{3}{c}{\thead{Mass\\{} [\si{\gram}]}  }           \\
\cmidrule(r){4-6} \cmidrule(l){7-9}
                     &       &      & \ce{KH2PO4} & \ce{Na2HPO4} & \ce{NaCl} & \ce{KH2PO4} & \ce{Na2HPO4} & \ce{NaCl}\\
\midrule
\ce{KH2PO4} stock    &  150  & 1.5  & -           &              &           & -           &              &     \\
\ce{Na2HPO4} stock   &  10   & {-}  & 1           &              & -         &             &              &     \\
\bottomrule         
\end{tabularx}
\end{table}


\begin{table}[ht!]
\small
\begin{tabular}{@{}l S[table-format=3] S[table-format=1.1] *{6}{c} @{}} 
\toprule 
\multirow{2.5}{*}{\thead{Solution}}   & {\multirow{2.5}{*}{\thead{Molar mass\\{}  [\si{\gram\per\mol}]}}}   & {\multirow{2.5}{*}{\thead{ V stock\\{}  [\si{\milli\liter}]}}} &      \multicolumn{3}{c}{\thead{Amount of substance [\si{\milli\mol}]}  }     &       \multicolumn{3}{c}{\thead{Mass [\si{\gram}]}  }           \\
\cmidrule(r){4-6} \cmidrule(l){7-9}
                     &       &      & \ce{KH2PO4} & \ce{Na2HPO4} & \ce{NaCl} & \ce{KH2PO4} & \ce{Na2HPO4} & \ce{NaCl}\\
\midrule
\ce{KH2PO4} stock    &  150  & 1.5  & -           &              &           & -           &              &     \\
\ce{Na2HPO4} stock   &  10   & {-}  & 1           &              & -         &             &              &     \\
\bottomrule         
\end{tabular}
\end{table}


\end{document}
3

Here is a solution. I have used \multirowcell from the \makecell package for the multiline \multirows and left the units outside of \textbf because units won't be done bold. The second column is fit to the "Molar mass" width.

EDIT: In fact \multirow{2}={\textbf{Molar mass} \\{}[$\si{\gram\per\mol}$] } works as well as \multirowcell, and for the other one similar.

\documentclass[a4paper, 11pt]{article}
\usepackage[margin=2cm]{geometry}

% language
\usepackage[utf8]{inputenc} 

% graphics
\usepackage{array,multirow,graphicx} 

% units 
\usepackage{siunitx}

% chemistry 
\usepackage{ghsystem}
\usepackage[version=4]{mhchem} 

% tables
\usepackage{ragged2e} 
\usepackage{booktabs, tabularx}
%____________________________________________________________________________________________________________
\newcolumntype{B}[1]{>{\scriptsize\RaggedRight\hspace{0pt}}p{#1}}
\newcolumntype{L}{>{\scriptsize\RaggedRight\hspace{0pt}}X}
\newlength\colwidth
\newlength\colwidthb
%____________________________________________________________________________________________________________
% figures 
\usepackage{float}
%____________________________________________________________________________________________________________
\usepackage{makecell}

\begin{document}

\begin{table}[ht!]
\settowidth\colwidth{\textbf{Solution}} % <-- need to use \textbf to get correct measurement
\settowidth\colwidthb{\textbf{Molar mass}} % <-- need to use \textbf to get correct measurement
\begin{tabularx}{\textwidth}{@{} B{\colwidth} @{} B{\colwidthb}@{} *{7}{L} @{}} 
\toprule 
 \multirow{2}*{\textbf{Solution}}   &
 \multirowcell{2}[0pt][l]{\textbf{Molar mass} \\{}[$\si{\gram\per\mol}$] }  &
 \multirowcell{2}[0pt][l]{\textbf{V mass} \\{}[\si{\milli\liter}] }  &
    \multicolumn{3}{c}{\textbf{Amount of substance [$\si{\milli\mol}$]}  }     &   
    \multicolumn{3}{c}{\textbf{Mass [$\si{\gram}$]}  }    
       \\
\cmidrule(lr){4-6} \cmidrule(lr){7-9}
 & & & \ce{KH2PO4} & \ce{Na2HPO4} & \ce{NaCl} & \ce{KH2PO4} & \ce{Na2HPO4} & \ce{NaCl} \\
\midrule
$\ce{KH2PO4}$ stock     &  \num{150}  & $\num{1.5}$  & -                 & $\num{}$ &  $\num{}$ & -         & $\num{}$ \\
$\ce{Na2HPO4}$ stock    &  \num{100}  & -             & $\num{1}$      & $\num{}$ & -            &\num{}     & $\num{}$ \\
\bottomrule
\end{tabularx}
%\endtabularx
\end{table}

\end{document}

enter image description here

1

With {NiceTabular} of nicematrix.

\documentclass[a4paper, 11pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{siunitx}
\usepackage[version=4]{mhchem} 
\usepackage{booktabs}
\usepackage{nicematrix}

\begin{document}

\begin{table}[ht!]
\small
\begin{NiceTabular}{@{}l S[table-format=3] S[table-format=1.1] *{6}{c} @{}} 
\toprule 
\Block{2-1}{\bfseries Solution} 
& \Block{2-1}<\bfseries>{Molar mass\\{} [\si{\gram\per\mol}]} 
& \Block{2-1}<\bfseries>{V stock\\{} [\si{\milli\liter}]} 
& \Block{1-3}<\bfseries>{Amount of substance\\ [\si{\milli\mol}]} &&
& \Block{1-3}{\bfseries Mass\\ [\si{\gram}]} \\
\cmidrule(r){4-6} \cmidrule(l){7-9}
                     &       &      & \ce{KH2PO4} & \ce{Na2HPO4} & \ce{NaCl} & \ce{KH2PO4} & \ce{Na2HPO4} & \ce{NaCl}\\
\midrule
\ce{KH2PO4} stock    &  150  & 1.5  & -           &              &           & -           &              &     \\
\ce{Na2HPO4} stock   &  10   & {-}  & 1           &              & -         &             &              &     \\
\bottomrule         
\end{NiceTabular}
\end{table}

\end{document}

Output of the above code

You must log in to answer this question.

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