[Tex/LaTex] How to get consistent spacing around an mbox

boxesspacing

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

Desired output

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):

Actual output

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

Best Answer

\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).