21

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.

5
  • 2
    You can put your node and decorate a regular arrow going from (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?
    – percusse
    Jun 18, 2012 at 1:17
  • 1
    @percusse: I guess there is no \xrightsquigarrow.
    – Caramdir
    Jun 18, 2012 at 1:59
  • @Caramdir Aha, that explains it :)
    – percusse
    Jun 18, 2012 at 2:02
  • Related: Squiggly arrows in tikz
    – Jake
    Jun 18, 2012 at 4:34
  • this arrow is in unicode at U+27FF, so it should be in the stix and xits fonts. the reference i have available gives it the name \longrightsquigarrow although x would seem more "traditional" than long under the circumstances. Dec 10, 2013 at 22:17

1 Answer 1

28

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}

enter image description here

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}

enter image description here

This definition does not cover the case in which the arrow is to be used in super/sub-scripts.

5
  • 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?
    – Ali
    Jun 18, 2012 at 2:35
  • 1
    @Ali in this case, use the zigzag decoration and appropriate values for amplitude and segment length; I'll give an example in some minutes. 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.
    – Ali
    Jun 18, 2012 at 3:19
  • 1
    @Ali please see my updated answer. Jun 18, 2012 at 3:23
  • 4
    Why 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. Feb 6, 2014 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .