增加表格第一行的间距后缩短过长的垂直线

增加表格第一行的间距后缩短过长的垂直线

我正在设计一张桌子。为了增加第一行的间距,我应用了以下解决方案表格第一行的间距\vrule depth 2ex height 4ex width 0pt,即在第一行之后添加。

\documentclass{article}
\usepackage{threeparttable}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}

\begin{document}

\setlength{\LTleft}{1pt}
\begin{table}[htbp!]
\renewcommand{\arraystretch}{1.1}
\begin{tabular}{ll|c}
\textbf{Country} & \multicolumn{1}{l}{\textbf{GDP p.c.}} & \textbf{Purchasing Power Parity GDP p.c.}\vrule depth 2ex height 4ex width 0pt \\
Luxembourg  & 127,673 & 141,587 \\ 
Denmark     &  65,713 &  69,845 \\ 
China       &  12,970 &  21,291 \\
India       &  2,466  &   8,293 \\
\end{tabular}
\caption*{List of countries by GDP per capita \& Purchasing Power Parity GDP p.c., 2022}
\end{table}
\end{document}

解决方案效果很好,但是在我在第二列旁边添加了一条垂直线之后,垂直线延伸到了第一行的上边界。

在此处输入图片描述

如何缩短该线(或应用其他修复)以使整个表格看起来不错?

可选/相关问题我很难指定垂直线的粗细。如何设置/增加其粗细,如屏幕截图所示?

答案1

将 更改\vrule depth 2ex height 4ex width 0pt为 例如\vrule depth 2ex height 2ex width 0pt。如果您想要表格上方的额外垂直空间,您可以添加\vspace{2pt}。厚度为:\setlength{\arrayrulewidth}{4pt}

\documentclass{article}
\usepackage{threeparttable}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}

\begin{document}

\setlength{\LTleft}{1pt}
\begin{table}[htbp!]
\setlength{\arrayrulewidth}{4pt}
\renewcommand{\arraystretch}{1.1}
\begin{tabular}{ll|c}
\textbf{Country} & \multicolumn{1}{l|}{\textbf{GDP p.c.}} & \textbf{Purchasing Power Parity GDP p.c.}\vrule depth 2ex height 2ex width 0pt \\
Luxembourg  & 127,673 & 141,587 \\ 
Denmark     &  65,713 &  69,845 \\ 
China       &  12,970 &  21,291 \\
India       &  2,466  &   8,293 \\
\end{tabular}
\caption*{List of countries by GDP per capita \& Purchasing Power Parity GDP p.c., 2022}
\end{table}
\end{document}

在此处输入图片描述

答案2

使用该tabularray包,解决方案很简单:

\documentclass{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{caption}     
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document}
    \begin{table}[htbp!]
\begin{tblr}{colspec = {Q[l, m] Q[c, m, si={table-format=3.3}] Q[c, m, si={table-format=3.3}]},
             rowsep  = 0.5pt,
             row{1}  = {guard, font=\bfseries, 
                        belowsep=4pt},  % set vertical distance between first and second row
             vline{3}= {2pt}    % set desired rule width, for default width write "{solid}" instead
             }
Country     & GDP p.c.  & Purchasing Power Parity GDP p.c. \\
Luxembourg  & 127,673   & 141,587 \\
Denmark     &  65,713   &  69,845 \\
China       &  12,970   &  21,291 \\
India       &  2,466    &   8,293 \\
\end{tblr}
\caption*{List of countries by GDP per capita \& Purchasing Power Parity GDP p.c., 2022}
    \end{table}
    
    \begin{table}[htbp!]
\begin{tblr}{colspec = {Q[l, m] Q[c, m, si={table-format=3.3}] Q[c, m, si={table-format=3.3}]},
             rowsep  = 0.5pt,
             row{1}  = {guard, font=\bfseries, belowsep=4pt},
             vline{3}= {2pt} 
             }
Country     & GDP p.c.  & {Purchasing Power\\ Parity GDP p.c.}  \\
Luxembourg  & 127,673   & 141,587 \\
Denmark     &  65,713   &  69,845 \\
China       &  12,970   &  21,291 \\
India       &  2,466    &   8,293 \\
\end{tblr}
\caption*{List of countries by GDP per capita \& Purchasing Power Parity GDP p.c., 2022}
    \end{table}

\end{document}

在此处输入图片描述

(红线表示页面边框上的文本框)

相关内容