![当我将宽度从 .7\textwidth 增加到 .8\textwidth 时,嵌套的 tabularx 会中断](https://linux22.com/image/353656/%E5%BD%93%E6%88%91%E5%B0%86%E5%AE%BD%E5%BA%A6%E4%BB%8E%20.7%5Ctextwidth%20%E5%A2%9E%E5%8A%A0%E5%88%B0%20.8%5Ctextwidth%20%E6%97%B6%EF%BC%8C%E5%B5%8C%E5%A5%97%E7%9A%84%20tabularx%20%E4%BC%9A%E4%B8%AD%E6%96%AD.png)
我正在尝试创建一个具有三个级别的嵌套表格。当我将最外层表格的宽度设置为小于 .7\textwidth 时,它看起来就像我想要的那样。但是,我想将其放大,以便它占据整个页面。当我将其更改为 \textwidth 甚至 .8\textwidth 或 .9\textwidth 时,似乎列变得非常窄。我不太清楚发生了什么!
\documentclass[a4paper,12pt, margin = .5]{article}
\usepackage{tabularx}
\newcolumntype{Y}{>{\small\raggedright\arraybackslash}X}
\newcolumntype{A}{>{\hsize=.80\hsize}Y}
\newcolumntype{Z}{>{\hsize=.35\hsize}Y}
\begin{document}
\renewcommand{\baselinestretch}{1.15}
\renewcommand{\baselinestretch}{1.15}
\begin{table}
\begin{tabularx}{.72\textwidth}{|Z|Y|}
\hline
\textbf{Analysis} & \textbf{Factors} \\
\hline
& \\
\textbf{Gender Generic Referents}
& {\begin{tabularx}{.5\textwidth}{|A|Y|Y|}
\cline{1-3}
& \textbf{Binary} & \textbf{Non-binary}\\ \cline{1-3}
\textbf{Ambig} & she-he & she-he\\ \cline{1-3}
\textbf{Unambig} & incongruent-congruent & incongruent-congruent\\ \cline{1-3}
\end{tabularx}} \\
& \\
\hline
& \\
\textbf{Gender Specific Referents}
& {\begin{tabularx}{.5\textwidth}{|A|Y|Y|}
\cline{1-3}
& \textbf{Binary} & \textbf{Non-binary}\\ \cline{1-3}
\textbf{Ambig} & she-he & she-he\\ \cline{1-3}
\textbf{Unambig} & incongruent-congruent & incongruent-congruent\\ \cline{1-3}
\end{tabularx}} \\
& \\
\hline
& \\
\textbf{Number Specific Referents}
& {\begin{tabularx}{\linewidth}{|A|Y|Y|}
\cline{1-3}
& \textbf{Binary} & \textbf{Non-binary}\\ \cline{1-3}
\textbf{Ambig}
& &\\
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}}
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}} \\
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}}
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}}\\ \cline{1-3}
\textbf{Unambig}
& &\\
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}}
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}} \\
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}}
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}}\\ \cline{1-3}
\end{tabularx}} \\
& \\
\hline
& \\
\textbf{Number Generic Referents}
& {\begin{tabularx}{\linewidth}{|A|Y|Y|}
\cline{1-3}
& \textbf{Binary} & \textbf{Non-binary}\\ \cline{1-3}
\textbf{Ambig}
& &\\
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}}
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}} \\
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}}
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}}\\ \cline{1-3}
\textbf{Unambig}
& &\\
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}}
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}} \\
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}}
& {\begin{tabularx}{\linewidth}{|Y|Y|}
\cline{1-2}
Sing & Plur \\ \cline{1-2}
\end{tabularx}}\\ \cline{1-3}
\end{tabularx}} \\
& \\
\hline
\end{tabularx}
\caption{Analysis Summary (Construal 1)}
\end{table}
\end{document}
答案1
用法tabularx
有两个错误。主要错误是
\newcolumntype{Y}{>{\small\raggedright\arraybackslash}X}
\newcolumntype{Z}{>{\hsize=.35\hsize}Y}
\begin{tabularx}{.72\textwidth}{|Z|Y|}
完全破坏了tabularx
列宽计算,因为tabularx
将计算实现总宽度 .72\textwidth 所需的列宽,但是随后您调整其中一列并使其宽度仅为计算宽度的 35%,因此算法将永远无法达到指定的总宽度。
然后第二个错误与嵌套表格有关。外部表格tabularx
(即使已修复以解决上述问题)正在动态计算列宽,但实际列内容 \begin{tabularx}{.5\textwidth}
始终是页面宽度的一半,无论外部表格列的计算宽度是多少。
tabularx
是关于调整列内换行的指定宽度,这里几乎没有换行,您可以更简单地使用。有些人建议使用较少的垂直和水平规则,但在这里我主要保留了它们,只显示使用而不是 的tabular
结果。tabular
tabularx
\documentclass[a4paper,12pt]{article}%margin = .5
\usepackage{array}
\newcolumntype{P}{>{\raggedright\arraybackslash
\renewcommand\arraystretch{1}}m{2.45cm}}
\begin{document}
\renewcommand{\baselinestretch}{1.15}
\begin{table}
\centering
\setlength\tabcolsep{4pt}
\begin{tabular}{@{}|l|l|@{}}
\hline
\textbf{Analysis} & \textbf{Factors} \\
\hline
\textbf{Gender Generic Referents}
&
\renewcommand\arraystretch{1.7}
\begin{tabular}{@{}l|P|P@{}}
& \textbf{Binary} & \textbf{Non-binary}\\ \hline
\textbf{Ambig} & she-he & she-he\\ \hline
\textbf{Unambig} & incongruent-congruent & incongruent-congruent\\
\end{tabular} \\
\hline
\textbf{Gender Specific Referents}
&
\renewcommand\arraystretch{1.7}
\begin{tabular}{@{}l|P|P@{}}
& \textbf{Binary} & \textbf{Non-binary}\\ \hline
\textbf{Ambig} & she-he & she-he\\ \hline
\textbf{Unambig} & incongruent-congruent & incongruent-congruent\\
\end{tabular} \\
\hline
\textbf{Number Specific Referents}
& \renewcommand\arraystretch{1.7}
\begin{tabular}{@{}l|P|P@{}}
& \textbf{Binary} & \textbf{Non-binary}\\ \hline
\textbf{Ambig}
& \begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}
\begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}
&\begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}
\begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}\\\hline
\textbf{Unambig}
& \begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}
\begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}
&
\begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}
\begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}
\end{tabular} \\
\hline
\textbf{Number Generic Referents}
& \renewcommand\arraystretch{1.7}
\begin{tabular}{@{}l|P|P@{}}
& \textbf{Binary} & \textbf{Non-binary}\\ \hline
\textbf{Ambig}
&
\begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}
\begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular} &
\begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}
\begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}\\
\hline
\textbf{Unambig}
& \begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}
\begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}
&\begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}
\begin{tabular}{|l|l|}
\hline
Sing & Plur \\\hline
\end{tabular}
\end{tabular} \\
\hline
\end{tabular}
\caption{Analysis Summary (Construal 1)}
\end{table}
\end{document}