LaTex中使用tabularx创建表格时边框无法闭合的问题求助
解决tabularx表格边框无法闭合且出现多余列的问题
嘿,我来帮你搞定这个tabularx的边框问题!你遇到的核心问题是固定宽度的p列总宽度和\textwidth不匹配,导致添加闭合边框时出现异常排版。下面给你具体的解决思路和修正后的代码:
问题根源分析
你当前的列格式是:
{|p{2.3cm}|p{3.5cm}|p{3.5cm}|p{3.5cm}}
- 末尾缺少
|导致表格右边框不闭合; - 直接添加
|后,固定列宽+边框宽度+列间距的总宽度超过了\textwidth,tabularx为了强制适配宽度会出现异常,看起来像多出了空白列。
两种可行解决方案
方案1:用tabularx的X列自动适配宽度(推荐)
tabularx的核心优势就是通过X列自动分配剩余宽度,不用手动计算列宽。把列格式改成下面这样,第一列固定宽度,剩下三列自动平分剩余空间,边框会完美闭合:
{|p{2.3cm}|X|X|X|}
方案2:手动调整p列宽度适配\textwidth
如果坚持用固定宽度的p列,需要精确计算列宽,让总宽度(列宽+边框宽度+列间距)刚好等于\textwidth。默认article类的\textwidth约为15.9cm,计算后把右侧三列的宽度调整为~3.95cm即可:
{|p{2.3cm}|p{3.95cm}|p{3.95cm}|p{3.95cm}|}
额外优化建议
- 移除多余的
\makeatother:你代码里没有用到\@开头的命令,这个命令是多余的,直接删掉即可; - 优化表格内的列表缩进:用
enumitem包替代paralist,可以更灵活地控制列表的缩进和间距,让表格内容更紧凑:\usepackage{enumitem} % 在表格内的列表使用: \begin{itemize}[leftmargin=*, topsep=0pt, partopsep=0pt, itemsep=0pt]
修正后的完整代码
\documentclass{article} \usepackage{tabularx} \usepackage{enumitem} % 替换paralist,更灵活控制列表 \begin{document} \begin{table}[!b] \centering \caption{Comparison between ST-Kriging, Bayesian inference, and ANNs.} \label{tab:2} \renewcommand{\arraystretch}{1.5} \scriptsize \begin{tabularx}{\textwidth} {|p{2.3cm}|X|X|X|} \hline \textbf{} & \textbf{Bayesian Inferences} & \textbf{ST-Kriging} & \textbf{ANNs} \\ \hline \textbf{Computational Complexity} & NP-hard \cite{ref-satria2020spatial} & $O(N^2)$ & $O(i\times o\times n + n\times o)$ or $O(n \times o \times (i+1))$ for training a single epoch. \cite{ref-taylor1995freeway} \\ \hline \textbf{Performance Evaluation } & Provides a posterior probability distribution with confidence interval. & Ensure linear unbiased predictors. & Epoch with the lowest sum of squared error.\\ \hline \textbf{Weaknesses} & Very computationally intensive due to choosing the proper prior distribution. & \begin{itemize}[leftmargin=*, topsep=0pt, partopsep=0pt, itemsep=0pt] \item Missing value causes error in unmatched dimensions. \item Can not handle large datasets. \item Require normal distribution. \end{itemize} & Require intensive data training, and this might lead to an overfitting problem. \\ \hline \textbf{Strengths } & \begin{itemize}[leftmargin=*, topsep=0pt, partopsep=0pt, itemsep=0pt] \item Handle large and small data. \item Handle missing values. \item Prior knowledge about uncertain input is not required. \end{itemize} & \begin{itemize}[leftmargin=*, topsep=0pt, partopsep=0pt, itemsep=0pt] \item Handle small data. \item Computational efficiency. \end{itemize} & \begin{itemize}[leftmargin=*, topsep=0pt, partopsep=0pt, itemsep=0pt] \item Handle big data and small data. \item Accommodate missing values without a separate estimation step [108] \item Computational efficiency due to the parallelity feature. \item Prior knowledge about uncertain input is not required. \end{itemize} \\ \hline \textbf{Overcoming the Limitation} & Use uninformative prior to reduce the computational time, however, it can affect the prediction accuracy negatively. & Remove observations that include missing values. & \begin{itemize}[leftmargin=*, topsep=0pt, partopsep=0pt, itemsep=0pt] \item Decrease the number of layers of the network. \item Use iterative methods to stop the training process such as gradient descent. \end{itemize} \\ \hline \end{tabularx} \end{table} \end{document}
内容的提问来源于stack exchange,提问作者Reta
相关产品推荐
相关产品推荐

