0

Community,

I want to increase the width of a column because the text in the second row makes a new line. When I use p{x.xcm} there is no more centering of the content below.

Picture of table

Here is my code:

\begin{tabularx}{\textwidth}{
 l
>{\centering}X
>{\centering}X
>{\centering}X
>{\centering}X
>{\centering}X
>{\centering}X
>{\centering}X
>{\centering}X
>{\centering}X
>{\centering}X
>{\centering}X
>{\centering}X
>{\centering}X
>{\centering}X
>{\centering}X
>{\centering}X
>{\centering\arraybackslash}X
}
   \toprule
   \multicolumn{1}{c}{\multirow{2}{*}[-0.5ex]{Probe}} & \multicolumn{2}{c}{Brechungsindex} & 
   \multicolumn{3}{c}{Volumen/mL} & \multicolumn{3}{c}{Masse/g} & \multicolumn{3}{c}{Stoffmenge/mol} 
   & \multicolumn{3}{c}{vol\%} & \multicolumn{3}{c}{mol\%}\\
   \cmidrule{2-18}
   & A-reich & B-reich & A & B & C & A & B & C & A & B & C & A & B & C & A & B & C\\
   \midrule
   P1 & 1.4242 & 1.4242 & 42   & 42   & 42   & 42    & 42   & 42 & 42    & 42   & 42 & 42  & 42 & 42 
   & 42  & 42 & 42\\
   P3 & 1.4242 & 1.4242 & 42   & 42   & 42   & 42    & 42   & 42 & 42    & 42   & 42 & 42  & 42 & 42 
   & 42  & 42 & 42\\
  \bottomrule
\end{tabularx}

The table is also in a sideways environment because it is so large.

Thank you in advance.

Greetings FH

4
  • 1
    You could try to replace the first two occurrences of >{\centering} with two c
    – Wulle
    Sep 24, 2020 at 12:19
  • 1
    Since you don't need linebreaks in your cells, I suggest entirely switching from tabularx to tabularor tabular* if you want to make sure yor table is as wide as the current linewidth. Additionally, I would suggest using siunitx for the units and in order to align the numbers in the table columns.
    – leandriis
    Sep 24, 2020 at 12:59
  • 1
    I would also replace \cmidrule{2-18} with \cmidrule(r){2-3} \cmidrule(lr){4-6} \cmidrule(lr){7-9} \cmidrule(lr){10-12} \cmidrule(lr){13-15} \cmidrule(l){16-18}
    – leandriis
    Sep 24, 2020 at 13:07
  • Thank you for the advice I also like the separated lines very much Sep 24, 2020 at 15:10

2 Answers 2

2

Here is my suggestion based on tabular* instead of tabularx.

enter image description here

Depending on the contents of the columns, you might want to consider using siunitx in order to align the numbers with respect to their decimal separator. siunitx also comes in handy for the units in your column headers.

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{rotating}
\begin{document}

\begin{sidewaystable}

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}l*{17}{c}}
   \toprule
   Probe 
     & \multicolumn{2}{c}{Brechungsindex} 
       & \multicolumn{3}{c}{Volumen/mL} 
         & \multicolumn{3}{c}{Masse/g} 
           & \multicolumn{3}{c}{Stoffmenge/mol} 
             & \multicolumn{3}{c}{vol\%} 
               & \multicolumn{3}{c}{mol\%}\\
   \cmidrule(r){2-3} \cmidrule(lr){4-6} \cmidrule(lr){7-9} \cmidrule(lr){10-12} \cmidrule(lr){13-15} \cmidrule(l){16-18}
   & A-reich & B-reich & A & B & C & A & B & C & A & B & C & A & B & C & A & B & C\\
   \midrule
   P1 & 1.4242 & 1.4242 & 42   & 42   & 42   & 42    & 42   & 42 & 42    & 42   & 42 & 42  & 42 & 42 
   & 42  & 42 & 42\\
   P3 & 1.4242 & 1.4242 & 42   & 42   & 42   & 42    & 42   & 42 & 42    & 42   & 42 & 42  & 42 & 42 
   & 42  & 42 & 42\\
  \bottomrule
\end{tabular*}

\end{sidewaystable}
\end{document}
0

As Wulle suggested: replacing the first two >{\centering} with c did the job.

Thank you Wulle

You must log in to answer this question.

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