I have tables where I am trying to use two features together:
- multirowcell (from the makecell package) for cells that span multiple rows with new lines inserted into the text in specific locations, and
- specifying a fixed width for one or more other columns where I want the text to wrap (and to better control the overall table width).
When using these features together, I would like the text in the multirowcells to be vertically centered.
When using default table column types, makecell will vertically center the multirowcell text automatically. Table 1 in the MWE illustrates this behavior.
If a column type that allows for specifying the width of a column is used, even for a column in the table that does not use multirowcell, Table 2 in the MWE shows that makecell won't successfully vertically center the text in the multirowcells. In this example I've used a custom column type, but the same problem occurs when using, e.g., p{}
.
Is there a way to help makecell vertically center the text when another column in the table has a specified width that causes the text in that column to wrap?
I tried using \Gape[][]{}
, but even a large negative value for the depth correction will not vertically center the text. Inserting a \vspace{}
above the text in the affected cells does work, but it requires guess-and-check approximation of the correct adjustment length for each affected cell. A solution that doesn't require specifying absolute length corrections would be ideal since I have several tables with different configurations that are affected.
\documentclass{article}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
Table 1
\begin{tabular}{|c|c|c|}
\hline
Column A & Column B & Column C \\
\hline
\multirowcell{4}{Some Somewhat\\Lengthy Text\\in a multirowcell} & Table Text & lorem ipsum dolor sit amet consectetur \\
\cline{2-3}
& \multirowcell{2}{A multirowcell\\More text} & adipiscing elit sed do elusmod tempur \\
\cline{3-3}
& & incididunt ut labore et dolore magna aliqua \\
\cline{2-3}
& Something & Whatever \\
\hline
\end{tabular}
Table 2
\begin{tabular}{|c|c|C{1.2in}|}
\hline
Column A & Column B & Column C \\
\hline
\multirowcell{4}{Some Somewhat\\Lengthy Text\\in a multirowcell} & Table Text & lorem ipsum dolor sit amet consectetur \\
\cline{2-3}
& \multirowcell{2}{A multirowcell\\More text} & adipiscing elit sed do elusmod tempur \\
\cline{3-3}
& & incididunt ut labore et dolore magna aliqua \\
\cline{2-3}
& Something & Whatever \\
\hline
\end{tabular}
\end{document}