General ⇒ Text in tables butting up against the top line in a cell
Text in tables butting up against the top line in a cell
Thanks.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Text in tables butting up against the top line in a cell
Best regards and welcome to the board
Thorsten¹
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Text in tables butting up against the top line in a cell
Otherwise you can redefine \arraystretch or add a strut to the problematic cells.
Text in tables butting up against the top line in a cell
Thankslocalghost wrote:Build a minimal working example (MWE) that gives us an idea of the problem.
Best regards and welcome to the board
Thorsten¹
Code: Select all
\documentclass[11pt,a4paper]{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{| l | p{8cm}|}
\hline
\textbf{{\Large{Heading}}} & \textbf{{\Large{This text is touching the top line}}}\\
\hline
\textbf{hline} & this text is almost touching the top edge of the cell\\
\midrule
\textbf{Midrule} & The gap between the top of the text and the cell edge is
better, but now there are gaps in the vertical lines\\
\hline
\end{tabular}
\end{document}
The vertical lines are nessiserry to separate the table elements, otherwise it just looks like one line of text, Il look at arrayctretch.In professional tables there are no vertical lines, and the booktabs package does not support them, so leave them out.
Otherwise you can redefine \arraystretch or add a strut to the problematic cells.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Text in tables butting up against the top line in a cell
You can always put some horizontal space between the columns. The code below demonstrates two possible solutions each for stretching the row height and the space between columns.Hessiess wrote:[...] The vertical lines are nessiserry to separate the table elements, otherwise it just looks like one line of text, Il look at arrayctretch.
Code: Select all
\documentclass[11pt,a4paper]{article}
\usepackage{array,booktabs}
\usepackage[font=small,labelfont=bf]{caption}
\usepackage[margin=2cm]{geometry}
\setlength{\parindent}{0em}
\begin{document}
\begin{table}[!ht]
\centering
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{|l|p{8cm}|} \hline
\textbf{{\Large{Heading}}} & \textbf{{\Large{This text is touching the top line}}} \\ \hline
\textbf{hline} & this text is almost touching the top edge of the cell \\ \hline
\textbf{hline} & The gap between the top of the text and the cell edge is better, but now there are gaps in the vertical lines \\ \hline
\end{tabular}
\caption{Table with stretched height of the rows}\label{tab:arraystretch}
\end{table}
\begin{table}[!ht]
\centering
\begin{tabular}{l@{\qquad}p{8cm}} \toprule
\textbf{{\Large{Heading}}} & \textbf{{\Large{This text is touching the top line}}} \\ \midrule
\textbf{midrule} & this text is almost touching the top edge of the cell \\ \midrule
\textbf{midrule} & The gap between the top of the text and the cell edge is better, but now there are gaps in the vertical lines \\ \bottomrule
\end{tabular}
\caption{Table with \textsf{booktabs} package and manual space between columns}\label{tab:booktabs-manual}
\end{table}
\begin{table}[!ht]
\centering
\setlength{\tabcolsep}{5mm}
\begin{tabular}{lp{8cm}} \toprule
\textbf{{\Large{Heading}}} & \textbf{{\Large{This text is touching the top line}}} \\ \midrule
\textbf{midrule} & this text is almost touching the top edge of the cell \\ \midrule
\textbf{midrule} & The gap between the top of the text and the cell edge is better, but now there are gaps in the vertical lines \\ \bottomrule
\end{tabular}
\caption{Table with \textsf{booktabs} package and fixed space between columns}\label{tab:booktabs-fixed}
\end{table}
\begin{table}[!ht]
\centering
\setlength{\extrarowheight}{2pt} % needs array package
\begin{tabular}{|l|p{8cm}|} \hline
\textbf{{\Large{Heading}}} & \textbf{{\Large{This text is touching the top line}}} \\ \hline
\textbf{hline} & this text is almost touching the top edge of the cell \\ \hline
\textbf{hline} & The gap between the top of the text and the cell edge is better, but now there are gaps in the vertical lines \\ \hline
\end{tabular}
\caption{Table with extra height for the rows}\label{tab:extrarowheight}
\end{table}
\end{document}
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10