# Row Padding, Row by Row

Here's my MWE that is almost right... except for the excess padding in the top row which I would like to reduce to 0.2cm. The rest, I'd like to keep at 1.5cm.

\documentclass[12pt,letterpaper]{article}

\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{tabularx}

\begin{document}

{
\setlength{\extrarowheight}{1.5cm}

\begin{tabularx}{8cm}{|p{2.5cm}|p{2.5cm}|X|}  \hline

Top Left & Top Middle & Top Right \\ [0.2cm] \hline

Bottom Left & Bottom Middle & Bottom Right \\ [0.2cm] \hline

\end{tabularx}
}

\end{document}


This thread shows how to specify the one amount of vertical padding above the cells for ALL rows in a table. But what if the rows need different amounts? (I am making worksheets on which students will be writing in pencil.)

P.S. This is my first, or one of my first ever posts on StackExchange. I'm also a LaTeX newb. If there's a better way to pose questions, please let me know and I will edit this post. Thanks!

• I need the \hline as that those lines will show up in my worksheets and be part of how my students know where to write answers. I also don't know how I could easily see the vertical padding without them. I do not need the \booktabs package for the MWE, though, so I'll remove it. – WeCanLearnAnything Jul 26 '15 at 7:39

An easy, but manual solution, to this problem would be to reduce the value defined in \extrarowheight to 0.2cm and manually add an empty row of 1.1cm (1.1cm + 2 * 0.2cm = 1.5cm) above each row for which a top padding of 1.5cm is desired.

This approach has some limitations however. Because there is a minimum height a table row can have by default (see Column and row padding in tables), the minimal padding that it is possible to add with this approach is limited by the \baselineskip. It is, however, possible to reduce this value as described here: How to make a row in a table shorter?.

Below is a MWE that shows how it can be done:

\documentclass[12pt,letterpaper]{article}

\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{tabularx}

\begin{document}

\begin{table}
\centering
\setlength{\extrarowheight}{0.2cm}
\begin{tabularx}{8cm}{|p{2.5cm}|p{2.5cm}|X|} \hline

Top Left & Top Middle & Top Right \\[0.2cm] \hline
&& \\[1.1cm]
Middle Left & Middle & Middle Right \\[0.2cm] \hline
&& \\[1.1cm]
Bottom Left & Bottom Middle & Bottom Right \\[0.2cm] \hline

\end{tabularx}

\end{table}

\end{document}


Which results in:

Update (2015-07-27):

Below is an updated solution derived from the macro presented at: How to make a row in a table shorter?. It consists in a new command, which allows to add an extra custom row padding of a given height on a row by row basis.

\documentclass[12pt,letterpaper]{article}
\usepackage{tabularx}

% Modified from :
% https://tex.stackexchange.com/questions/84524/
% how-to-make-a-row-in-a-table-shorter/84536#84536

\makeatletter
\newsavebox\saved@arstrutbox
\newcommand*{\setarstrut}[1]{%
\noalign{%
\begingroup
\global\setbox\saved@arstrutbox\copy\@arstrutbox
\global\setbox\@arstrutbox\hbox{%
\vrule \@height #1
\@depth  0cm
\@width\z@
}%
\endgroup
}%
}
\newcommand*{\restorearstrut}{%
\noalign{%
\global\setbox\@arstrutbox\copy\saved@arstrutbox
}%
}
\makeatother

% New command to add an extra custom padding at the top of a row.
% Basically, it adds an empty row with the height value
% defined in the command.

\newcommand{\paddingtop}[2]{\setarstrut{#1} #2 \\ \restorearstrut}

\begin{document}

\begin{tabularx}{8cm}{|p{2.5cm}|p{2.5cm}|X|} \hline
Top Left & Top Middle & Top Right \\[2mm] \hline
Middle Left & Middle & Middle Right \\[2mm] \hline

• I see. I think I will use that for my smaller tables as it seems pretty easy. Question: Why was it necessary to nest the \tabularx environment inside the \table environment? – WeCanLearnAnything Jul 26 '15 at 16:36
• @WeCanLearnAnything Oh, it was not necessary to nest it in a \table environment for this example, it was just easier for me to test. In a document however, using the \table environment is useful for automatic placement of your \tabular within the flow of the text. – Jean-Sébastien Jul 26 '15 at 17:19