tabularx 和 multirow:奇怪的行為

tabularx 和 multirow:奇怪的行為

微量元素

\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輸出

在此輸入影像描述

問題

  • 我有一個表,我在其中使用tabularxmultirow
  • 當我在 MWE 中添加紅色文字時,其中一列發生了變化X
  • 我不明白發生了什麼事。

更新

經過評論中的聊天,我認為這可能是更好的問題:

我可以使用帶有自動換行符multirow的 andmulticolumn而無需明確指定寬度(此處為 120mm)嗎?

「真實」表

這是「真實」的表。

在此輸入影像描述

答案1

您想要使用 Y 列作為跨越條目

在此輸入影像描述

\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}{>{\hsize=\dimexpr3\hsize+4\tabcolsep+2\arrayrulewidth\relax}Y}
{\multirow{2}{=}{\centering Text 
text text text text text text text text text text
text text text text text text text text text text
text text text text text text text text text 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}

相關內容