# Can one break stackrel text into multiple lines?

I'm writing something up where I want to be explicit about some elementary operations I'm performing. I have an arrow between matrices with some text above the arrow showing what I'm doing. The text above the arrow is quite long, is it possible to cause a line break of some sort in stackrel?

My code is the following:

\stackrel{R2:= R2-2R1,\ R3:= R3+2R1}{\longrightarrow}

• Could you show how you intend to use it? Perhaps even including some mock-up of the expected output.
– Werner
Jan 31 '14 at 4:27

\substack or subarray are your friends.

I suggest two commands, one for centered alignment of the elementary operation denotations, one for left alignment, that you might prefer.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\elem}[1]{% elementary operations
\xrightarrow{\substack{#1}}%
}

\newcommand{\lelem}[1]{% elementary operations (left alignment)
\xrightarrow{\begin{subarray}{l}#1\end{subarray}}%
}

\begin{document}

$\elem{R2:= R2-2R1,\\ R3:= R3+2R1}\quad \lelem{R2:= R2-2R1,\\ R3:= R3+2R1}$

\end{document}


There's no need to have multiple lines: \elem{R2:=R2-2R1} would work seamlessly.

What is wrong with substack?

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\stackrel{\substack{R2:= R2-2R1,\\ R3:= R3+2R1}}{\longrightarrow}$
\end{document}


• The first is of course wrong. Jan 31 '14 at 11:18
• The vertical alignment will be completely wrong. Jan 31 '14 at 22:19

Perhaps a combination of \overset and \shortstack?

\documentclass{article}
\usepackage{amsmath}

\begin{document}

$\overset{\shortstack{\scriptstyle R2:= R2-2R1,\\ \scriptstyle R3:= R3+2R1}}{\longrightarrow}\quad \overset{\shortstack[l]{\scriptstyle R2:= R2-2R1,\\ \scriptstyle R3:= R3+2R1}}{\longrightarrow}$

\end{document}


The optional argument for \shortstack allows you to control the alignment.