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

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

share|improve this question
up vote 15 down vote accepted

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.

share|improve this answer
Wow, that's a powerful package. – quazgar Aug 30 '13 at 19:39
@quazgar Thanks for the compliment. – Steven B. Segletes Aug 30 '13 at 19:44
totally agree with quazgar—it makes it so simple! – loved.by.Jesus Feb 18 at 16:09

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.

share|improve this answer
I'd prefer \dual{left}{right} that's more easily manageable. – egreg Aug 30 '13 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

share|improve this answer

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.