# how to force text to write in two or more lines in overset command

I have the following code:

\documentclass[]{article}
\usepackage{amsmath}

\begin{document}

\begin{gather*}
\overset{-1*R_{4}\rightarrow R_{3} \\ -2*R_{4}\rightarrow R_{2} }{\rightarrow}
\end{gather*}

\end{document}


I get everything in one line over the arrow, but i need it to be in two lines as indicated by the line break \\.

You can use the subarray environment. To make the arrow as long as the text you can use \xrightarrow.

Code:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

With \verb|\rightarrow|:

$\overset{ \begin{subarray}{l} -1*R_{4}\rightarrow R_{3}\\ -2*R_{4}\rightarrow R_{2} \end{subarray} }{\rightarrow}$

With \verb|\xrightarrow|:

$\xrightarrow{ \begin{subarray}{l} -1*R_{4}\rightarrow R_{3}\\ -2*R_{4}\rightarrow R_{2} \end{subarray} }$

\end{document}


Result:

As you might have noticed from the answer above, spacing above the \rightarrow is an issue. My answer uses the substack command to achieve your stated aim of multiple lines, and a new macro found here for changing the space with overset.

Output:

MWE:

\documentclass[]{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\oset}[3][0ex]{%
\mathrel{\mathop{#3}\limits^{
\vbox to#1{\kern-2\ex@
\hbox{$\scriptstyle#2$}\vss}}}}
\makeatother

\begin{document}

\begin{gather*}
\oset[3ex]{\substack{-1*R_{4}\rightarrow R_{3} \\ -2*R_{4}\rightarrow R_{2} }}{\rightarrow}
\end{gather*}

\end{document}