TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

I'm not very good with raw TeX. Can someone please help?

share|improve this question
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
up vote 3 down vote accepted

While this is an old question, it looked like a good place to highlight the various capabilities of my new stackengine package in one place, rather than (as I have been doing) on a piecemeal basis. All the gap/shift distances are specifiable, as well. [EDIT: This MWE revised to use V2.0 syntax, which was implemented to allow stackgap lengths to be scalable with fontsize. The V2.0 package was submitted to CTAN 7/11/13]

\parindent 0pt\parskip 1em

The \textsf{stackengine} package:

SHORT STACKS (constant inter-item gap):
\\with center alignment

\Shortstack{this is the Shortstack macro}\x
\Shortunderstack{the Shortunderstack macro}\x

LONG STACKS (constant inter-baseline distance):
\\with left alignment\def\stackalignment{l}

\Longstack{this is the Longstack macro}\x
\Longunderstack{the Longunderstack macro}\x


use anchorwidth for
{\Longunderstack{this is the Longunderstack macro}} 
stack rather than the full stackwidth

In addition, the \textsf{stackengine} package does baseline 
\belowbaseline[6pt]{shifts}, as well as 
and insetting (\bottominset{*}{O}{-2pt}{}verlapping) text and


enter image description here

share|improve this answer

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:
    It also accepts an optional argument [l], [c] or [r] to align the lines.

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

share|improve this answer
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?



\foo{some}{test text}


or (more in TeX's spirit):



\foo{some}{test text}

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.