I need to create a table in LaTeX that looks exactly like its counterpart in a Word document.
For this, I need a table that can span multiple pages with repeating headers (longtable
, etc.) and contains merged cells with horizontally and vertically centered content (multirow
, makecell
, etc.). Some of the content needs to be rotated/vertical.
Currently, I'm struggling with overflowing content in a multirow
environment. I have tried to find a solution for over a day now:
\documentclass{article}
\usepackage{xltabular}
\usepackage{array}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{graphicx}
\begin{document}
\begin{xltabular}{\textwidth}{|X|X|}
\hline
\thead{Two \\ lines} & \thead{One vertically centered line} \\
\hline
\multirowcell{2}{\rotatebox{90}{LONG CENTERED STRING }} & \makecell{Something} \\
\cline{2-2}
& \makecell{Something} \\
\hline
\end{xltabular}
\end{document}
How can I make the table adjust all the row heights based on the highest row? That is, how can I make the table adjust the height of the two "Something" rows so that they're equal in height to the "LONG CENTERED STRING" multirow cell?
(I'd prefer a non-cheating, dynamic solution as the content of the table is also somewhat dynamically generated. Hence, adjusting row heights manually or inserting fake rows is not ideal.)
\multirow
withlongtable
/xltabular
, especially when it comes to your long and rotated texts, is somewhat risky as a page break might occur at a subpar place in your table resulting in the contents of the\multirow
protruding into the footer of the page.xltabular
in a non-breakabletable
environment does not really make sense. Remove thetable
environment.table
environment. Regarding your concern: Yes, in some cases having a table that spans multiple pages will result in weird effects with such a table layout. However, I'm willing to accept this as the document will be reviewed by a human who can then tweak the document manually before sending it out to a customer.\multirow
cells can not be higher than height of spanned adjacent cells (actually lines). If it is declared such, it contents spill out of bottom of cells. I see two possible solutions: (i) increase heights of adjacent cells, or (ii) break text inmultirow
cells in multiline text.