我是 LaTeX 新手,正在尝试创建表格。我已阅读 Wikibooks 中有关表格的所有文档。我遇到的问题是使用 \cline 时我的列间距不均匀。
我有以下代码:
%begin table 1
\begin{table*}
\centering
\caption{Description of datasets of proficiency test results from AAFCO check sample program}
\setlength{\abovecaptionskip}{10pt}
\setlength{\belowcaptionskip}{-12pt}
\setlength\extrarowheight{4pt} % sets row height
\setlength{\tabcolsep}{15pt} % sets column space
%\renewcommand{\arraystretch}{1}
\vspace{6pt}
\scalebox{1.0}{
\begin{tabular}{ | c | c | c | c | c | }
\hline
\multirow{2}{*}{Year} & \multirow{2}{*}{Feed Type} & \multicolumn{2}{ c| }{\# of laboratories
submitting the PT results} & \multirow{2}{*}{\# of analyses} \\ \cline{3-4}
& & Min & Max & \\
\hline
test & test & test & test & test \\
\hline
\end{tabular}
\label{tab:tab1}
}
\end{table*}
%end table 1
我尝试过的一个补救措施是使用 \multirow{1}{2.5cm}{Min},但我的文本没有对齐。图片如下
我正在尝试重新创建此表。如能得到任何帮助我将不胜感激。谢谢。
答案1
一个与列类型相关的解决方案wc
。我删除了该\scalebox
命令,因为它不应该用于表格,因为它会导致字体大小不一致。
\documentclass{article}
\usepackage{graphicx}
\usepackage{array, multirow}
\usepackage{makecell}
\begin{document}
\begin{table*}
\centering
\caption{Description of datasets of proficiency test results from AAFCO check sample program}
\setlength{\abovecaptionskip}{10pt}
\setlength{\belowcaptionskip}{-12pt}
\setlength\extrarowheight{4pt} % sets row height
\setlength{\tabcolsep}{15pt} % sets column space
\vspace{6pt}
\begin{tabular}{ | c | c | wc{15mm} | wc{15mm} | c | }
\hline
\multirow{2}{*}{Year} & \multirow{2}{*}{Feed Type} & \multicolumn{2}{ c| }{\makecell{\# of laboratories\\
submitting the PT results}} & \multirow{2}{*}{\# of analyses} \\ \cline{3-4}
& & Min & Max & \\
\hline
test & test & test & test & test \\
\hline
\end{tabular}
\label{tab:tab1}
\end{table*}
\end{document}
答案2
这是一个解决方案,(a)使用tabularx
环境并允许在第二列自动换行(带有悬挂缩进)和(b)对第 3、4 和 5 列使用固定相等的宽度。它还消除了所有垂直线,并使用少量但间距适当的水平线。
\documentclass{article}
\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{array} % for 'w' and 'm' column types
\usepackage{tabularx,ragged2e}
\newcolumntype{L}{>{\RaggedRight\hangafter=1\hangindent=1em}X}
\usepackage{calc}
\usepackage[skip=0.5\baselineskip]{caption}
\begin{document}
\begin{table*}
\caption{Description of datasets of proficiency test results
from AAFCO check sample program}
\label{tab:tab1}
\newlength\mylen
\settowidth\mylen{\# of analyses} % measure widths of cols 2 thru 5
\begin{tabularx}{\textwidth}{@{} l L *{3}{wc{\mylen}} @{}}
\toprule
Year
& Feed Type
& \multicolumn{2}{ >{\centering}m{2\mylen+2\tabcolsep} }{%
\# of laboratories submitting the PT results}
& \# of analyses \\
\cmidrule(lr){3-4}
& & min & max & \\
\midrule
2022
& Beet pulp & 5 & 55 & 45 \\
& Calf starter\slash grower, medicated & 6 & 209 & 58 \\
& \dots \\
& Ewe developer \& gestation feed, medicated & 10 & 214 & 35 \\
& \dots \\
& Pelleted sheep concentrate, medicated & 7 & 212 & 54 \\
& \dots \\
& Swine grower, medicated & 5 & 155 & 55 \\
\bottomrule
\end{tabularx}
\end{table*}
\end{document}