3

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,
             -\dimexpr 1in+\topmargin+\headheight+\headsep+\topskip)%
        {%
            \vtop to\dimexpr\vsize+\baselineskip{
            \hrule
            \leaders\vbox to\baselineskip{\hrule width\hsize\vfill}\vfill
        }%
    }%
}%

\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?

output

7
  • 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. Jul 2, 2015 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, 2015 at 14:09
  • Nice trick with the red lines by the way
    – daleif
    Jul 2, 2015 at 14:10
  • use [b] not [t] Jul 2, 2015 at 15:41
  • 1
    @daleif Credit for the red lines goes to egreg tex.stackexchange.com/questions/150619/…
    – fiziks
    Jul 2, 2015 at 19:14

1 Answer 1

3

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:

Result

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .