# A gap between text and line in table

To eliminate the problem I have fboxed shortstack with zero fboxsep:

\documentclass[a4paper,11pt]{extarticle}
\usepackage{array}
\begin{document}

\newcommand{\mystr}{9:00\\10:30}

\setlength{\fboxsep}{0pt}

\begin{tabular}{m{5mm}|m{15mm}|m{5mm}}
&&\\\hline
&\fbox{\bf\shortstack{\mystr}}&\\\hline
&&\\%
\end{tabular}
\end{document}


and get as result: so question: What is nature of the gap between shortstack bottom and rows separtion line? and how the gap can be avoided?

• Wouldn't it look better if you added a gap at the top of the cell? – Bernard Mar 12 '17 at 22:07
• The problem is not the space at the bottom but the (lack of) space at the top. The problem is the same with a \huge X. When the box is just higher than a normal X, the space above is increased as needed, but not more, while the space below the baseline is the for the height of descender in character like "g" plus a minimum space between the text and the line. Otherwise ...what if you write "9:00pm\\10:30pm"?: The solution is incrase the row height ( \renewcommand\arraystretch{2.2} or simply end the row with some like \\[3ex]) or even add \vspace{.3ex} to the cell. – Fran Mar 12 '17 at 22:15

In the middle cell there are only a line with a box. That is, for LaTeX the stacked text is just like a huge character. In fact, the problem is exactly the same with a cell with \huge X. Remember that any character is a box, and that a box is managed like a character.

The table rows have a always a minimal vertical space, to ensure that any normal font fit perfectly, no matter if the character have ascender (like "f"), descender (like "g") or none (like "m"), or are only small dots. As you know, they are not aligned at the top, bottom or the middle of the row , as vectorial objects in a drawing program, but lined up at their baseline (red lines in the MWE), where most letters "sit" in this baseline, except those with a descender:

This cannot be done with 2D boxes with only a total height and width, so TeX boxes are pseudo 3D rentangles with a width, a height (upon the baseline) and a depth (the height under the baseline). That is, height + depth is the total height that we see.

If there are a box with higher height or depth than the normal font in a table row, then TeX make room to fit one or both dimensions but unfortunately, not enough to avoid colliding with top or bottom lines, or both. Note in the MWE that a medium "p" can touch both lines, while a huge "X" cannot touch the bottom line, no matter how big it is, because the depth of X is always 0pt.

In your case, the \shortstack box increase considerably only the height, as a huge "X" does, thus touching the top line, but left unchanged the depth, so the your bottom gap is simply the default space reserved for descenders. If you add to the same \shortstack box a final "p", the apparent gap is reduced considerably.

Therefore, although visually unpleasant ,your bottom gap is correct. The real problem is the lack of padding above the \shortstack box. You can solve this locally with \\[<length>], or with two global approaches:

1) Increase a bit the height of the rows, with \extrarowheight.

2) Change the minimum vertical space with the array stretch factor (\arraystretch) that is 1 by default, that mean increase both height and depth proportionally. At low values could produce odd or similar similar result that \extrarowheight but this have the effect of a bottom align, whereas \arraystretch tend to a balanced vertical padding (or a balanced lack of padding when less of 1).

The complete code of the above images:

\documentclass[a4paper,11pt]{extarticle}
\usepackage{array,xcolor}
\newcommand\mystr{\colorbox{cyan!50}{\bfseries\shortstack{9:00\\10:30}}}
\newcommand\mystrpm{\colorbox{orange!50}{\bfseries\shortstack{9:00pm\\10:30pm}}}
\newcommand\baseline{\leavevmode\rlap{\color{red!50}\rule{.3\textwidth}{.4pt}}}
\setlength{\parskip}{1em}
\setlength{\fboxsep}{0pt}

\newlength\myhe
\settoheight{\myhe}{X}
\newlength\myde
\settodepth{\myde}{p}
\newlength\myhede
\setlength{\myhede}{\dimexpr\myhe+\myde}

\begin{document}

\twocolumn[\centering
\begin{tabular}{m{3mm}||m{20mm}|m{3mm}}\hline
\baseline x & \fbox{x} x x x &  x \\\hline
\baseline . & \fbox{.} . . . &  . \\\hline
\baseline x & \fbox{h} h \fbox{g} g &  x \\\hline
\baseline x & \baseline h \fbox{\Huge X} &  x \\\hline
\baseline x & \baseline\fbox{h} h \fbox{\huge p} &  x \\\hline
\end{tabular}\bigskip]

{\Large\bfseries \verb|\extrarowheight|}

+0pt (default) \par

%\setlength{\extrarowheight}{0pt} % default
\begin{tabular}{m{3mm}||m{20mm}|m{3mm}}\hline
\baseline . & ... &  . \\\hline
\baseline x & \baseline\hfil\mystr &  x \\\hline
\baseline x & \baseline\hfil\mystrpm &  x \\\hline
\end{tabular}

-\the\numexpr\number\myde/65536\relax pt (-depth)\par

\setlength{\extrarowheight}{\dimexpr-\myde}
\begin{tabular}{m{3mm}|m{20mm}|m{3mm}}\hline
\baseline . & ... &  . \\\hline
\baseline x & \hfil\mystr &  x \\\hline
\baseline x & \hfil\mystrpm &  x \\\hline
\end{tabular}

+\the\numexpr\number\myhe/65536\relax pt (heigth)\par

\setlength{\extrarowheight}{\myhe}
\begin{tabular}{m{3mm}|m{20mm}|m{3mm}}\hline
\baseline . & ... &  . \\\hline
\baseline x & \hfil\mystr &  x \\\hline
\baseline x & \hfil\mystrpm &  x \\\hline
\end{tabular}

+\the\numexpr\number\myhede/65536\relax pt (heigth + depth)\par

\setlength{\extrarowheight}{\dimexpr\myhe+\myde}
\begin{tabular}{m{3mm}|m{20mm}|m{3mm}}\hline
\baseline . & ... &  . \\\hline
\baseline x & \hfil\mystr &  x \\\hline
\baseline x & \hfil\mystrpm &  x \\\hline
\end{tabular}

\newpage
{\Large\bfseries \verb|\arraystretch|}

0 (no default space)\par
\renewcommand\arraystretch{0}
\begin{tabular}{m{3mm}|m{20mm}|m{3mm}}\hline
\baseline . & ... &  . \\\hline
\baseline x & \hfil\mystr &  x \\\hline
\baseline x & \hfil\mystrpm &  x \\\hline
\end{tabular}

$\times1$ (default)\par
\renewcommand\arraystretch{1}
\begin{tabular}{m{3mm}|m{20mm}|m{3mm}}\hline
\baseline . & ... &  . \\\hline
\baseline x & \hfil\mystr &  x \\\hline
\baseline x & \hfil\mystrpm &  x \\\hline
\end{tabular}

$\times2$ \par
\renewcommand\arraystretch{2}
\begin{tabular}{m{3mm}|m{20mm}|m{3mm}}\hline
\baseline . & ... &  . \\\hline
\baseline x & \hfil\mystr &  x \\\hline
\baseline x & \hfil\mystrpm &  x \\\hline
\end{tabular}

$\times2.5$ \par
\renewcommand\arraystretch{2.5}
\begin{tabular}{m{3mm}|m{20mm}|m{3mm}}\hline
\baseline . & ... &  . \\\hline
\baseline x & \hfil\mystr &  x \\\hline
\baseline x & \hfil\mystrpm &  x \\\hline
\end{tabular}

\end{document}

• @scottkosty Probably I was playing with some macro including a \verb in a preliminar version of the MWE. Deleted. – Fran Apr 18 '18 at 21:31

There is normally a bottom strut in tabulars of a 0.9ex height. So, you need to compensate for this height by issuing \\[\dimexpr-.9ex+.4pt] and that extra 0.4pt is for the \fboxrule thickness. I've added a third row to see the effect of removing that 0.9ex.

\documentclass[a4paper,11pt]{extarticle}
\usepackage{array}
\begin{document}

\newcommand{\mystr}{9:00\\10:30}
\setlength{\fboxsep}{0pt}

\begin{tabular}{m{5mm}|m{15mm}|m{5mm}}
&&\\\hline
&\fbox{\bf\shortstack{\mystr}}&\\[\dimexpr-.9ex+.4pt] \hline
&here&\\[-.9ex]\hline%
\end{tabular}
\end{document}


There is an alternative/easier solution, however, using a parbox:

\documentclass[a4paper,11pt]{extarticle}
\usepackage{array}
\begin{document}

\setlength{\fboxsep}{0pt}

\begin{tabular}{m{5mm}|m{15mm}|m{5mm}}
&&\\\hline
&\fbox{\parbox{15mm}{\centering\bfseries9:00\\10:30}}& \\ \hline
&&\\%
\end{tabular}
\end{document}


with the following result: