Two-lined text (text over text)
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}
.
\documentclass{article}
\usepackage{stackengine}
\parskip 1em
\begin{document}
\def\mytext{If you walk \stackanchor{left}{right}, you will see a
\stackanchor{house}{boat} with \stackanchor{an old man}{a cat}.}
\mytext
\def\stackalignment{l}\mytext
\setstackgap{S}{8pt}
\def\stackalignment{r}\mytext
\end{document}
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.
If you're interested in that particular syntax, the following might be of interest:
\documentclass{article}
\makeatletter
\def\dual#1{\expandafter\dual@aux#1\@nil}
\def\dual@aux#1/#2\@nil{\begin{tabular}{@{}c@{}}#1\\#2\end{tabular}}
\makeatother
\begin{document}
If you walk \dual{left/right}, you will see a \dual{house/boat} with \dual{an old man/a cat}.
\end{document}
It uses the parameter text of a \def
inition to specify the required input: \dual{<top>/<bottom>}
. If you wish to have a different layout (not vertically centred), try using \begin{tabular}[t]
:
or \begin{tabular}[b]
:
Here is an expansion of the above solution that provides some key-value options:
\documentclass{article}
\usepackage{xkeyval}% http://ctan.org/pkg/xkeyval
\makeatletter
\newlength{\dk@toplen}\newlength{\dk@botlen}
\define@cmdkey{dualkey}[dk@]{halign}[c]{}%
\define@cmdkey{dualkey}[dk@]{valign}[c]{}%
\define@key{dualkey}{topwidth}{\setlength{\dk@toplen}{#1}}
\define@key{dualkey}{botwidth}{\setlength{\dk@botlen}{#1}}
\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
\def\dual@aux#1/#2\@nil{%
\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
\end{tabular}}
\makeatother
\begin{document}
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}.
\end{document}
You can now set the vertical and horizontal alignment within \dual
(default is c
enter 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
.
What that is, eventually, is a vertical box which has horizontal boxes inside, so (in plain-tex; compile with tex
/pdftex
/xetex
/luatex
):
\catcode`/=13
\def/#1/#2/{\leavevmode$\vcenter{\hbox{#1}\hbox{#2}}$}
If you walk , you will see a /left/right/, you will see a /house/boat/ with an
old /man/a cat/.
\bye