Changing minipage vertical alignment in mid-line?

\documentclass{article}
\usepackage{lipsum}
\usepackage[showframe,showcrop]{geometry}

\begin{document}

\section{Section 1}

aa
\fbox{\begin{minipage}{100pt}
Box 1
\end{minipage}}
\fbox{\begin{minipage}[t]{150pt}
\lipsum[11]
\end{minipage}}
\fbox{\begin{minipage}[b]{50pt}
..... Box 3
\end{minipage}}
zz

\end{document}


It results with the following output:

All of the minipage boxes are top aligned.

Is it somehow possible to have the first and second minipage top-aligned (as they are) - but then have minipage 3 bottom-aligned to minipage 2 (and correspondingly, the last "zz" aligned to minipage 3)? Here is the desired output, composed in an image editor:

I would prefer a solution where I don't have to wrap the minipages in another minipage/environment (or load another package, EDIT: and that is because I eventually want to hook into a macro, which typesets a whole line [the "aa" to "zz"] parts - and allows me a hook for the middle; where I'd want to insert the miniboxes, and change the line alignment as shown) - but lacking that, I'd be interested in hearing any approach which is applicable here.

-

Besides measuring box heights and according manual placement you could use two tabulars. Compared to nested minipages, you do not have to specify any widths for the outer environment with this approach. Further packages are not required; however, if desirable e.g. for the "aa" and "zz" text parts, you could make use of advanced table features such as automatic-width X columns.

Proper bottom alignment of the two tables is sensitive to the insertion of a space, e.g. [0pt], after the line breaks (alternatively, a rule may be used).

The tables insert some additional horizontal space in the current setting. This space can however be removed by placing @{} before/after each column in the column definitions and by removing the line break between the tables.

\documentclass{article}
\usepackage{lipsum}
\usepackage[showframe,showcrop]{geometry}

\begin{document}

\section{Section 1}

\rule{\textwidth}{.5pt}
\begin{tabular}[b]{lll}
aa
& \fbox{\begin{minipage}[t]{100pt}Box 1\end{minipage}}
& \fbox{\begin{minipage}[t]{150pt}\lipsum[11]\end{minipage}}
\\[0pt]
\end{tabular}
\begin{tabular}[b]{ll}
\fbox{\begin{minipage}[b]{50pt}..... Box 3\end{minipage}}
& zz
\\[0pt]
\end{tabular}
\\\rule[\baselineskip]{\textwidth}{.5pt}

\end{document}

-
Many thanks for that @dgs - accept as I didn't even thing tabular would be applicable here! Unfortunately it still requires "wrapping" in an extern environment, including the "aa" and "zz" parts - and my ultimate intent is to hook into a different macro, which typesets a line with "aa" .. "zz", and I can only hook in the middle of the line, where I wanted to insert the miniboxes. But still, I think now I have enough to go further with this - many thanks again, and cheers! –  sdaau Jun 7 '12 at 10:06
but the baseline of box 1 is lower than either "aa" or the baseline of the first line in box 2, which doesn't look so good. (that's also true in the original posting.) otherwise, very nice. –  barbara beeton Jun 7 '12 at 12:15
Why do you use [b] in \begin{tabular}[b]{ll} while tabular is not floating?. –  Harish Kumar Jun 7 '12 at 16:25
@barbarabeeton Ah, thanks. The first minipage wasn't top-aligned in the original code, and I just copied/pasted it. I've updated the code, with rules added to show the alignment. @HarishKumar tabular takes its own position parameter. If you leave out any of the two [b]s, you'll notice that the result changes. –  dgs Jun 7 '12 at 18:52

Just a sidenote to @dgs' answer - note that what is holding the two fist boxes top-aligned, is the common tabular they are wrapped in; as soon as you try to break the tabular, the top alignment of the first two items stops (even if you keep the same arguments); that is, this:

\rule{\textwidth}{.5pt}
\begin{tabular}[b]{ll}
aa
& \fbox{\begin{minipage}[t]{100pt}Box 1\end{minipage}}
\\[0pt]
\end{tabular}
\begin{tabular}[b]{l}
\fbox{\begin{minipage}[t]{150pt}\lipsum[11]\end{minipage}}
\\[0pt]
\end{tabular}
\begin{tabular}[b]{ll}
\fbox{\begin{minipage}[b]{50pt}..... Box 3\end{minipage}}
& zz
\\[0pt]
\end{tabular}
\\\rule[\baselineskip]{\textwidth}{.5pt}


... results with this:

... even if the three tabulars are [b]ottom aligned (like the two tabulars in the answer were); - and the three minipages are aligned [t], [t], [b] (also like in the answer).

However, by accident, I also finally realized what I can use to "lift" the items in the first tabular; this is not necessarily trivial, because \vspace, \vskip or \rule (negative height rules are not drawn at all!) cannot be applied; however, as this snippet shows:

\rule{\textwidth}{.5pt}
\begin{tabular}[b]{ll}
% \vspace{-50pt}    % pushes down, doesn't "lift"
% \vspace*{-50pt}   % pushes down, doesn't "lift"
% \vskip -50pt      % ! Missing } inserted.
% \vskip -50pt      % ! Missing } inserted.
% \rule{4pt}{-60pt} % isn't drawn at all when negative
aa \raisebox{-50pt}{b} \rule{4pt}{60pt}
& \fbox{\begin{minipage}[t]{100pt}Box 1\end{minipage}}
\\[0pt]
\end{tabular}
\begin{tabular}[b]{l}
\fbox{\begin{minipage}[t]{150pt}\lipsum[11]\end{minipage}}
\\[0pt]
\end{tabular}
\begin{tabular}[b]{ll}
\fbox{\begin{minipage}[b]{50pt}..... Box 3\end{minipage}}
& zz
\\[0pt]
\end{tabular}
\\\rule[\baselineskip]{\textwidth}{.5pt}


... it is \raisebox with a negative "raise distance" that can be used for this purpose (sidenote: I looked at the definition of \raisebox in latex.ltx, and it seems that all it does is calculate some lengths, and apply them to the "currently selected" box ?!). Notice how the "b" acts as a bottom anchor now, taking up the "bottom" space relative to the environment:

So, all that is left now is to measure the height of the minipage, and "raise" negatively by approx the same amount, and thereby "lift up" contents from the bottom of the environment:

\documentclass{article}
\usepackage{lipsum}
\usepackage[showframe,showcrop]{geometry}
\usepackage{trace}
\usepackage{calc}

\begin{document}

\section{Section 1}

\newsavebox\mybox
\newlength{\miniheight}

% save long minipage for tabular 2 into a box,
% so we can measure its height:
\begin{lrbox}{\mybox} %
\begin{minipage}[t]{150pt}\lipsum[11]\end{minipage}
\end{lrbox} %

% note \baselineskip dissapears (is 0) in tabular!
% so save the default \baselineskip in
% another variable:
\typeout{\the\baselineskip} %
\newlength{\oldbaselineskip}
\setlength{\oldbaselineskip}{\baselineskip}

\rule{\textwidth}{.5pt}
\begin{tabular}[b]{ll}
% \vspace{-50pt}    % pushes down, doesn't "lift"
% \vspace*{-50pt}   % pushes down, doesn't "lift"
% \vskip -50pt      % ! Missing } inserted.
% \vskip -50pt      % ! Missing } inserted.
% \rule{4pt}{-60pt} % isn't drawn - is negative
% note: correct height is ht + dp; not just ht!
% +1em matches the {M} - 1.12\oldbaselineskip is manually tuned
\settoheight{\miniheight}{\usebox\mybox} %
\setlength{\miniheight}{\ht\mybox+\dp\mybox+1em-1.12\oldbaselineskip} %
\typeout{\the\miniheight, \the\baselineskip} %
aa \raisebox{-\miniheight}{M} \rule{4pt}{60pt}
& \fbox{\begin{minipage}[t]{100pt}Box 1\end{minipage}}
\\[0pt]
\end{tabular}
\begin{tabular}[b]{l}
\fbox{\usebox\mybox}
\\[0pt]
\end{tabular}
\begin{tabular}[b]{ll}
\fbox{\begin{minipage}[b]{50pt}..... Box 3\end{minipage}}
& zz
\\[0pt]
\end{tabular}
\\\rule[\baselineskip]{\textwidth}{.5pt}

\end{document}


Note here:

• You must save the long minipage in a box to measure its height
• The actual height is ht+dp (not just ht) of the saved box
• You must use the package calc, to use + as addition operator in the \setlength{\miniheight}... stanza
• You must save the default \baselineskip - since it disappears within the tabular environment
• I used the character M there as anchor, so I could adjust to 1em for the displacement height; however additional -1.12\oldbaselineskip, which I found manually (by trial and error)
• The \raisebox that does the shifting is inside a \tabular - but outside of a \minipage

... and finally that code results with this:

How applicable this is to other similar contexts, I cannot tell as of yet :) Cheers!

-