Tabularx 永无止境的行

Tabularx 永无止境的行

所以基本上我的表格在表格格式下工作得很好,但在某些情况下我需要使用 tabularx 因为它们太大而无法容纳在正常的文本宽度内。

然而,行变得无限长,似乎是由于一个错误的额外列?

编辑:将表格更改为我的实际表格。图 1 显示了使用 tabular 且不带 \noindent\makebox 的相同代码。如您所见,表格太宽,略微向右浮动,因此我尝试使用 tabularx 使其更宽,以便它可以在页面上居中。但是它会产生奇怪的无尽行。

图像: 在此处输入图片描述

在此处输入图片描述

在图像 1 中,表格比文本宽度宽,但至少它正确结束。因此,我尝试在下面的代码中使用 tabularx,结果得到图像 2:

代码:

\begin{table}[!h]
\label{table-A_3_posthoc}
\centering
\small
\caption[One-way ANOVA tests for scenarios 14, 16, 18 and 19-22]{One-way ANOVA tests showing the variation between sample means in three different internetwork topologies. Comparisons without a significant level (SL) were deemed statistically insignificantly different i.e. $p > 0.05$.\\}
\noindent\makebox[\textwidth]{%
\begin{tabularx}{1.5\textwidth}{l|r|r|r|r|r|r|r|r}
\toprule
One-way ANOVA & SL($\langle k \rangle$) & SL($\overline{C_E}$) & SL($D$) & SL($\ell$) & SL($G_E$) & SL($C_G$) & SL($\Phi$) & SL($\Gamma$)\\
\midrule
14 and 19 & 0.010 & & 0.010 & 0.001 & 0.001 & 0.001 & 0.001 & 0.001\\
16 and 20 & 0.001 & & 0.010 & 0.001 & 0.001 & 0.050 & & \\
18 and 21 & 0.001 & 0.050 & 0.050 & 0.001 & 0.001 & 0.001 & 0.010 & 0.010\\
\bottomrule
\end{tabularx}}
\end{table}

前言:

\usepackage{parskip}
\usepackage[margin=1.4in]{geometry}
\usepackage{amsmath,amssymb} % For using * for no eq. numbers
\usepackage{amsthm}
\usepackage[]{graphicx} % For inserting figures etc
\usepackage{booktabs} % For \toprule, \midrule and \bottomrule
\usepackage{url}
\usepackage{titlesec}
\usepackage{tabularx}
\usepackage{verbatim}
\usepackage[toc,page]{appendix}
\usepackage[nottoc,notlot,notlof]{tocbibind}
\usepackage{etoolbox}
\usepackage{adjustbox}
\usepackage{framed}
\usepackage{cite}
\usepackage{subfigure}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{algorithmicx}

答案1

如果要使用该tabularx环境,请确保至少有一个使用该X列类型的列。在下面的示例代码中,我建议X为 8 个数据列分配一个居中版本的列类型。

不需要\makebox“包装器”。考虑到文本块的宽度,也不需要\small字体大小指令。由于环境的宽度tabularx是(或至少应该是!)\textwidth\centering所以指令是多余的。并且,请删除不需要的竖线。

在此处输入图片描述

\documentclass{article}  
\usepackage{booktabs,tabularx}
% Define a centered version of the "X" column type:
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage[margin=1.4in]{geometry}
\begin{document}

\begin{table}
\label{table-A_3_posthoc}
\caption[One-way ANOVA tests for scenarios 14, 16, 18 and 19-22]{One-way 
  ANOVA tests showing the variation between sample means in three 
  different internetwork topologies. Comparisons without a significant 
  level (SL) were deemed statistically insignificantly different, i.e., 
  $p > 0.05$.}

\smallskip
\begin{tabularx}{1\textwidth}{@{} l *{8}{C} @{}}
\toprule
One-way ANOVA & SL($\langle k \rangle$) & SL($\overline{C_E}$) & SL($D$) 
  & SL($\ell$) & SL($G_E$) & SL($C_G$) & SL($\Phi$) & SL($\Gamma$)\\
\midrule
14 and 19 & 0.010 &       & 0.010 & 0.001 & 0.001 & 0.001 & 0.001 & 0.001\\
16 and 20 & 0.001 &       & 0.010 & 0.001 & 0.001 & 0.050 & & \\
18 and 21 & 0.001 & 0.050 & 0.050 & 0.001 & 0.001 & 0.001 & 0.010 & 0.010\\
\bottomrule
\end{tabularx}
\end{table}

\end{document}



\documentclass{article}  
\usepackage{booktabs,tabularx}
% define a centered version of the "X" column type:
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage[margin=1.4in]{geometry}
\begin{document}

\begin{table}[!h]
\label{table-A_3_posthoc}
\centering
\caption[One-way ANOVA tests for scenarios 14, 16, 18 and 19-22]{One-way ANOVA tests showing the variation between sample means in three different internetwork topologies. Comparisons without a significant level (SL) were deemed statistically insignificantly different, i.e., $p > 0.05$.}

\smallskip
\begin{tabularx}{1\textwidth}{@{} l *{7}{C} c @{}}
\toprule
One-way ANOVA & SL($\langle k \rangle$) & SL($\overline{C_E}$) & SL($D$) & SL($\ell$) & SL($G_E$) & SL($C_G$) & SL($\Phi$) & SL($\Gamma$)\\
\midrule
14 and 19 & 0.010 & & 0.010 & 0.001 & 0.001 & 0.001 & 0.001 & 0.001\\
16 and 20 & 0.001 & & 0.010 & 0.001 & 0.001 & 0.050 & & \\
18 and 21 & 0.001 & 0.050 & 0.050 & 0.001 & 0.001 & 0.001 & 0.010 & 0.010\\
\bottomrule
\end{tabularx}
\end{table}

\end{document}

答案2

在此处输入图片描述

\documentclass[a4paper]{article}

\usepackage{array,booktabs}

\newcommand\hd[1]{%
\begin{tabular}{@{}c@{}}#1\end{tabular}}

\begin{document}

\begin{table}[htp]%[!h]

\centering
\small
\caption[One-way ANOVA tests for scenarios 14, 16, 18 and 19-22]{One-way ANOVA tests showing the variation between sample means in three different internetwork topologies. Comparisons without a significant level (SL) were deemed statistically insignificantly different i.e. $p > 0.05$.%
%\\ never end a paragraph with \\
\label{table-A_3_posthoc}% never use \label before caption
}


\begin{tabular}{l|r|r|r|r|r|r|r|r}
\toprule
\hd{One-way\\ANOVA}&
\hd{SL\\($\langle k \rangle$)} &
\hd{SL\\($\overline{C_E}$)}&
\hd{SL\\($D$)}&
\hd{SL\\($\ell$)}&
\hd{SL\\($G_E$)}&
\hd{SL\\($C_G$)}&
\hd{SL\\($\Phi$)}&
\hd{SL\\($\Gamma$)}\\
\midrule
14 and 19 & 0.010 & & 0.010 & 0.001 & 0.001 & 0.001 & 0.001 & 0.001\\
16 and 20 & 0.001 & & 0.010 & 0.001 & 0.001 & 0.050 & & \\
18 and 21 & 0.001 & 0.050 & 0.050 & 0.001 & 0.001 & 0.001 & 0.010 & 0.010\\
\bottomrule
\end{tabular}
\end{table}

\end{document}

答案3

表格环境tabularx不打算将表格设置为比文本宽度更宽!正确使用列类型(它应该基于X列类型)可以确定列本身,并且单元格中的较长文本会分成更多行。因此,切勿像您那样仅使用表格列类型(lcrp{...}tabularx

如果您希望某个地方的表格宽度大于文本宽度(但不能像您的情况那样大于页面宽度):

在此处输入图片描述

然后您需要在本地适当地更改表格的文本宽度。这可以通过不同的方式完成,其中之一(除了您使用的方法之外)例如使用包changepage

\documentclass[11pt,a4paper]{article}
\usepackage[margin=1.4in,showframe]{geometry}

\usepackage{booktabs,tabularx}

\usepackage{changepage}

\begin{document}
\begin{adjustwidth}{-1in}{-1in}
\begin{tabularx}{\linewidth}{|>{\raggedleft\arraybackslash}X|>{\centering\arraybackslash}X|}
    \hline
Hello & Right\\
    \hline
Yes & No\\
    \hline
\end{tabularx}
\end{adjustwidth}
\end{document}

在此处输入图片描述

附录: 同时问题发生了变化,从现在可以看出,表格实际上完全适合\textwidth...如果您出于某种原因仍然坚持tabularx,您可以重写您的表格,如下所示:

在此处输入图片描述

\documentclass[11pt,a4paper]{article}
\usepackage[margin=1.4in,showframe]{geometry}

\usepackage{booktabs,tabularx}

\usepackage{siunitx}

\begin{document}

\begin{table}[!h]
\label{table-A_3_posthoc}
\small
\caption[One-way ANOVA tests for scenarios 14, 16, 18 and 19-22]{One-way ANOVA tests showing the variation between sample means in three different internetwork topologies. Comparisons without a significant level (SL) were deemed statistically insignificantly different i.e. $p > 0.05$.\\}

\begin{tabularx}{\linewidth}{>{\centering\arraybackslash}X|
                             *{8}{S[table-format=1.3]}
                             }%r|r|r|r|r|r|r|r}
\toprule
One-way ANOVA & {SL($\langle k \rangle$)} & {SL($\overline{C_E}$)} & {SL($D$)} & {SL($\ell$)} & {SL($G_E$)} & {SL($C_G$)} & {SL($\Phi$)} & {SL($\Gamma$)}\\
\midrule
14 and 19 & 0.010 & & 0.010 & 0.001 & 0.001 & 0.001 & 0.001 & 0.001\\
16 and 20 & 0.001 & & 0.010 & 0.001 & 0.001 & 0.050 & & \\
18 and 21 & 0.001 & 0.050 & 0.050 & 0.001 & 0.001 & 0.001 & 0.010 & 0.010\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}

相关内容