# Vertical space after minipage (EDIT : in an environment)

How to get proper vertical white space on linebreak after a minipage?

I.e.: How to fix my \alphabet command below so that the green and red marked spaces (in the figure below) are equal? (Is that \baselineskip?)

## MWE

\documentclass[12pt]{article}
\begin{document}
\newcommand\alphabet
{
\noindent
\begin{minipage}{5.5cm}
\noindent abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz
\end{minipage}
}
\alphabet
\alphabet
\alphabet
\alphabet
\alphabet
\alphabet
some more text for illustation purposes
\end{document}


I actually use those minipages in an environment. So here we go, using the environ package, as suggested in Werner's answer here.

\documentclass[12pt]{article}
\usepackage{environ}
\def\alphabet{abcdefghijklmnopqrstuvwxyz}
\NewEnviron{petitePage}%
{%
\noindent%
\begin{minipage}[t]{5.5cm}%
\noindent%
\BODY%
\sbox0{\BODY}%
\vspace{\dp0}%
\end{minipage}
}%
\newcommand\blabla
{%
\begin{petitePage}%
\noindent \alphabet \ \alphabet \ \alphabet \
\end{petitePage}
}
\begin{document}
\blabla%
\blabla%
\blabla%
\blabla%
\blabla%
\blabla%
\end{document}


minipage are centred by default which means that (typically) they have both height and depth larger than \baselineskip this means that when lines containing such large boxes are stacked baseline spacing can not be preserved and so TeX just separates the resulting boxes by \lineskip which is normally 1pt. All information about the baselines within the box is gone so there is no equal spacing between lines in different boxes.

If you only need to worry about space above or below a minipage you can use [t] or [b] which puts the reference point for the box on the top or bottom line so normal baselineskip calculation can be made. But this only works at one end of the box. To do both you could use a box that records both reference points (the infamous expl3 coffin for example) but simpler just case the boxes to be abutted with no space by setting \lineskip to zero, and then use a \strut at the start and end of the text so that the baseline of the first row is \ht\strutbox from the top of one box and the baseline of the previous row is \dp\strutbox from the bottom of its box, so the visible baselines are the height+depth of a \strut apart, that is, normal baseline spacing.

\showoutput
\showboxdepth=3
\documentclass[12pt]{article}
\def\alpha{abcdefghijklmnopqrstuvwxyz}
\newcommand\alphabet{%
\noindent\begin{minipage}{5.5cm}%
\strut\alpha\ \alpha\ \alpha\strut
\end{minipage}%
}

\begin{document}

{\setlength\lineskip{0pt}
\alphabet\ \alphabet\ \alphabet\ %
\alphabet\ \alphabet\ \alphabet\ %
\alphabet\ \alphabet\ \alphabet\ %
\strut some more text for illustration purposes

}
\end{document}


In TeX boxes have a width, height and depth (cf. Understanding minipages - aligning at top). The "bottom" of the minipage gets aligned with the baseline of the main page, but what you want is for the final baseline of the minipage to be aligned with the baseline of the text of the main page. You need to add in the space of the depth of the final line in the minipage:

\documentclass[12pt]{article}
\def\alpha{abcdefghijklmnopqrstuvwxyz}
\newcommand\alphabet{%
\noindent\begin{minipage}{5.5cm}%
\alpha\ \alpha\ \alpha\ %
\sbox0{\alpha}%
\vspace{\dp0}%
\end{minipage}%
}

\begin{document}
\alphabet\ \alphabet\ \alphabet\ %
\alphabet\ \alphabet\ \alphabet\ %
\alphabet\ \alphabet\ \alphabet\ %
some more text for illustation purposes
\end{document}


• ,@StrongBad (+1) I would use \sbox0{gh}, though. – AboAmmar Jan 17 '17 at 19:37
• this description of the alignment (and the added vspace) seem .. strange. you are using centred miniboxes and not accounting for \lineskip – David Carlisle Jan 17 '17 at 19:54
• @DavidCarlisle looking forward to seeing the correct answer. – StrongBad Jan 17 '17 at 19:56
• @StrongBad an answer posted I can't vouch for its correctness:-) – David Carlisle Jan 17 '17 at 20:11

For a quick fix you can simply insert some space by hand -- which in my opinion corresponds to something like a fifth of \baselineskip:

\documentclass{article}

\newcommand\alphabet{abcdefghijklmnopqrstuvwxyz}
\newcommand\tripplealphabet{%
\noindent
\begin{minipage}{5.5cm}
\noindent\alphabet\ \alphabet\ \alphabet
\end{minipage}
\vskip.2\baselineskip
}

\begin{document}
\tripplealphabet

some text

some more text
\end{document}


For a double check of this soulution you might wanna try:

...
\setlength\parindent{0em}
...

\begin{document}
\tripplealphabet

\alphabet

\alphabet
\end{document}