# Odd behavior after minipage environment

I have this code where, for demonstrative purposes, I have drawn in red lines at integer values of \baselineskip and framed the minipages:

\documentclass{article}
\usepackage{calc}
\usepackage[margin = 1.0in, showframe, heightrounded]{geometry}
\usepackage{lipsum}

\setlength{\fboxsep}{-\fboxrule}% Remove space between fbox frame and content

% Red lines at baselines.
\usepackage{eso-pic}
\usepackage{atbegshi,picture,xcolor}
\AtBeginShipout{%
\AtBeginShipoutUpperLeft{%
\color{red}%
\put(\dimexpr 1in+\oddsidemargin,
{%
\vtop to\dimexpr\vsize+\baselineskip{
\hrule
}%
}%
}%

\begin{document}

\fbox
{%
\begin{minipage}[t][\heightof{Lorem} + 9\baselineskip]{0.85\textwidth}
\lipsum[1]
\end{minipage}%
}

\hfill

Hello,

\end{document}


My question is simple: why isn't the baseline of "Hello," at precisely the next red line after the minipage?

• one more close brace is needed to match the opener for \vtop in the definition of \AtBeginShipout. i can't figure out why the \hfill should be needed, but removing it only makes things worse, and \struts don't help either. – barbara beeton Jul 2 '15 at 13:51
• If I ditch the specific height of the minipage, use \lipsum*[1]\strut and add a \par before Hello it seems to match. Some of the box wizards my explain the actual size of the boxes – daleif Jul 2 '15 at 14:09
• Nice trick with the red lines by the way – daleif Jul 2 '15 at 14:10
• use [b] not [t] – David Carlisle Jul 2 '15 at 15:41
• @daleif Credit for the red lines goes to egreg tex.stackexchange.com/questions/150619/… – fiziks Jul 2 '15 at 19:14

The following

\begin{minipage}[t][\heightof{Lorem} + 9\baselineskip]{0.85\textwidth}


assigns the minipage the height of the first line ("Lorem"). Thus the \topskip setting is correct with regarding to the grid lines.

However the depth of the box is the remaining space of 9\baselineskip. The depth of the last line sticks even outside the box. Because of the very large depth of the minipage, \baselineskip is not used and set, but \lineskip (default: 1 pt). The depth of the "g" is sticking out of the box and is around 2 pt, the next line "Hello" overprints the descender of the "g" (without the \hfill of course).

The example can be fixed in two ways:

• Setting \prevdepth to zero:

\fbox{%
\begin{minipage}[t][\heightof{Lorem} + 9\baselineskip]{0.85\textwidth}
\lipsum[1]
\end{minipage}%
}\par
\setlength{\prevdepth}{0pt}
Hello,


An overlarge descender of the last line of the minipage or accented uppercase letters might clash then, because TeX does not know about the depth of the last line, when setting the "Hello" line. But the grid is more respected.

• A box can be added, which simulates the depth of the last line in the minipage:

\fbox{%
\begin{minipage}[t][\heightof{Lorem} + 9\baselineskip]{0.85\textwidth}
\lipsum[1]
\par
\xdef\lastprevdepth{\the\prevdepth}%
\end{minipage}%
}\par
\nobreak
\nointerlineskip
\hbox{\vrule width0pt depth\lastprevdepth}
Hello,


Result in both cases: