Is it possible to have some words written over each other in normal text? The use case is that it should be used instead of slashes where a sentence talks about two similar options.

A short example:

If you walk left/right, you will see a house/boat with an old man/a cat.

I'm hoping to get a result that looks a bit like this mockup (done in an ugly and very manual manner here with \raisebox and \hspace):

mockup of example text

3 Answers 3


This is what the \stackanchor macro does in the stackengine package. I show three instances, center, left, and right aligned. In the last instance, I set the stackgap between the items to 8pt, rather than the default (3pt). Note that the gap can be alternately achieved via \stackanchor[8pt]{top item}{bottom item}.

The default stack sets the gap between the bottom of the top item and the top of the bottom item (what I call short stacks). Alternately, you could set the gap between baselines of the two stacked items (what I call long stacks) with \def\stacktype{L}and \setstackgap{L}{inter-baseline gap}.

\parskip 1em
\def\mytext{If you walk \stackanchor{left}{right}, you will see a
\stackanchor{house}{boat} with \stackanchor{an old man}{a cat}.}




enter image description here

Alternately, \stackon and \stackunder will produce the stack where the baseline is not split, but instead aligned with either the lower item (\stackon) or upper item{\stackunder), respectively.

  • Wow, that's a powerful package.
    – quazgar
    Aug 30, 2013 at 19:39
  • totally agree with quazgar—it makes it so simple! Feb 18, 2016 at 16:09
  • What if I want to stack three or more lines of text?
    – Adriaan
    Apr 17, 2018 at 15:08
  • @Adriaan Then there are other options, such as \Shortstack, \Longstack, \Shortunderstack, \Lonunderstack, and \Centerstack. If the argument needs horizontal tabbing, in addition to vertical stacking, then the tabstackengine package extends the syntax of the stackengine package. Apr 17, 2018 at 21:38

If you're interested in that particular syntax, the following might be of interest:

enter image description here

If you walk \dual{left/right}, you will see a \dual{house/boat} with \dual{an old man/a cat}.

It uses the parameter text of a \definition to specify the required input: \dual{<top>/<bottom>}. If you wish to have a different layout (not vertically centred), try using \begin{tabular}[t]:

enter image description here

or \begin{tabular}[b]:

enter image description here

Here is an expansion of the above solution that provides some key-value options:

enter image description here

\usepackage{xkeyval}% http://ctan.org/pkg/xkeyval
\newcommand{\dual}[2][,]{% \dual[<opts>]{<top>/<bot>}
  \setkeys{dualkey}{valign=c,halign=c,topwidth=\m@ne\p@,botwidth=\m@ne\p@,#1}% Set (default) keys
  \expandafter\dual@aux#2\@nil}% Print dual
  \begin{tabular}[\dk@valign]{@{}\dk@halign @{}}
    \ifdim\dk@toplen<\z@ #1\else\makebox[\dk@toplen]{#1}\fi\\
    \ifdim\dk@botlen<\z@ #2\else\makebox[\dk@botlen]{#2}\fi
If you walk \dual[valign=b]{left/right}, you will see a \dual[valign=b,topwidth=0pt]{house/boat} with 
\dual[valign=t,halign=r]{an old man/a cat}.

You can now set the vertical and horizontal alignment within \dual (default is center for both), as well as the width of the respective items. This allows for a better flow of the sentence structure, if need be. Line-breaking at the end of the text block will still be problematic though, due to the boxing nature of \dual.

  • I'd prefer \dual{left}{right} that's more easily manageable.
    – egreg
    Aug 30, 2013 at 19:11

What that is, eventually, is a vertical box which has horizontal boxes inside, so (in plain-tex; compile with tex/pdftex/xetex/luatex):

If you walk , you will see a /left/right/, you will see a /house/boat/ with an
old /man/a cat/.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .