4

I do have to use multirow in one of my tables, but unfortunately I am unable to get it working. The text is cut off and not certered vertically.

What's wrong with my code?

\documentclass[12pt,a4paper]{scrartcl} 
\usepackage{float}
\usepackage{caption}
\usepackage{siunitx}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{booktabs}

\begin{document}
    \begin{table}[H]
        \centering
        \captionabove{Abstände der Nebenmaxima vom Hauptmaxima in den Beugungsbildern der Gitter A bis D}
        \label{tab:abstaende}
        \vspace{-10px}
        \rowcolors{2}{gray!10}{white}
        \begin{tabularx}{\linewidth}{ c c c c c m{0px} }
            \toprule \rowcolor{white}
                \multirowcell{2}[0.5ex]{Ordnung des \\ Nebenmaximums}  &   \multicolumn{4}{c}{Abstände vom Hauptmaximum [\si{mm}]}     &\\ \rowcolor{white}
                &   Gitter A    &   Gitter B    &   Gitter C    &   Gitter D        &\\[6pt]
            \midrule    
            \num{1}     &   \num[separate-uncertainty = true]{3.8 \pm 1}        &   \num[separate-uncertainty = true]{3.9 \pm 1}    &   \num[separate-uncertainty = true]{5.6 \pm 1}    &   \num[separate-uncertainty = true]{5.8 \pm 1}    &\\

            \num{2}     &   \num[separate-uncertainty = true]{7.8 \pm 1}            &   \num[separate-uncertainty = true]{7.7 \pm 1}    &   \num[separate-uncertainty = true]{11.6 \pm 1}   &   \num[separate-uncertainty = true]{11.8 \pm 1}   &\\

            \num{3}     &   \num[separate-uncertainty = true]{11.4 \pm 1}           &   \num[separate-uncertainty = true]{11.6 \pm 1}   &   \num[separate-uncertainty = true]{17.3 \pm 1}   &   \num[separate-uncertainty = true]{17.5 \pm 1}   &\\

            \num{4}     &   \num[separate-uncertainty = true]{15.4 \pm 1}   &   \num[separate-uncertainty = true]{15.4 \pm 1}   &   \num[separate-uncertainty = true]{23.3 \pm 1}   &   \num[separate-uncertainty = true]{23.5 \pm 1}   &\\

            \num{5}     &   \num[separate-uncertainty = true]{19.1 \pm 1}   &   \num[separate-uncertainty = true]{19.3 \pm 1}   &   \num[separate-uncertainty = true]{28.8 \pm 1}   &   \num[separate-uncertainty = true]{29.0 \pm 1}   &\\

            \num{6}     &   \num[separate-uncertainty = true]{23.2 \pm 1}   &   \num[separate-uncertainty = true]{23.0 \pm 1}   &   \num[separate-uncertainty = true]{34.7 \pm 1}   &   \num[separate-uncertainty = true]{34.9 \pm 1}   &\\

            \bottomrule \rowcolor{white}
        \end{tabularx}
    \end{table}
\end{document}

Thanks in advance!

enter image description here

  • Should be fixed :) – Sam Dec 21 '16 at 22:10
5

The second line of the \multirowcell is overwritten by the row color. When useing \multirow with table colors, put the \multirow entry in the last row, with a negate nrows parameter, like this:

    \toprule \rowcolor{white}
        &   \multicolumn{4}{c}{Abstände vom Hauptmaximum [\si{mm}]}     &\\ \rowcolor{white}
      \multirowcell{-2}[0.5ex]{Ordnung des \\ Nebenmaximums}   &   Gitter A    &   Gitter B    &   Gitter C    &   Gitter D        &\\[6pt]
    \midrule    
| improve this answer | |
4

Just a little reformatting. I was too slow...

% arara: pdflatex

\documentclass[12pt]{scrartcl} 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{caption}
\usepackage{siunitx}
\sisetup{separate-uncertainty=true}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{booktabs}

\begin{document}
\begin{table}
    \centering
    \caption{Abstände der Nebenmaxima vom Hauptmaxima in den Beugungsbildern der Gitter A bis D}
    \label{tab:abstaende}
    \rowcolors{2}{gray!10}{white} 
    \begin{tabular}{%
        S[table-format={1.0}] 
        S[table-format={2.1}, table-figures-uncertainty=1]
        S[table-format={2.1}, table-figures-uncertainty=1]
        S[table-format={2.1}, table-figures-uncertainty=1]
        S[table-format={2.1}, table-figures-uncertainty=1]
        }
        \toprule
        & \multicolumn{4}{c}{Abstände vom Hauptmaximum in \si{\milli\metre}} \\
        \multirow{-2}{*}{\begin{tabular}{@{}l@{}}Ordnung des\\Nebenmaximums\end{tabular}} & {Gitter A} & {Gitter B} & {Gitter C} & {Gitter D} \\
        \midrule  
        1 & 3.8  \pm 1 & 3.9  \pm 1 & 5.6  \pm 1 & 5.8  \pm 1 \\
        2 & 7.8  \pm 1 & 7.7  \pm 1 & 11.6 \pm 1 & 11.8 \pm 1 \\
        3 & 11.4 \pm 1 & 11.6 \pm 1 & 17.3 \pm 1 & 17.5 \pm 1 \\
        4 & 15.4 \pm 1 & 15.4 \pm 1 & 23.3 \pm 1 & 23.5 \pm 1 \\
        5 & 19.1 \pm 1 & 19.3 \pm 1 & 28.8 \pm 1 & 29.0 \pm 1 \\
        6 & 23.2 \pm 1 & 23.0 \pm 1 & 34.7 \pm 1 & 34.9 \pm 1 \\
        \bottomrule
    \end{tabular}
\end{table}
\end{document}
| improve this answer | |
2

Just put the \multirow on the last row, with a negative number of rows. I improved your table using the S column type from siunitx, and simplified its coding. No tabularx is required, as you don't use the X column type. I replaced it with a simple tabular, within threeparttable, so the caption has the width of the table. Last point: rules from booktabs leave a thin white strip at the top and bottom of coloured cells, due to the padding around these rules (\aboverulesep and \belowrulesep). There are workarounds with makecell, which also has variable width rules without the padding, but I cheated, removing this padding where necessary.

\documentclass[12pt,a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{float}
\usepackage{caption}
\usepackage{siunitx}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{makecell, booktabs,  threeparttable}
\usepackage[table]{xcolor}

\begin{document}

\begin{table}[H]
    \centering
    \sisetup{table-format=2.1 (2), table-number-alignment=center,  separate-uncertainty = true,  table-figures-uncertainty=1,  %
     table-align-uncertainty}
    \begin{threeparttable}
    \captionabove{Abstände der Nebenmaxima vom Hauptmaxima in den Beugungsbildern der Gitter A bis D}
    \label{tab:abstaende}
    \vspace{-10px}
    \rowcolors{1}{white}{gray!10}
    \begin{tabular}{c*{4}{S} m{0px}}%
        \toprule
         & \multicolumn{4}{c}{Abstände vom Hauptmaximum [\si{mm}]} &\\
         \addlinespace
       \cellcolor{white}  \multirowcell{-2}{Ordnung des \\ Nebenmaximums} & {Gitter A} & {Gitter B} & {Gitter C} & {Gitter D} &\\[6pt]
        \noalign{\vspace{-\aboverulesep}}\midrule
        \num{1} & 3.8 (10) & 3.9  (10) & 5.6  (10) & 5.8  (10) &\\
        \num{2} & 7.8  (10) & 7.7  (10) & 11.6  (10) & 11.8  (10) &\\
        \num{3} & 11.4  (10) & 11.6  (10) & 17.3  (10) & 17.5  (10) &\\
        \num{4} & 15.4  (10) & 15.4  (10) & 23.3  (10) & 23.5  (10) &\\
        \num{5} & 19.1  (10) & 19.3  (10) & 28.8  (10) & 29.0  (10) &\\
        \num{6} & 23.2  (10) & 23.0  (10) & 34.7  (10) & 34.9  (10) &\\[-\aboverulesep]
        \bottomrule
    \end{tabular}
    \end{threeparttable}
\end{table}

\end{document} 

enter image description here

| improve this answer | |
2

I suppose that you like to obtain something like this:

enter image description here

Edit: Combination of Piet van Oostrum, LaRiFaRi and mine first version of answer (it is on bottom of answer) gives even more concise code for above picture of table:

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{caption}
\usepackage{siunitx}
\usepackage[table]{xcolor}
\usepackage{booktabs, multirow, tabularx}
\belowrulesep=0pt
\aboverulesep=0pt    
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcommand\mcx[1]{\multicolumn{1}{C}{#1}}% new

\begin{document}
    \begin{table}
\renewcommand\arraystretch{1.2}
    \centering
\captionabove{Abstände der Nebenmaxima vom Hauptmaxima in den Beugungsbildern der Gitter A bis D}
    \label{tab:abstaende}
    \vspace{-10px}
    \rowcolors{2}{white}{gray!10}
\begin{tabularx}{\linewidth}{    C 
                            *{4}{S[table-format=2.1 (2),% from LaRiFaRi 
                                   separate-uncertainty = true,  
                                   table-figures-uncertainty=1]}}
    \toprule
    \rowcolor{white} % next dour lines from Piet van Oostrum
  & \multicolumn{4}{c}{Abstände vom Hauptmaximum [\si{mm}]}     \\
    \rowcolor{white}
\multirow{-2}{=}{Ordnung des Nebenmaximums}
  & \mcx{Gitter A} & \mcx{Gitter B} & \mcx{Gitter C} & \mcx{Gitter D}  \\
    \midrule % table content from LaRiFaRi
1 & 3.8  \pm 1 & 3.9  \pm 1 & 5.6  \pm 1 & 5.8  \pm 1 \\
2 & 7.8  \pm 1 & 7.7  \pm 1 & 11.6 \pm 1 & 11.8 \pm 1 \\
3 & 11.4 \pm 1 & 11.6 \pm 1 & 17.3 \pm 1 & 17.5 \pm 1 \\
4 & 15.4 \pm 1 & 15.4 \pm 1 & 23.3 \pm 1 & 23.5 \pm 1 \\
5 & 19.1 \pm 1 & 19.3 \pm 1 & 28.8 \pm 1 & 29.0 \pm 1 \\
6 & 23.2 \pm 1 & 23.0 \pm 1 & 34.7 \pm 1 & 34.9 \pm 1 \\
     \bottomrule 
\end{tabularx}
    \end{table}
\end{document}

In comparison to the first version of answer use of \num in table is replaced by S column type as suggested LaRiFaRi, row colors are used as suggested Piet van Oostrum, for equal width of table columns serve new command \mcx.

The first version: Using tabularx at least one column had to be X type. For centering I define new column type C (see MWE below). The use of num{...} in the first column is not necessary, for others the set up is defined at loading sinunitx package

Also multirow and rowcolors doesn't work fine together. So I add to rowcolor command to each colored row. The arraystretch is increased, and for better looks of table the vertical space above and below rules from booktabs are set to zero.

Purpose the last column isn't clear. I delete it as surplus.

\documentclass[12pt,a4paper]{scrartcl}
%\usepackage{float}
\usepackage{caption}
\usepackage[separate-uncertainty = true]{siunitx}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{booktabs, multirow}
\belowrulesep=0pt
\aboverulesep=0pt

\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}
    \begin{table}%[H]
\renewcommand\arraystretch{1.2}
        \centering
\captionabove{Abstände der Nebenmaxima vom Hauptmaxima in den Beugungsbildern der Gitter A bis D}
        \label{tab:abstaende}
        \vspace{-10px}
\begin{tabularx}{\linewidth}{ C C C C C}
    \toprule 
%    \rowcolor{white}
\multirow{2}{=}{Ordnung des \\ Nebenmaximums}
    &   \multicolumn{4}{c}{Abstände vom Hauptmaximum [\si{mm}]}     \\
    &   Gitter A    &   Gitter B    &   Gitter C    &   Gitter D    \\
    \midrule
\rowcolor{gray!10}
1   &   \num{3.8 \pm 1}        
        &   \num{3.9 \pm 1}
            &   \num{5.6 \pm 1}
                &   \num{5.8 \pm 1}    \\
2   &   \num{7.8 \pm 1}
        &   \num{7.7 \pm 1}
            &   \num{11.6 \pm 1}
                &   \num{11.8 \pm 1}   \\
\rowcolor{gray!10}
3   &   \num{11.4 \pm 1}
        &   \num{11.6 \pm 1}
            &   \num{17.3 \pm 1}
                &   \num{17.5 \pm 1}   \\
4   &   \num{15.4 \pm 1}
        &   \num{15.4 \pm 1}
            &   \num{23.3 \pm 1}
                &   \num{23.5 \pm 1}   \\
\rowcolor{gray!10}
5   &   \num{19.1 \pm 1}
        &   \num{19.3 \pm 1}
            &   \num{28.8 \pm 1}
                &   \num{29.0 \pm 1}   \\
6   &   \num{23.2 \pm 1}
        &   \num{23.0 \pm 1}
            &   \num{34.7 \pm 1}
                &   \num{34.9 \pm 1}   \\
    \bottomrule 
        \end{tabularx}
    \end{table}
\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.