I need to define a new command to create a squiggle arrow with some text on it. Something similar to what \xrightarrow
command produces but with wiggly arrows as in \rightsquigarrow
. The length of the arrow should automatically be adjusted to fit the text above it and I do not know how to handle this part in TikZ. Any ideas would be much appreciated.
1 Answer
As percusse mentions in his comment, you can use a node and a decorated arrow; something like this:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,shapes}
\newcounter{sarrow}
\newcommand\xrsquigarrow[1]{%
\stepcounter{sarrow}%
\begin{tikzpicture}[decoration=snake]
\node (\thesarrow) {\strut#1};
\draw[->,decorate] (\thesarrow.south west) -- (\thesarrow.south east);
\end{tikzpicture}%
}
\begin{document}
\xrsquigarrow{text}\quad\xrsquigarrow{longer text}
\end{document}
The following code contains a new version of \xrsquigarrow
using the zigzag
decoration and \mathrel
to be used in math-mode; it shows a comparison between \xrightarrow
, \rightsquigarrow
and \xrsquigarrow
(some fine-tuning is still required, but I leave that to you):
\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathmorphing,shapes}
\newcounter{sarrow}
\newcommand\xrsquigarrow[1]{%
\stepcounter{sarrow}%
\mathrel{\begin{tikzpicture}[baseline= {( $ (current bounding box.south) + (0,-0.5ex) $ )}]
\node[inner sep=.5ex] (\thesarrow) {$\scriptstyle #1$};
\path[draw,<-,decorate,
decoration={zigzag,amplitude=0.7pt,segment length=1.2mm,pre=lineto,pre length=4pt}]
(\thesarrow.south east) -- (\thesarrow.south west);
\end{tikzpicture}}%
}
\begin{document}
\[
A\xrightarrow{f} B\quad A\rightsquigarrow B\quad A\xrsquigarrow{f}B\quad A\xrsquigarrow{(f\circ g)\circ h}B
\]
\end{document}
This definition does not cover the case in which the arrow is to be used in super/sub-scripts.
-
Thanks, Gonzalo! This is very similar to what I had in mind. The only difference is the shape of the arrow that does not exactly look like
\rightsquigarrow
. This is important since I want to use the command in math mode and thus, it has to have a clean look. For example, $s \xsquigarrow{OR} t$ means a special operation between $s$ and $t$. The way you have defined the command does not produce a neat output in this setting. I am under impression that the wiggle type must have something to do with the "segment amplitude" and "segment length" of the arrow. Do you have any idea for fixing this?– AliCommented Jun 18, 2012 at 2:35 -
1@Ali in this case, use the
zigzag
decoration and appropriate values foramplitude
andsegment length
; I'll give an example in some minutes. Commented Jun 18, 2012 at 2:50 -
I customized your command as follows:
\newcounter{sarrow} \newcommand\xrsquigarrow[1]{% \stepcounter{sarrow}% \begin{tikzpicture} \node[scale=0.5] (\thesarrow) {\mathstrut#1}; \draw[->,snake=zigzag,segment amplitude=.3mm,segment length=1.3mm,line after snake=.9mm] (\thesarrow.south west) -- (\thesarrow.south east); \end{tikzpicture}% }
This almost produces the right output in math mode, e.g., $s \xrsquigarrow{OR} t$. I am just wondering how I can add some free space between the math symbols and the arrow? Thanks again.– AliCommented Jun 18, 2012 at 3:19 -
1
-
4Why is the counter needed for the node name? I seem to be able to replace the node name with a fixed value and everything still works. Commented Feb 6, 2014 at 14:16
(nodename.south west)
to(nodename.south east)
with a little extra adjustment (Check the manual page 49) but why do you need TikZ for this? Is there any disadvantage of the ones you mentioned?\xrightsquigarrow
.\longrightsquigarrow
althoughx
would seem more "traditional" thanlong
under the circumstances.