![表格中有两列比其他列拉伸得更多](https://linux22.com/image/358429/%E8%A1%A8%E6%A0%BC%E4%B8%AD%E6%9C%89%E4%B8%A4%E5%88%97%E6%AF%94%E5%85%B6%E4%BB%96%E5%88%97%E6%8B%89%E4%BC%B8%E5%BE%97%E6%9B%B4%E5%A4%9A.png)
一年前,我根据一个示例制作了一个适合我需要的表格。当表格在日记模板中时,它显示没有错误。现在我将其移到另一个模板,它超出了页面限制。所以我添加了调整框,但发生了另一件事,两列(图片中的 S4)比其他列更拉伸。有办法解决这个问题吗?
\begin{table}
\centering
\setlength\tabcolsep{2pt}
\caption{Mapping Precision of MedK} \label{tab:t3}
\begin{adjustbox}{max width=\textwidth}
\begin{tabular}{ | l | l | l | l | l | l | l | l | l | l | c | l | l | l | c | l | }
\hline
\multirow{2}{*}{Keyword} & \multirow{2}{*}{\begin{tabular}[c]{@{}l@{}}Results Requested\\per source\end{tabular}} & \multicolumn{5}{c|}{Results available} & \multicolumn{4}{c|}{Properties retrieved}& \multicolumn{4}{c|}{\begin{tabular}[c]{@{}c@{}}Properties matched\\with \end{tabular}} & \multirow{2}{*}{\begin{tabular}[c]{@{}c@{}}Overall\\Precision\end{tabular}} \\[1ex] \cline{3-15}
& & S1 & S2 & S3 & S4 & overall & S1 & S2 & S3 & S4 & S1 & S2 & S3 & S4 & \\ \hline
& & & & & & & & & & & & & & & \\ \hline
& & & & & & & & & & & & & & & \\ \hline
& & & & & & & & & & & & & & & \\ \hline
& & & & & & & & & & & & & & & \\ \hline
\end{tabular}
\end{adjustbox}
\end{table}
答案1
\multicolumn
如果最后一列比它跨越的列宽,则将所有宽度添加到最后一列。只需\makebox[3em]{}
在每列中放入一个单元格即可强制设置最小宽度(将 3em 替换为所需的任何值)。只有在万不得已的情况下才将诸如调整框之类的缩放应用于表格,即使这样也不要这样做。
但在这里我认为如果你选择较小的字体,并且换行你的标题,那么你不应该有过大的多列,例如:
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}
\centering
\small
\setlength\tabcolsep{1.7pt}
\caption{Mapping Precision of MedK} \label{tab:t3}
\begin{tabular}{@{}| l | l | l | l | l | l | l | l | l | l | c | l | l | l | c | l |@{}}
\hline
\multirow{2}{*}{Keyword} &
\multirow{2}{*}{\begin{tabular}[c]{@{}l@{}}Results Requested\\per source\end{tabular}} &
\multicolumn{5}{c|}{\begin{tabular}[c]{@{}c@{}}Results\\available\end{tabular}}&
\multicolumn{4}{c|}{\begin{tabular}[c]{@{}c@{}}Properties\\retrieved\end{tabular}}&
\multicolumn{4}{c|}{\begin{tabular}[c]{@{}c@{}}Properties\\matched\\with \end{tabular}} &
\multirow{2}{*}{\begin{tabular}[c]{@{}c@{}}Overall\\Precision\end{tabular}} \\[1ex] \cline{3-15}
& & S1 & S2 & S3 & S4 & overall & S1 & S2 & S3 & S4 & S1 & S2 & S3 & S4 & \\ \hline
& & & & & & & & & & & & & & & \\ \hline
& & & & & & & & & & & & & & & \\ \hline
& & & & & & & & & & & & & & & \\ \hline
& & & & & & & & & & & & & & & \\ \hline
\end{tabular}
\end{table}
\end{document}
答案2
正如已经解释过的,多余的宽度放在最后一列。
在这里,我提出了一种不同的表格排版方式,没有垂直线,而是使用 LaTeX 来计算列间空间。
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}
\centering
\setlength\tabcolsep{0pt}
\small
\caption{Mapping Precision of MedK} \label{tab:t3}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l l l l l l l l l l c l l l c l @{}}
\toprule
Keyword &
\multicolumn{6}{c}{Results} &
\multicolumn{8}{c}{Properties} &
\multicolumn{1}{c@{}}{\smash{\begin{tabular}[t]{@{}c@{}}Overall\\precision\end{tabular}}}
\\
\cmidrule{2-7}\cmidrule{8-15}
&
\multicolumn{1}{c}{requested} &
\multicolumn{5}{c}{available} &
\multicolumn{4}{c}{retrieved} &
\multicolumn{4}{c}{matched} &
\multicolumn{1}{c}{}
\\
&
\multicolumn{1}{c}{per source} &
\multicolumn{5}{c}{} &
\multicolumn{4}{c}{} &
\multicolumn{4}{c}{with} &
\multicolumn{1}{c}{}
\\
\cmidrule{2-2}\cmidrule{3-7}\cmidrule{8-11}\cmidrule{12-15}
& & S1 & S2 & S3 & S4 & overall & S1 & S2 & S3 & S4 & S1 & S2 & S3 & S4 & \\
\midrule
& & & & & & & & & & & & & & & \\
& & & & & & & & & & & & & & & \\
& & & & & & & & & & & & & & & \\
& & & & & & & & & & & & & & & \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}