![表格超出列宽并与下一列的文本相冲突。如何强制压缩其宽度?](https://linux22.com/image/351861/%E8%A1%A8%E6%A0%BC%E8%B6%85%E5%87%BA%E5%88%97%E5%AE%BD%E5%B9%B6%E4%B8%8E%E4%B8%8B%E4%B8%80%E5%88%97%E7%9A%84%E6%96%87%E6%9C%AC%E7%9B%B8%E5%86%B2%E7%AA%81%E3%80%82%E5%A6%82%E4%BD%95%E5%BC%BA%E5%88%B6%E5%8E%8B%E7%BC%A9%E5%85%B6%E5%AE%BD%E5%BA%A6%EF%BC%9F.png)
我正在用 LaTex 编写一个包含 2 列的文档,其中我希望表格的宽度与列的宽度相同。我不太懂 LaTex,所以我使用在线编辑器创建表格的代码,它看起来几乎符合我的要求。代码如下:
\begin{table}[]
\caption{My caption}
\label{my-label}
\begin{tabular}{llllll}
\hline
Pre-processing & NV$^a$(LV$^b$) & \multicolumn{2}{l}{Calibration} & \multicolumn{2}{l}{Validation} \\ \cline{3-6}
& & RMSE & R$^2$ & RMSE & R$^2$ \\ \hline
$R(\lambda)$ & X(X) & X & X & X & X \\
$D^1(R(\lambda))$ & X(X) & X & X & X & X \\
$D^2(R(\lambda))$ & X(X) & X & X & X & X \\
$-log(R(\lambda))$ & X(X) & X & X & X & X \\
$-log(D^1(R(\lambda))$ & X(X) & X & X & X & X \\
$-log(D^2(R(\lambda))$ & X(X) & X & X & X & X \\
$D^1(-log(R(\lambda)))$ & X(X) & X & X & X & X \\
$D^2(-log(R(\lambda)))$ & X(X) & X & X & X & X \\
$MSC(R(\lambda))$ & X(X) & X & X & X & X \\
$MSC(D^1(R(\lambda)))$ & X(X) & X & X & X & X \\
$MSC(D^2(R(\lambda)))$ & X(X) & X & X & X & X \\
$MSC(-log(R(\lambda)))$ & X(X) & X & X & X & X \\
$MSC(D^1(-log(R(\lambda))))$ & X(X) & X & X & X & X \\
$MSC(-log(D^1(R(\lambda))))$ & X(X) & X & X & X & X \\
$MSC(D^2(-log(R(\lambda))))$ & X(X) & X & X & X & X \\
$MSC(-log(D^2(R(\lambda))))$ & X(X) & X & X & X & X \\
$SNV(R(\lambda))$ & X(X) & X & X & X & X \\
$SNV(D^1(R(\lambda)))$ & X(X) & X & X & X & X \\
$SNV(D^2(R(\lambda)))$ & X(X) & X & X & X & X \\
$SNV(-log(R(\lambda)))$ & X(X) & X & X & X & X \\
$SNV(D^1(-log(R(\lambda))))$ & X(X) & X & X & X & X \\
$SNV(-log(D^1(R(\lambda))))$ & X(X) & X & X & X & X \\
$SNV(D^2(-log(R(\lambda))))$ & X(X) & X & X & X & X \\
$SNV(-log(D^2(R(\lambda))))$ & X(X) & X & X & X & X \\
Multiple simultaneous & X(X) & X & X & X & X \\ \hline
\end{tabular}
\textit{$^a$Number of variables active in final variable selection,$^b$optimal number of latent variables in PLS regression model.}
\end{table}
主要问题是它太宽了。它不在列宽内,而是与右侧列中的文本相冲突。我怎样才能强制它调整表格中的空间以使其与列宽保持一致?
谢谢
答案1
我会做以下改变:
- 对于表格环境使用
tabularx
规定一列的宽度 - 减半
\tabcolsep
(3pt) - 减小字体大小至
\small
- 用于
multirow
第二列的标题 - 定义新命令以弥补不足
\multicolumn
- 第一列定义为数学环境
- 使用
booktabs
包中的规则 - 用于
threeparttable
表格注释
梅威瑟:
\documentclass[twocolumn]{article}
\usepackage{booktabs, multirow, tabularx, threeparttable}
\newcommand\mcc[1]{\multicolumn{2}{c}{#1}}
\usepackage{amsmath}
\usepackage{lipsum}% for dummy text
\begin{document}
\lipsum*[2]
\begin{table}[htb]
\begin{threeparttable}[htb]
\caption{My caption}
\label{my-label}
\small%footnotesize
\setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{@{}>{$}l<{$} >{\centering}X cc cc@{}}
\toprule
& \multirow{2}{=}{\centering
NV\tnote{a} \\
(LV\tnote{b})}
& \mcc{Calibration} & \mcc{Validation} \\
\cmidrule(lr){3-4}\cmidrule(lr){5-6}
\text{Pre-processing} & & RMSE & R$^2$ & RMSE & R$^2$\\
\midrule
R(\lambda) & X(X) & X & X & X & X \\
D^1(R(\lambda)) & X(X) & X & X & X & X \\
D^2(R(\lambda)) & X(X) & X & X & X & X \\
-log(R(\lambda)) & X(X) & X & X & X & X \\
-log(D^1(R(\lambda)) & X(X) & X & X & X & X \\
-log(D^2(R(\lambda)) & X(X) & X & X & X & X \\
D^1(-log(R(\lambda))) & X(X) & X & X & X & X \\
D^2(-log(R(\lambda))) & X(X) & X & X & X & X \\
MSC(R(\lambda)) & X(X) & X & X & X & X \\
MSC(D^1(R(\lambda))) & X(X) & X & X & X & X \\
MSC(D^2(R(\lambda))) & X(X) & X & X & X & X \\
MSC(-log(R(\lambda))) & X(X) & X & X & X & X \\
MSC(D^1(-log(R(\lambda)))) & X(X) & X & X & X & X \\
MSC(-log(D^1(R(\lambda)))) & X(X) & X & X & X & X \\
MSC(D^2(-log(R(\lambda)))) & X(X) & X & X & X & X \\
MSC(-log(D^2(R(\lambda)))) & X(X) & X & X & X & X \\
SNV(R(\lambda)) & X(X) & X & X & X & X \\
SNV(D^1(R(\lambda))) & X(X) & X & X & X & X \\
SNV(D^2(R(\lambda))) & X(X) & X & X & X & X \\
SNV(-log(R(\lambda))) & X(X) & X & X & X & X \\
SNV(D^1(-log(R(\lambda)))) & X(X) & X & X & X & X \\
SNV(-log(D^1(R(\lambda)))) & X(X) & X & X & X & X \\
SNV(D^2(-log(R(\lambda)))) & X(X) & X & X & X & X \\
SNV(-log(D^2(R(\lambda)))) & X(X) & X & X & X & X \\
\text{Multiple simultaneous}& X(X) & X & X & X & X \\
\bottomrule
\end{tabularx}
\begin{tablenotes}[para, flushleft]\itshape
\item[a] Number of variables active in final variable selection,
\item[b] optimal number of latent variables
in PLS regression model.
\end{tablenotes}
\end{threeparttable}
\end{table}
\lipsum
\end{document}
答案2
你可以使用调整框并调整表格大小以适合所需的宽度。
\documentclass[preview]{standalone}
\usepackage{adjustbox}
\begin{document}
\begin{table}[]
\caption{My caption}
\label{my-label}
\begin{adjustbox}{max width=\textwidth}
\begin{tabular}{llllll}
.....
\end{tabular}
\end{adjustbox}
\end{table}
\end{document}