这是代码。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{booktabs}
\usepackage{tabularx}
% define colors
%line space
\renewcommand{\baselinestretch}{1.2}
\begin{document}
\begin{table}[htbp]
\centering
\caption{plan}
\begin{tabular} {|m{3cm}<{\centering}|m{3cm}<{\centering}|}
\toprule
\textbf{University} & \textbf{Country} \\
\hline
University of London & United Kingdom \\
\bottomrule
\end{tabular}%
\label{tab:Secondment plan}%
\end{table}%
\end{document}
答案1
包中定义的规则booktabs
不适用于带有垂直线的表格。添加到规则中的间隙可以用表格包nicematrix
(如包作者在其评论中提到的)以及包来处理tabularray
:
\documentclass{article}
\usepackage[english]{babel}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\begin{table}[htbp]
\centering
\caption{plan}
\label{tab:Secondment plan}%
\begin{tblr}{vlines,
colspec = {*{2}{Q[c, m, 30mm]}},
row{1} = {font=\bfseries}
}
\toprule
University & Country \\
\hline
University of London & United Kingdom \\
\bottomrule
\end{tblr}
\end{table}
\end{document}
答案2
如果您确实想将垂直规则与 booktabs 的水平规则一起使用(这完全不符合 的精神booktabs
!),则可以使用nicematrix
。只需加载nicematrix
并替换{tabular}
为即可{NiceTabular}
。
\documentclass{article}
\usepackage[english]{babel}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{nicematrix}
% define colors
%line space
\renewcommand{\baselinestretch}{1.2}
\begin{document}
\begin{table}[htbp]
\centering
\caption{plan}
\begin{NiceTabular} {|m{3cm}<{\centering}|m{3cm}<{\centering}|}
\toprule
\textbf{University} & \textbf{Country} \\
\hline
University of London & United Kingdom \\
\bottomrule
\end{NiceTabular}%
\label{tab:Secondment plan}%
\end{table}%
\end{document}
您需要进行多次编译(因为nicematrix
在后台使用了 PGF/Tikz)。