TeX - LaTeX Asked by trynthink on August 3, 2020
I have tables where I am trying to use two features together:
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]{>{centeringarraybackslash}m{#1}}
begin{document}
Table 1
begin{tabular}{|c|c|c|}
hline
Column A & Column B & Column C
hline
multirowcell{4}{Some SomewhatLengthy Textin a multirowcell} & Table Text & lorem ipsum dolor sit amet consectetur
cline{2-3}
& multirowcell{2}{A multirowcellMore 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 SomewhatLengthy Textin a multirowcell} & Table Text & lorem ipsum dolor sit amet consectetur
cline{2-3}
& multirowcell{2}{A multirowcellMore 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}
multirow
is designed for on-line cells, so you have to count the total number of lines, not of rows. In addition, adding vertical padding of cells may change the equivalent number of lines. Also, you can adjust the number of equivalent rows using a decimal number.
Here is a code for this case:
begin{tabular}{|c|c|C{1.2in}|}
hline
Column A & Column B & Column C
hline
multirowcell{7}{Some SomewhatLengthy Textin a multirowcell} & Table Text & lorem ipsum dolor sit amet consectetur
cline{2-3}
& multirowcell{2}{A multirowcellMore 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}
Answered by Bernard on August 3, 2020
Here is what you can do with {NiceTabular}
of nicematrix
.
documentclass{article}
usepackage{makecell}
usepackage{nicematrix}
usepackage{array}
newcolumntype{C}[1]{>{centeringarraybackslash}m{#1}}
begin{document}
NiceMatrixOptions{cell-space-top-limit=1mm,cell-space-bottom-limit=1mm}
begin{NiceTabular}{wc{1in}wc{1in}C{1.2in}}[hvlines]
Column A & Column B & Column C
Block{4-1}{makecell{Some SomewhatLengthy Text in a multirowcell}} & Table Text & lorem ipsum dolor sit amet consectetur
& Block{2-1}{makecell{A multirowcellMore text}} & adipiscing elit sed do elusmod tempur
& & incididunt ut labore et dolore magna aliqua
& Something & Whatever
end{NiceTabular}
end{document}
In {NiceTabular}
, you have a command Block
for merged cells. You specifiy the number of rows and the number of columns.
However, the command Block
don't create space and that's why I have specified the width of the first and the second column.
The key hvlines
draws all the rules excepted in the blocks.
Answered by F. Pantigny on August 3, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP