I know it's possible to have \xrightarrow (text)
, but if I try to do \xRightarrow (text)
I get an error each time. Does anybody know if it's a syntax error or if there is a other way to produce the \Rightarrow
with text above?
[Tex/LaTex] \xRightarrow (text)
amsmatharrowsmath-mode
Related Solutions
I wrote some functions that allow to lower/raise the text under/above xrightarrow
arrows. It seams that the text typeset using these macros is a little wider but it doesn't look too bad ;)
The code required is:
\usepackage{ifthen}
\usepackage{xargs}
\newcommandx{\yaHelper}[2][1=\empty]{%
\ifthenelse{\equal{#1}{\empty}}%
{ \ensuremath{ \scriptstyle{ #2 } } } % no offset
{ \raisebox{ #1 }[0pt][0pt]{ \ensuremath{ \scriptstyle{ #2 } } } } % with offset
}
\newcommandx{\yrightarrow}[4][1=\empty, 2=\empty, 4=\empty, usedefault=@]{%
\ifthenelse{\equal{#2}{\empty}}
{ \xrightarrow{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's no text below
{ \xrightarrow[ \protect{ \yaHelper[ #2 ]{ #1 } } ]{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's text below
}
\newcommandx{\yleftarrow}[4][1=\empty, 2=\empty, 4=\empty, usedefault=@]{%
\ifthenelse{\equal{#2}{\empty}}
{ \xleftarrow{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's no text below
{ \xleftarrow[ \protect{ \yaHelper[ #2 ]{ #1 } } ]{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's text below
}
\newcommandx{\yRightarrow}[4][1=\empty, 2=\empty, 4=\empty, usedefault=@]{%
\ifthenelse{\equal{#2}{\empty}}
{ \xRightarrow{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's no text below
{ \xRightarrow[ \protect{ \yaHelper[ #2 ]{ #1 } } ]{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's text below
}
\newcommandx{\yLeftarrow}[4][1=\empty, 2=\empty, 4=\empty, usedefault=@]{%
\ifthenelse{\equal{#2}{\empty}}
{ \xLeftarrow{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's no text below
{ \xLeftarrow[ \protect{ \yaHelper[ #2 ]{ #1 } } ]{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's text below
}
Usage is: yrightarrow[<TEXT-BELOW>][<OFFSET-BELOW>]{<TEXT-ABOVE>}[<OFFSET-ABOVE>}
and similarly for the others.
A working minimal example looks like this:
\documentclass{minimal}
\usepackage{amsmath}
\usepackage{ifthen}
\usepackage{xargs}
\newcommandx{\yaHelper}[2][1=\empty]{%
\ifthenelse{\equal{#1}{\empty}}%
{ \ensuremath{ \scriptstyle{ #2 } } } % no offset
{ \raisebox{ #1 }[0pt][0pt]{ \ensuremath{ \scriptstyle{ #2 } } } } % with offset
}
\newcommandx{\yrightarrow}[4][1=\empty, 2=\empty, 4=\empty, usedefault=@]{%
\ifthenelse{\equal{#2}{\empty}}
{ \xrightarrow{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's no text below
{ \xrightarrow[ \protect{ \yaHelper[ #2 ]{ #1 } } ]{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's text below
}
\begin{document}
\begin{align*}
A \yrightarrow{\pi \, \text{s.d.r.}}[-2pt] B \, , \: C \yrightarrow[\pi \, \text{s.d.r.}][4pt]{\pi \, \text{s.d.r.}}[-2pt] D
\end{align*}
\end{document}
However, this seems to be a brute force approach and I don't know whether there may be any side-effects (also I'm not doing any math-size checks, the stuff above and below the arrow will be always set in scriptstyle
). And of course it is a "dumb" solution because one has to determine the offset manually. And finally there's no support for the feature suggested by the fifth image.
I'd advise you to accept this answer not (yet) because I hope that somebody can provide a better solution (hopefully including the feature suggested by the fifth image, which possibly could be achieved by printing first the content with a slightly larger font and white colour and then overprint the actual content in black).
I provide a solution with use of tikz-cd. This is easy but will not expand automatically. Just edit the [column sep=4.5em]
to your needs.
As you had problems with Gonzalo's code, I adapted it slightly for you. Should work now. However, you will not be able to set the label below the arrow. If you are good in TikZ, you may define more commands like this or set optional parameters in order to modify the placement.
% arara: pdflatex
\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz-cd}
\usetikzlibrary{decorations.pathmorphing}
% code from Gonzalo
\newcommand\xrsquigarrow[1]{%
\mathrel{%
\begin{tikzpicture}[%
baseline={(current bounding box.south)}
]
\node[%
,inner sep=.44ex
,align=center
] (tmp) {$\scriptstyle #1$};
\path[%
,draw,<-
,decorate,decoration={%
,zigzag
,amplitude=0.7pt
,segment length=1.2mm,pre length=3.5pt
}
]
(tmp.south east) -- (tmp.south west);
\end{tikzpicture}
}
}
\newcommand\xlsquigarrow[1]{%
\mathrel{%
\begin{tikzpicture}[%
,baseline={(current bounding box.south)}
]
\node[%
,inner sep=.44ex
,align=center
] (tmp) {$\scriptstyle #1$};
\path[%
,draw,<-
,decorate,decoration={%
,zigzag
,amplitude=0.7pt
,segment length=1.2mm,pre length=3.5pt
}
]
(tmp.south west) -- (tmp.south east);
\end{tikzpicture}
}
}
\begin{document}
\[\begin{tikzcd}[column sep=4.5em]
A\arrow[leftsquigarrow]{r}{\text{this way}}
& B\arrow[rightsquigarrow]{r}[swap]{\text{or that way}}
& C
\end{tikzcd}\]
\[
A \xleftarrow{\text{this way}} B
\xrightarrow[\text{or that way}]{} C
\]
\[
A \xlsquigarrow{\text{this way}} B
\xrsquigarrow{\text{or that way}} C
\]
\end{document}
Best Answer
Just taking the definition of
\xrightarrow
and replacingr
byR
: