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

egreg
  • 1,121,712
fiziks
  • 345
  • 2
  • 8
  • 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 02 '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 02 '15 at 14:09
  • Nice trick with the red lines by the way – daleif Jul 02 '15 at 14:10
  • use [b] not [t] – David Carlisle Jul 02 '15 at 15:41
  • @DavidCarlisle Then you move the problem from the bottom to the top. ;-) – Heiko Oberdiek Jul 02 '15 at 16:20
  • @HeikoOberdiek but the example only had text below, and top of the page is easier to control:-) latex3 coffins are designed for this problem (can have two or more reference points) (but +1 for your answer anyway:-) – David Carlisle Jul 02 '15 at 16:23
  • 1
    @daleif Credit for the red lines goes to egreg http://tex.stackexchange.com/questions/150619/drawing-a-background-grid-based-on-linespread-value – fiziks Jul 02 '15 at 19:14

1 Answers1

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

Heiko Oberdiek
  • 271,626