MWE
\documentclass[12pt]{article}
\usepackage[
a4paper,
left = 5mm,
right = 5mm,
landscape,
%showframe,
]
{geometry}
\usepackage{tabularx}
\usepackage{multirow}
% Thicker table lines for screenshot
\setlength{\arrayrulewidth}{1.5pt}
\setlength{\parindent}{0pt}
\usepackage[table]{xcolor}
\definecolor{myTableColor}{gray}{0.80}
% Nice sf font for screenshot
\usepackage[sfdefault]{cabin}
% https://tex.stackexchange.com/questions/163061
% https://tex.stackexchange.com/questions/89166
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
\section*{Red Text Causes Strange Column}
\begin{tabularx}{\textwidth}{lc|l|Y|Y|Y|Y}
& & & \multicolumn{3}{c}{\multirow{2}{*}{\parbox{130mm}{\centering Text}}} & \\
% New Row
& & & \multicolumn{3}{l}{} & \\
% New Row
Text & Text & & & & & \\ \hline
% New Row
\rowcolor{myTableColor}
Text & Text & & & & \textcolor{red}{Problem Column} & \\ \hline
% New Row
Text Text Text Text \textcolor{red}{Text} & Text & Text Text Text Text Text \textcolor{red}{Text} & & & & \\ \hline
% New Row
Text & Text & & & & & \\ \hline
\end{tabularx}
\section*{Red Text Removed}
\begin{tabularx}{\textwidth}{lc|l|Y|Y|Y|Y}
& & & \multicolumn{3}{c}{\multirow{2}{*}{\parbox{130mm}{\centering Text}}} & \\
% New Row
& & & \multicolumn{3}{l}{} & \\
% New Row
Text & Text & & & & & \\ \hline
% New Row
\rowcolor{myTableColor}
Text & Text & & & & \textcolor{blue}{No Problem Column} & \\ \hline
% New Row
Text Text Text Text & Text & Text Text Text Text Text & & & & \\ \hline
% New Row
Text & Text & & & & & \\ \hline
\end{tabularx}
\end{document}
MWE Output
Problem
- I have a table in which I use
tabularx
andmultirow
. - When I add the red text in the MWE then I get a shift in one of the
X
columns. - I don't understand what happens.
Update
After the chat in the comments, I think that this may be the better question:
Can I use a
multirow
andmulticolumn
with automatic line break without having to specify the width explicitly (here 120mm)?
"Real" Table
This is the "real" table.
\parbox
inmultirow
cell is wider than sum of column width below ofmulticol
cell in which you havemultirow
. If you will reduce its width from 130 mm to 90 mmm (as example), your problem will disappear. Or I misunderstanding your problem?X
columns have all the same width. I am confused that it affects only one column. Question: Can I use amultirow
with automatic line break without having to specify the width explicitly (here120mm
)? And thanks for the comment.p
column with a fixed width that is wider than the natural width of the columns being spanned, in such a case the tex\halign
primitive always adds the excess width to the last spanned column.