1

I'm designing a table. In order to increase the first row's spacing I've applied the solution at Spacing for first row in a table, i.e. add \vrule depth 2ex height 4ex width 0pt after the 1st row.

\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}

The solution worked fine but after I've added a vertical line next to the 2nd column, the vertical line extended over the first row's upper boundary.

enter image description here

How to shorten that line (or apply some other fix) so that the table looks decent as a whole?

Optional / Relevant Question I have a hard time specifying the thickness of the vertical line. How to set/increase its thickness, as shown in the screenshot?

  • 2
    Change the \vrule depth 2ex height 4ex width 0pt to e.g. \vrule depth 2ex height 2ex width 0pt. If you want the extra vertical space above the tabular you can add \vspace{2pt}. For the thickness: \setlength{\arrayrulewidth}{4pt}. – Pieter van Oostrum Jan 20 '23 at 16:59
  • Thank you for the comment. The solution works quite fine. If you post it as an answer, I'd select it as accepted. – Lars Malmsteen Jan 20 '23 at 17:12

2 Answers2

1

With use of the tabularray package, solution is simple:

\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}

enter image description here

(red lines show text box on page borders)

Zarko
  • 296,517
  • Thank you for the answer. The tabularray works quite fine, plus the showframe is sure to help diagnose the issues while designing tables. I'm sure to take a look at it as I design my next table. I still had to select the earlier answer as it came earlier and worked the problem out. – Lars Malmsteen Jan 20 '23 at 17:44
  • @LarsMalmsteen, you are welcome! Is there a specualč reason, that you have caption below table? Usual it is above table, In this case you can employ threeparttable or talltblr and and limit caption width to table width. Many people like such table design.. – Zarko Jan 20 '23 at 18:29
  • yep there's a special reason for having the caption below the table: I'm writing down a scanned-PDF document in LaTeX and in that document, some of the tables are captioned in below :) Meanwhile, I have 2 other, ongoing problems with the tables, and I plan to post them as questions. 1st problem is about aligning the first row's (let's call it header) columns differently than the rest of the table, e.g. the header text will be center aligned the rest, left or right aligned. 2nd is about aligning the money units in a column by their decimal points. – Lars Malmsteen Jan 22 '23 at 10:27
1

Change the \vrule depth 2ex height 4ex width 0pt to e.g. \vrule depth 2ex height 2ex width 0pt. If you want the extra vertical space above the tabular you can add \vspace{2pt}. For the thickness: \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}

enter image description here