# Arrow with plus/minus sign on top

Below you can see an arrow with a plus and a minus sign on top of it. How is this achievable in latex? Further possibilities: arrow with only plus and arrow with only minus sign on top. How can I do this?

• Is $\xrightarrow{+/-}$ (or $\xrightarrow{+}$ or $\xrightarrow{-}$) what you want? You can use one of the commands here to make the plus/minus sign smaller. – moewe Sep 22 '13 at 10:54

## \stackrel

LaTeX provides \stackrel to place something on a relational operator:

\documentclass{article}

\begin{document}
$A \stackrel{+/-}\longrightarrow B \stackrel{+}\rightarrow C \stackrel{-}\rightarrow D$
\end{document}


• However the arrow is too short for the first case with +/-.
• The plus/minus signs are perfectly horizontally centered, but it does not look too good because of the arrow tip. The plus/minus signs should be moved to the left a little.

## \xrightarrow

Package amsmath addresses the previous problems by providing extensible arrows:

\xrightarrow[<below>]{<above>}


The length of the arrow grows with width of the annotations below or above. The arrow tip is taken into account.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
$A \xrightarrow{+/-} B \xrightarrow{+} C \xrightarrow{-} D$
\end{document}


But there is room for improvement:

• The minus and plus sign start and end with a horizontal line, thus the extra space of the arrow to the left and right can be reduced a little.
\documentclass{article}
\usepackage{amsmath}

\newcommand*{\rightarrowpm}[1]{%
\xrightarrow{\!#1\!}%
}

\begin{document}
$A \rightarrowpm{+/-} B \rightarrowpm{+} C \rightarrowpm{-} D$
\end{document}


If the size of the plus and minus signs are too large, then \scriptscriptstyle can be added:

\documentclass{article}
\usepackage{amsmath}

\newcommand*{\rightarrowpm}[1]{%
\xrightarrow{\scriptscriptstyle\!#1\!}%
}

\begin{document}
$A \rightarrowpm{+/-} B \rightarrowpm{+} C \rightarrowpm{-} D$
\end{document}


## Scalable \xrightarrow

\xrightarrow of amsmath does not resize automatically with different math styles. The last example redefines \ext@arrow for \rightarrowpm to make it scalable according to the current math style. A smaller style than \scriptscriptstyle is achieved by scaling to 90%.

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}

\makeatletter
\newcommand*{\rightarrowpm}[1]{%
\begingroup
\let\ext@arrow\ext@arrow@scalable
\xrightarrow{\scriptscriptstyle\!#1\!}%
\endgroup
}
\newcommand*{\ext@arrow@scalable}[7]{%
\mathrel{%
\mathpalette{\@ext@arrow@scalable{#1}{#2}{#3}{#4}{#5}{#6}{#7}}{}%
}%
}
\newcommand*{\@ext@arrow@scalable}[8]{%
\mathop{%
\setbox\z@\hbox{#5#8}%
\setbox\tw@\vbox{%
\m@th
\ifx#8\scriptscriptstyle
\let\my@hbox\hbox@scriptscriptscaled
\else
\let\my@hbox\hbox@math
\fi
\my@hbox{%
\ifx#8\scriptstyle\scriptscriptstyle\else\scriptstyle\fi
\mkern#3mu{#6}\mkern#4mu%
}%
\my@hbox{%
\ifx#8\scriptstyle\scriptscriptstyle\else\scriptstyle\fi
\mkern#3mu{#7}\mkern#4mu%
}%
\copy\z@
}%
\hbox to\wd\tw@{\unhbox\z@}}%
\limits
\@ifnotempty{#7}{%
^{%
\ifx#8\scriptscriptstyle
\expandafter\hbox@scriptscriptscaled
\else
\expandafter\@firstofone
\fi
{%
\if0#1\else\mkern#1mu\fi
#7%
\if0#2\else\mkern#2mu\fi
}%
}%
}%
\@ifnotempty{#6}{%
_{%
\ifx#8\scriptscriptstyle
\expandafter\hbox@scriptscriptscaled
\else
\expandafter\@firstofone
\fi
{%
\if0#1\else\mkern#1mu\fi
#6%
\if0#2\else\mkern#2mu\fi
}%
}%
}%
}

\newcommand*{\hbox@scriptscriptscaled}[1]{%
\hbox{%
\scalebox{.9}{$\scriptscriptstyle#1\m@th$}%
}%
}
\newcommand*{\hbox@math}[1]{%
\hbox{$#1\m@th$}%
}
\makeatother

\begin{document}
$A \rightarrowpm{+/-} B^{A\rightarrowpm{+/-}B^{A\rightarrowpm{+/-}B}}$
\end{document}


Package amsmath provides \overset to put something over a binary or relational operator:

\overset{+/-}{\longrightarrow}


• Could the downvoter please add a reason for this? – Joseph Wright Sep 22 '13 at 11:26
• @JosephWright: Possible (I have not voted) reasons: (1) Package amsmath is missing that provides \overset. (2) The annotation above the arrow exceeds the arrow width. (3) The size of the symbols above the arrow might be too large. – Heiko Oberdiek Sep 22 '13 at 11:33
• I don't know but I upvoted you :-) – tester Sep 22 '13 at 11:48

If you prefer an auto-size solution, use amsmath's \xrightarrow{}.

$\xrightarrow{+/-}$


If you want smaller +/- signs you can use $\xrightarrow{\scriptscriptstyle +/-}$

\documentclass{standalone}
\usepackage{amsmath}
\begin{document}
$\xrightarrow{+/-}$
$\xrightarrow{\scriptscriptstyle +/-}$

$\xrightarrow{+}$
$\xrightarrow{\scriptscriptstyle +}$
\end{document}


gives