# The context

I'm trying to create a table that meets the following conditions

1. the padding on all cells from the first row must be bigger than the default padding.
2. the content of all cells must be vertically center aligned.

Regarding the condition no. 1: I know how to change the padding on all cells but don't know how to do it for all cells of an specific row without causing this effect on all the other rows (see document below)

\documentclass{article}

\begin{document}

\def\arraystretch{2}

\noindent
\begin{tabular}{|c|c|c|}
\hline a & b & c
\\ \hline a & b & c
\\ \hline a & b & c
\\ \hline
\end{tabular}

\end{document}


Regarding the condition no. 2: I know how to do it.

\documentclass{article}

\usepackage{array, lipsum}

\begin{document}

\noindent
\begin{tabular}{|m{5cm}|m{5cm}|}
\hline a & \lipsum[1][1-2]
\\ \hline \lipsum[2][1-2] & b
\\ \hline
\end{tabular}

\end{document}


# The question

How can I create a table that meet condition no. 1 and condition no. 2?

• Use \multicolumn{1}{|c|}{a} instead of a, \multicolumn{1}{c|}{b} instead of b to center them. – ZhiyuanLck Jun 16 at 14:38

I use zero width rules piped into a zero width m-column to set the height of the rows. In addition, I define a new column type, M, which vertically and horizontally centres its content.

In example 2, I have defined a new command \rl, which allows you to set the row height individually.

Example 1 - same height rows

\documentclass{article}

\usepackage{array}
\newcolumntype{M}{>{\centering\arraybackslash}m{15pt}}

\begin{document}

\noindent
\begin{tabular}{|*{3}{M|}>{\rule{0pt}{30pt}}m{0pt}}
\cline{1-3} a & b & j &
\\ \cline{1-3}  a & b & j &
\\ \cline{1-3}  a & b & j &
\\ \cline{1-3}
\end{tabular}

\end{document}


Example 2 - different height rows

\documentclass{article}

\usepackage{array}
\newcolumntype{M}{>{\centering\arraybackslash}m{15pt}}
\newcommand{\rl}[1]{\rule{0pt}{#1pt}}

\begin{document}

\noindent
\begin{tabular}{|*{3}{M|}m{0pt}}
\cline{1-3} a & b & j & \rl{16}
\\ \cline{1-3}  a & b & j &
\\ \cline{1-3}  a & b & j &\rl{30}
\\ \cline{1-3}
\end{tabular}

\end{document}

• This answer doesn't meet the condition no. 1. The reason I posted this question is because I want to find a way to set the padding for the cells of an specific row without affecting the cells from the other rows. – gfe Jun 16 at 21:44

In the environment {NiceTabular} of nicematrix, you have two keys cell-space-top-limit and cell-space-bottom-limit.

You can set these keys with a command \NiceMatrixOptions. These options are set locally. However (even if it is not elegant) you can switch to a global affectation by using the TeX primitive \globaldefs.

In the following example, I have defined a command cellspace which changes globally the value of the parameters cell-space-top-limit and cell-space-bottom-limit.

\documentclass{article}
\usepackage{nicematrix,xparse}

\NewDocumentCommand \cellspace { m }
{
{
\globaldefs=1
\NiceMatrixOptions{cell-space-top-limit=#1,cell-space-bottom-limit=#1}
}
}

\NiceMatrixOptions{cell-space-top-limit=1mm,cell-space-bottom-limit=1mm}

\begin{document}

\newcolumntype{M}{>{\raggedright}m{2.2cm}}

\begin{NiceTabular}{MMM}[hvlines]
some text & here also some text & text, text, text and text \tabularnewline
some text & here also some text & text, text, text and text \tabularnewline
\cellspace{0pt}
some text & here also some text & text, text, text and text \tabularnewline
\cellspace{1mm}
some text & here also some text & text, text, text and text
\end{NiceTabular}

\end{document}


The package nicematrix also provides a key hvlines which draw all the rules.

I wouldn't use arraystretch to have vertically centered cells contents, as it asymmetrically expands the height and depth of cells. A better way uses package cellspace, which defines a minimal vertical padding at the top and bottom of cells in columns with specifier prefixed with the letter S (or C if you load siunitx).

Here is demo, with \cellspacetop-bottomlimit chosenn so that the solution with arraystretch and the solution with cellspace result in tables of the same height:

\documentclass{article}
\usepackage{cellspace}
\setlength{\cellspacetoplimit}{8.5pt}
\setlength{\cellspacebottomlimit}{8.5pt}

\begin{document}

{\def\arraystretch{2}

\noindent
\begin{tabular}{|c|c|c|}
\hline a & b & c
\\ \hline a & b & c
\\ \hline a & b & c
\\ \hline
\end{tabular}}
\begin{tabular}{|Sc|Sc|Sc|}
\hline a & b & c
\\ \hline a & b & c
\\ \hline a & b & c
\\ \hline
\end{tabular}

\end{document}


• Hm, it seems that in answer you not load your solution (the code for the right table on image) – Zarko Jun 16 at 14:41
• @Zarko: I did, but there may be an optical effect due to b having an ascender, in the middle column. – Bernard Jun 16 at 14:55
• Sorry to bother you, but your MWE doesn't reproduce showed image. In it is missing code for the right table (a solution for use cellspace package. Or I not understand your answer :-( – Zarko Jun 16 at 14:59
• @Zarko: Oh! A copy-paste accident. I misunderstood what you meant. I should have checked. Thank you! – Bernard Jun 16 at 16:09
• This answer doesn't meet the condition no. 1. The reason I posted this question is because I want to find a way to set the padding for the cells of an specific row without affecting the cells from the other rows. – gfe Jun 16 at 21:43

Both conditions are met with this approach

\documentclass{article}

\usepackage{tabu, stackengine}

\usepackage{lipsum}

\begin{document}

\begin{tabu}{|m{80pt}|m{80pt}|m{80pt}|}
\hline

& b
& \lipsum[1][1-2]
\\ \hline

A
& B
& C
\\ \hline

\end{tabu}

\end{document}