1

Trying to align cells in a table, i'm struggling as it seems that row 3 and following are not centered, but left justified. I was expecting "Onset" and "Tmax" to be equally spaced from the above (°C).

Here is a MWE (Lualaxtex):

\documentclass{scrreprt}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\begin{table}[htb]
    \centering
    \begin{tabular}{@{} l c c c c c c @{}}
        \toprule
         & \multicolumn{2}{c}{Température de fusion} & \multicolumn{2}{c}{Température de cristallisation} & $\Delta_f H$ & $\chi_c$ \\
         & \multicolumn{2}{c}{(\si{\celsius})} & \multicolumn{2}{c}{(\si{\celsius})} & (\si{\joule\per\gram}) & (\si{\percent}) \\
         & Onset & $T_{max}$ & Onset & $T_{max}$ & & \\
        \midrule
        1er passage & 174.6 & 180.6 & 153.7 & 150.9 & 104 & 49.7\\
        2nd passage & 171.9 & 176.4 & 153.4 & 150.5 & 52.2 & 24.9\\
        \bottomrule
    \end{tabular}
\end{table}
\end{document}
3
  • You have two different fonts. It is to be expected that they differ...
    – TeXnician
    Sep 18, 2017 at 10:06
  • In fact they are centered. The problem is that all extra width coming from the long cells in the first line goes to the last column (of two). It's a known issue, and I'm afraid you can't do anything to resolve it automatically. I would surround the 'Onset' and 'Tmax' headers by some spaces to eat the extra width, like \makebox[3cm][c]{Onset} (you can choose the width to make the table look better). Sep 18, 2017 at 10:18
  • @SergeiGolovan Thank you, that is an acceptable solution, as well as egreg's one. Thank you for your time.
    – Snow
    Sep 18, 2017 at 11:10

1 Answer 1

1

The problem is in the long “Température de cristallisation”.

In general, common parts in the header should not be repeated, so you can print “Température” to straddle the four columns, with a subheader for the two different parts regarding “fusion” and “cristallisation”.

I also use siunitx features for tables in order to get alignment of the figures.

\documentclass{scrreprt}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\begin{table}[htb]
\centering

\begin{tabular}{
  @{}
  l
  S[table-format=3.1]
  S[table-format=3.1]
  S[table-format=3.1]
  S[table-format=3.1]
  S[table-format=3.1]
  S[table-format=2.1]
  @{}
}
\toprule
& \multicolumn{4}{c}{Température (\si{\celsius})} & {$\Delta_f H$} & {$\chi_c$} \\
& \multicolumn{2}{c}{fusion} & \multicolumn{2}{c}{cristallisation} &
  {(\si{\joule\per\gram})} & {(\si{\percent})} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5}
& {Onset} & {$T_{\max}$} & {Onset} & {$T_{\max}$} & & \\
\midrule
1er passage & 174.6 & 180.6 & 153.7 & 150.9 & 104 & 49.7\\
2nd passage & 171.9 & 176.4 & 153.4 & 150.5 & 52.2 & 24.9\\
\bottomrule
\end{tabular}

\end{table}

\end{document}

enter image description here

1
  • thank you. Any place I can learn more on how LaTeX is constructing a table, and why such a long text in the cell will screw up the next rows?
    – Snow
    Sep 18, 2017 at 11:51

You must log in to answer this question.

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