# Stacking two hboxes

I am trying to write the macro \foo{...}{...} that creates an hbox made up of both \hbox{#1} and \hbox{#2}, such that both hboxes are stacked one on top of the other. The width of the resulting hbox should be the maximum of the two hboxes. The arguments to the macro are in plain mode (i.e., not in math mode).

-
 Note that it is unusual around here to sign your questions (as there is already a box with your username below it). – lockstep Mar 5 '11 at 17:22

In general you can stack \hboxes inside a \vbox (which should be placed inside a \hbox as well if you want to use the result in horizontal mode), like Gonzalo Medina shows in his nice answer.

There are also some macros and packages for this:

• \shortstack{foo\\bar} will stack foo over bar (adding \struts might be a good idea to get correct baseline skip)
• The small minibox package provides \minibox:
\minibox{foo\\bar}
It also accepts an optional argument [l], [c] or [r] to align the lines.

Both macros allow for more than two hbox'es/lines.

-
If you try \foo{some}{test text} \foo{some}{test text} \foo{some}{test text} then Gonzalo's solution does not work -- the stacks are placed one under the other, rather then to their side. Now the minibox package works just great, and I created a wrapper macro that does just what I need. Thanks! – Mayer Goldberg Mar 5 '11 at 17:51
@Mayer Goldberg: Note that \minibox itself is just a wrapper around tabular: \long macro:[#1]#2->\begin {tabular}{@{}#1@{}} #2 \end {tabular} – Martin Scharrer Mar 5 '11 at 18:00

Perhaps something like this?

\documentclass{article}
\newcommand*\foo[2]{%
\hbox{\vbox{\hbox{#1}\hbox{#2}}}
}

\begin{document}

\foo{some}{test text}

\end{document}


or (more in TeX's spirit):

\documentclass{article}
\def\foo#1#2{%
\hbox{\vbox{\hbox{#1}\hbox{#2}}}
}

\begin{document}

\foo{some}{test text}

\end{document}

-
Not quite: The problem with this is that I need these foo-stacks to be printed one after the other on the same line. So I might use it as \foo{in}{in} \foo{principio}{the beginning} \foo{creavit}{created (3rd, sg)} \foo{Deus}{God} \word{caelum}{heaven} \word{et}{and} \word{terram.}{earth.} I'm trying to use this for inter-linear texts. – Mayer Goldberg Mar 5 '11 at 17:40
@Meyer That's because you're using it before entering horizontal mode (i.e., before properly beginning a paragraph). You can take care of this case by changing it to \def\foo#1#2{\leavevmode\hbox{\vbox{\hbox{#1}\hbox{#2}}}}, i.e., just insert \leavevmode. – Phil Hirschhorn Mar 5 '11 at 18:40