[Tex/LaTex] Can one break stackrel text into multiple lines

stacking-symbols

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}

Best Answer

\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}

enter image description here

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

Related Question