# How do I get consistent spacing around an mbox?

I am trying to typeset a formula in LaTeX with a rule name beneath it, such as the following:

The code for the rule an automatically-generated mess (not necessarily using maths mode), output from the theorem prover Isabelle/HOL, which I have little control over. My hope was that I could somehow isolate the auto-generated output by using mbox or something similar.

My attempt to generate a macro for generating this output boils down to something like the following once I remove formatting commands:

\newcommand{\myrule}[2]{{
\begin{minipage}{\textwidth}%
\mbox{#1} \\
\mbox{#2}
\end{minipage}}}


This can then be used as \myrule{\AutoGeneratedOutput}{ParitalPrimeSuc}.

The problem I have is that the vertical space between the two boxes depends on the content of the first box. For example, consider the following example:

\documentclass{article}

\begin{document}

\newcommand{\myrule}[2]{{
\begin{minipage}{\textwidth}%
\mbox{#1} \\
\mbox{#2}
\end{minipage}}}

\newcommand{\myruleii}[2]{{
\begin{minipage}{\textwidth}%
\fbox{#1} \\
\fbox{#2}
\end{minipage}\ignorespacesafterend}}

\myrule{\begin{minipage}{1in}line 1\end{minipage}}{last line}

\vspace*{.5in}

\myrule{\begin{minipage}{1in}line 1\\ line 2\end{minipage}}{last line}

\vspace*{.5in}

\myruleii{\begin{minipage}{1in}line 1\end{minipage}}{last line}

\vspace*{.5in}

\myruleii{\begin{minipage}{1in}line 1\\ line 2\end{minipage}}{last line}

\end{document}


The output of this is as follows (images moved to save space):

Note that the distance between the bottom of the first mbox and the second mbox (highlighted in blue) differs depending on whether the first parameter has a line-break in it our not.

Interestingly, if I replace the mbox with a fbox, the spacing becomes consistent (highlighted in green). This confuses me somewhat, because an fbox is supposed to be the same as an mbox, other than having a border around it.

Is there a way to get the consistent spacing of fbox without the border? (Or should I be using a completely different mechanism for this?)

-

\begin{minipage}[b] should help. Then the reference point of the minipage is moved to the bottom element (e.g. line). Then the normal line spacing rules apply, trying \baselineskip for the base lines first.

Otherwise the reference point is vertically in the middle. With several lines the depth of the minipage becomes huge and very likely exceeds \lineskiplimit. Then TeX does not set the space according to \baselineskip. Instead it inserts \lineskip (default: 1pt).

-
Thanks for your post. So using \fbox solves my problem simply because the border pushes me over \lineskiplimit? Using \begin{minipage}[b] appears to solve the problem, but after reading up on \lineskiplimit, \baselineskip, \lineskip (which led me to \offinterlineskip), I wonder if adjusting these is a better approach? – davidg Mar 31 '14 at 5:06
@davidg: The distance between the two \fboxes is not larger in your image. The space between the lines is very likely \lineskip = 1pt. The space inside the \fbox does not matter. The dimension of the \fbox is visible by its lines. The spacing inside is controlled by \fboxsep. Therefore \fbox is larger by \fboxsep + \fboxrule in all four directions than a \mbox with the same argument. – Heiko Oberdiek Mar 31 '14 at 5:16

you could try putting a \strut at the end of the last line in the first box, and another at the beginning of the first line in the second box.

that should enforce the equivalent of a \baselineskip between them.

-