4

I can't wrap my head around multicolumns in latex.

\documentclass{article}
\usepackage{booktabs}
\usepackage{array}
\usepackage{siunitx}
\usepackage{rotating}
\usepackage[colorlinks]{hyperref}

\sisetup{ % insert global siunitx settings here separate-uncertainty=true, group-digits=false, round-pad=false, table-auto-round=true, group-separator={}, }

\newcolumntype{T}{S[table-format=2.1]} \newcolumntype{U}{S[table-format=1.5(1)]} \begin{document} \begin{tabular}{ S TT UUUU } \toprule \multicolumn{2}{c}{\textbf{Mass fraction}, \textbf{Concentration}, \textbf{Density relative to \qty{4}{\degreeCelsius} water}} & \ \multicolumn{4}{c}{(\unit{\percent}) Volume (\unit{\percent}) Mass (\unit{\gram}/(\qty{100}{\mL})) \qty{10}{\degreeCelsius} \qty{20}{\degreeCelsius} \qty{25}{\degreeCelsius} \qty{30}{\degreeCelsius}} \ 0 & 0 & 0 & 0.99973(2) & 0.99823(1) & 0.99708(3) & 0.99568(1) \ 4.0 & 5.00 & 3.97 & 0.99258(1) & 0.99103(2) & 0.98984(2) & 0.98839(2) \ 10.0 & 12.40 & 9.84 & 0.98393(2) & 0.98187(1) & 0.98043(2) & 0.97875(2) \ 18.0 & 22.10 & 17.54 & 0.97473(1) & 0.97129(2) & 0.96923(1) & 0.96697(1) \ 25.0 & 30.40 & 24.12 & 0.96665(2) & 0.96168(3) & 0.95895(2) & 0.95607(3) \ 28.0 & 33.90 & 26.90 & 0.96268(3) & 0.95710(1) & 0.95410(3) & 0.95098(2) \ 30.0 & 36.20 & 28.73 & 0.95977(1) & 0.95382(2) & 0.95067(2) & 0.94741(2) \ \bottomrule \end{tabular} \end{document}

Generated it looks like this: Mine

How can I get the first two rows of my table to look like the one below?

Goal

  • Welcome. // There were many similar questions answered here. Just follow the multicolumn tag you placed and add some more keywords. The tag alone guides you to over 1.000 answers. Also check out the Related entries to the right. – MS-SPO Jan 15 '24 at 07:23
  • 2
    If you want help you'll have to adapt your MWE to something we can actually compile. Where are the column types S, T, and U defined? From the looks of it, I'd guess you don't want to use \multicolumn in the first column. And if I guess that S is defined by the siunitx package, you'll need {} around your text if you don't use \multicolumn. – Skillmon Jan 15 '24 at 07:33

1 Answers1

3

Setting the multicolumns is quite trivial, but your table does not fit the page.

Here two solution: 1) a sideways table or 2) a table that goes out of the page borders in a box with zero width:

\documentclass{article}
\usepackage{rotating}
\usepackage{booktabs}
\usepackage{array}
\usepackage{siunitx}
\usepackage{rotating}
\usepackage[colorlinks]{hyperref}

\sisetup{ % insert global siunitx settings here separate-uncertainty=true, group-digits=false, round-pad=false, table-auto-round=true, group-separator={}, }

\newcolumntype{T}{S[table-format=2.1]} \newcolumntype{U}{S[table-format=1.5(1)]}

\begin{document} \begin{sidewaystable}\small\centering \begin{tabular}{@{}S TT UUUU@{}} \toprule \textbf{Mass fraction} &\multicolumn{2}{c}{\textbf{Concentration}}&\multicolumn{4}{c}{\textbf{Density relative to \qty{4}{\degreeCelsius} water}} \ \cmidrule(lr){2-3}\cmidrule(l){4-7} {(\unit{\percent})} & {Volume (\unit{\percent})} & {Mass (\unit{\gram}/(\qty{100}{\mL}))} & {\qty{10}{\degreeCelsius}} & {\qty{20}{\degreeCelsius}} & {\qty{25}{\degreeCelsius}} & {\qty{30}{\degreeCelsius}} \ \midrule 0 & 0 & 0 & 0.99973(2) & 0.99823(1) & 0.99708(3) & 0.99568(1) \ 4.0 & 5.00 & 3.97 & 0.99258(1) & 0.99103(2) & 0.98984(2) & 0.98839(2) \ 10.0 & 12.40 & 9.84 & 0.98393(2) & 0.98187(1) & 0.98043(2) & 0.97875(2) \ 18.0 & 22.10 & 17.54 & 0.97473(1) & 0.97129(2) & 0.96923(1) & 0.96697(1) \ 25.0 & 30.40 & 24.12 & 0.96665(2) & 0.96168(3) & 0.95895(2) & 0.95607(3) \ 28.0 & 33.90 & 26.90 & 0.96268(3) & 0.95710(1) & 0.95410(3) & 0.95098(2) \ 30.0 & 36.20 & 28.73 & 0.95977(1) & 0.95382(2) & 0.95067(2) & 0.94741(2) \ \bottomrule \end{tabular} \caption{Properties of aqueous ethanol solution (Wikipedia)} \end{sidewaystable}

\begin{table}\small\centering\makebox[0pt]{% \begin{tabular}{@{}S TT UUUU@{}} \toprule \textbf{Mass fraction} &\multicolumn{2}{c}{\textbf{Concentration}}&\multicolumn{4}{c}{\textbf{Density relative to \qty{4}{\degreeCelsius} water}} \ \cmidrule(lr){2-3}\cmidrule(l){4-7} & {Volume } & {Mass } & & & & \ {(\unit{\percent})} & {(\unit{\percent})} & {(\unit{\gram}/(\qty{100}{\mL}))} & {\qty{10}{\degreeCelsius}} & {\qty{20}{\degreeCelsius}} & {\qty{25}{\degreeCelsius}} & {\qty{30}{\degreeCelsius}} \ \midrule 0 & 0 & 0 & 0.99973(2) & 0.99823(1) & 0.99708(3) & 0.99568(1) \ 4.0 & 5.00 & 3.97 & 0.99258(1) & 0.99103(2) & 0.98984(2) & 0.98839(2) \ 10.0 & 12.40 & 9.84 & 0.98393(2) & 0.98187(1) & 0.98043(2) & 0.97875(2) \ 18.0 & 22.10 & 17.54 & 0.97473(1) & 0.97129(2) & 0.96923(1) & 0.96697(1) \ 25.0 & 30.40 & 24.12 & 0.96665(2) & 0.96168(3) & 0.95895(2) & 0.95607(3) \ 28.0 & 33.90 & 26.90 & 0.96268(3) & 0.95710(1) & 0.95410(3) & 0.95098(2) \ 30.0 & 36.20 & 28.73 & 0.95977(1) & 0.95382(2) & 0.95067(2) & 0.94741(2) \ \bottomrule \end{tabular}% } \caption{Properties of aqueous ethanol solution (Wikipedia)} \end{table} \end{document}

Sideways:

enter image description here

Out of borders:

enter image description here

CarLaTeX
  • 62,716