GeneralText in tables butting up against the top line in a cell

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Hessiess
Posts: 4
Joined: Sat Dec 06, 2008 1:01 pm

Text in tables butting up against the top line in a cell

Post by Hessiess »

If I put text into a table, the top of the characters are almost tutching the tip line in the cell, I can use \midrule instead which adds a small gap at the top of a cell, but then there are white gaps on the vertical lines of the table.

Thanks.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

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

Post by localghost »

Build a minimal working example (MWE) that gives us an idea of the problem.


Best regards and welcome to the board
Thorsten¹
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Text in tables butting up against the top line in a cell

Post by phi »

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.
Hessiess
Posts: 4
Joined: Sat Dec 06, 2008 1:01 pm

Text in tables butting up against the top line in a cell

Post by Hessiess »

localghost wrote:Build a minimal working example (MWE) that gives us an idea of the problem.


Best regards and welcome to the board
Thorsten¹
Thanks

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}
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.
The vertical lines are nessiserry to separate the table elements, otherwise it just looks like one line of text, Il look at arrayctretch.
User avatar
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

Post by localghost »

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.
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.

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}
Post Reply