3

I can't specify the vertical position of my multirow content. The following compiles fine:

\documentclass{standalone}
\usepackage{booktabs,multirow}
\begin{document}
    \begin{tabular}{p{3cm}ccc}
        \toprule
        \multirow{2}{3cm}{Cat cat cat cat cat cat cat}
        &\multicolumn{3}{c}{Food}\\
        \cmidrule{2-4}
        & A&B&C\\
        \midrule
        D & 123 & 456 & 789\\\addlinespace
        E & 123 & 456 & 789\\\addlinespace
        F & 123 & 456 & 789\\
        \bottomrule
    \end{tabular}
\end{document}

But when I add [b] to the multirow it gets messed up:

\documentclass{standalone}
\usepackage{booktabs,multirow}
\begin{document}
    \begin{tabular}{p{3cm}ccc}
        \toprule
        \multirow[b]{2}{3cm}{Cat cat cat cat cat cat cat}
        &\multicolumn{3}{c}{Food}\\
        \cmidrule{2-4}
        & A&B&C\\
        \midrule
        D & 123 & 456 & 789\\\addlinespace
        E & 123 & 456 & 789\\\addlinespace
        F & 123 & 456 & 789\\
        \bottomrule
    \end{tabular}
\end{document}

According to the multirow documentation the syntax should be fine...

5
  • 1
    In my opinion there is no need for multirow here. You can place Cat in the lower header row - image.
    – Werner
    Commented Jul 30, 2017 at 12:53
  • Yes, in the MWE with reduced content that would do the job. But it's not perfoming as per documentation - is that a bug?
    – Mace
    Commented Jul 30, 2017 at 13:08
  • I updated the MWE to make the problem more apparent.
    – Mace
    Commented Jul 30, 2017 at 13:28
  • I cannot detect any difference in output between the versions with and without the [b] option.
    – Mico
    Commented Jul 30, 2017 at 14:42
  • Hmm.. for me the version with [b] won't compile at all. I get an error Missing number, treated as zero. \multirow[b]
    – Mace
    Commented Jul 30, 2017 at 15:13

2 Answers 2

4

enter image description here

use of rules from booktabs add some vertical space which multirow can not compensate automatically for such and similar cases multirow has possibility to manual adjusting content position:

\documentclass[margin=3mm]{standalone}
\usepackage{booktabs,multirow}

\begin{document}
    \begin{tabular}{p{3cm}ccc}
        \toprule
        \multirow{2}{=}[-0.5ex]{Cat cat cat cat cat cat cat}% [-0.tex] is manual adjusting of posititon
          &   \multicolumn{3}{c}{Food}  \\
        \cmidrule{2-4}
          &  A  &  B  &   C             \\
        \midrule
        D & 123 & 456 & 789             \\\addlinespace
        E & 123 & 456 & 789             \\\addlinespace
        F & 123 & 456 & 789             \\
        \bottomrule
    \end{tabular}
\end{document}
2
  • I get the feeling that something's wrong with my setup. I get the same error as stated above with your code: Missing number, treated as zero. ...{2}{=}[-0.5ex]{Cat cat cat cat cat cat cat}. I run pdfLaTeX. From the log file: pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016/W32TeX) (preloaded format=pdflatex 2016.9.28)
    – Mace
    Commented Jul 30, 2017 at 15:20
  • 1
    hm, it seems that you not have recent multirow package ... it should be version v2.2 from 2016/11/25,
    – Zarko
    Commented Jul 30, 2017 at 15:34
2

The problem comes from the vertical padding around \cmidrule. You have to make a correction for this.

I propose another solution, just in case you don't really need a p column type; with the makecell package, you can break lines inside standard cells. I wrote a code that gives the same result with \multirowcell and a manual line-breaking:

\documentclass[border = 3pt]{standalone}
\usepackage{booktabs,multirow, makecell}

\begin{document}

\begin{tabular}{p{3cm}ccc}
  \toprule
  \multirow[b]{2}{3cm}[-\dimexpr\aboverulesep + \belowrulesep + \cmidrulewidth]{Cat cat cat cat cat cat cat}
    & \multicolumn{3}{c}{Food} \\
  \cmidrule{2-4}%
    & A & B & C \\
  \midrule
  D & 123 & 456 & 789 \\\addlinespace
  E & 123 & 456 & 789 \\\addlinespace
  F & 123 & 456 & 789 \\
  \bottomrule
\end{tabular}
\qquad\renewcommand\cellalign{bl}
\begin{tabular}{lccc}
  \toprule\
  \ & \multicolumn{3}{c}{Food} \\
  \cmidrule{2-4}%
  \multirowcell{-2}{Cat cat cat cat \\ cat cat cat} & A&B&C\\
  \midrule
  D & 123 & 456 & 789 \\\addlinespace
  E & 123 & 456 & 789 \\\addlinespace
  F & 123 & 456 & 789 \\
  \bottomrule
\end{tabular}

\end{document} 

enter image description here

1
  • I accepted Zarko's answer, since it solved the specific problem. However, I really like the solution using ´makecell´, which I am actually using now due simplicity
    – Mace
    Commented Jul 30, 2017 at 17:35

You must log in to answer this question.

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