9

Sometimes I need to type an arrow between nouns in my text, e.g.:

Foo $\rightarrow$ Bar $\rightarrow$ Baz

Is there any way to adjust the length of the arrow? I have tried with \scalebox but it also shrinks it vertically, while all I want is to control its length.

  • 2
    You could use \xrightarrow{\hspace{2cm}} (requires amsmath) which gives an arrow a bit longer than 2cm. Do you know about \longrightarrow? – egreg Sep 28 '15 at 14:12
  • Thanks @egreg That's good to know! I actually want it shorter than \rightarrow I will try the solution with \xrightarrow – Amelio Vazquez-Reina Sep 28 '15 at 14:25
  • 1
    No, shorter arrows are not available (if you don't find a font that has shorter arrows or make them with TikZ) – egreg Sep 28 '15 at 14:27

3 Answers3

13

enter image description here

\documentclass[12pt]{article}
\begin{document}

Foo vv \parbox{.5cm}{\rightarrowfill} Bar $\rightarrow$ Baz

\end{document}

For lengths shorter than the default \rightarrow, you can go to TikZ:

\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}

\newcommand{\Arrow}[1]{%
\parbox{#1}{\tikz{\draw[->](0,0)--(#1,0);}}
}

Foo \Arrow{.1cm}Bar $\rightarrow$ Baz

\end{document}

enter image description here

Too many other arrow tips available to use with TikZ are possible, but, after all I suspect these tiny arrows will be readable.

AboAmmar
  • 46,352
  • 4
  • 58
  • 127
  • Thanks @AboAmmar. I just tried this with a very short arrow (0.1cm), but I still get the same length as the default $\rightarrow$. Hmm. – Amelio Vazquez-Reina Sep 28 '15 at 14:43
  • @AmelioVazquez-Reina -- as egreg commented on your question, there are no shorter horizontal arrows in the computer modern fonts. there are shorter vertical arrows that could possibly be rotated 90 degrees, but that's a nuisance. however, there are matching arrowheads in the lasy font that might be made use of. – barbara beeton Sep 28 '15 at 15:31
  • Why \parbox? I'd use \makebox, instead, with a proper setting for the baseline. – egreg Sep 28 '15 at 17:20
  • @egreg That's exactly why I avoid makebox; height adjustment. I used \raisebox{.5\ht\strutbox} but it's higher than it should be. How much should I raise this? – AboAmmar Sep 28 '15 at 17:26
  • 1
    \makeatletter \DeclareRobustCommand{\Arrow}[1]{% \check@mathfonts \raisebox{\fontdimen22\textfont2}{\tikz{\draw[->](0,0)--(#1,0);}}% } \makeatother (You should be able to guess the line breaks.) – egreg Sep 28 '15 at 17:30
  • What egreg says, plus \usetikzlibrary{arrows.meta} would be certainly good. – Manuel Sep 28 '15 at 17:42
2

Implementing the suggestion by Barbara Beeton of using the arrow head in the lasy fonts, which is however smaller than the standard arrow head of \rightarrow. It shouldn't be a problem if you always use \Arrow.

\documentclass[12pt]{article}
\usepackage{pict2e,picture}

\makeatletter
\DeclareRobustCommand{\Arrow}[1][]{%
  \check@mathfonts
  \if\relax\detokenize{#1}\relax
    \settowidth{\dimen@}{$\m@th\rightarrow$}%
  \else
    \setlength{\dimen@}{#1}%
  \fi
  \sbox\z@{\usefont{U}{lasy}{m}{n}\symbol{41}}%
  \begin{picture}(\dimen@,\ht\z@)
  \roundcap
  \put(\dimexpr\dimen@-.7\wd\z@,0){\usebox\z@}
  \put(0,\fontdimen22\textfont2){\line(1,0){\dimen@}}
  \end{picture}%
}
\makeatother

\begin{document}

Foo \Arrow[.1cm] Bar $\rightarrow$ Baz

\Arrow\Arrow[1cm]\Arrow[.5cm]

$\rightarrow$

\end{document}

enter image description here

egreg
  • 1,121,712
1

Here is a light weight approach, using no packages, and not even picture environment.

\documentclass{article}

\newcommand{\myarrow}[1][1cm]{\mathrel{%
   \hbox{\rule[\dimexpr\fontdimen22\textfont2-.2pt\relax]{#1}{.4pt}}%
   \mkern-4mu\hbox{\usefont{U}{lasy}{m}{n}\symbol{41}}}}

\makeatletter

\setbox0\hbox{$\xdef\scriptratio{\strip@pt\dimexpr
    \numexpr(\sf@size*65536)/\f@size sp}$}

\newcommand{\myscriptarrow}[1][1cm]{{%
    \hbox{\rule[\scriptratio\dimexpr\fontdimen22\textfont2-.2pt\relax]
               {\scriptratio\dimexpr#1\relax}{\scriptratio\dimexpr.4pt\relax}}%
   \mkern-4mu\hbox{\let\f@size\sf@size\usefont{U}{lasy}{m}{n}\symbol{41}}}}

\makeatother

\begin{document}

\[x-a\myarrow b_{c\myscriptarrow d-e}-f\]
\[x-a\myarrow[.5cm] b_{c\myscriptarrow[.5cm] d-e}-f\]
\[x-a\myarrow[1mm] b_{c\myscriptarrow[1mm] d-e}-f\]

\end{document}

enter image description here

As in other answers it implements @BarbaraBeeton's suggestion of using the arrow head in the lasy fonts. The length parameter or \myscriptarrow is automatically scaled, so it should be same as for \myarrow.


Equivalent result is obtained via shorter code which employs \vcenter:

\documentclass{article}

\newcommand{\myarrow}[1][1cm]{\mathrel{%
   \vcenter{\hbox{\rule[-.2pt]{#1}{.4pt}}}%
   \mkern-4mu\hbox{\usefont{U}{lasy}{m}{n}\symbol{41}}}}

\makeatletter

\setbox0\hbox{$\xdef\scriptratio{\strip@pt\dimexpr
    \numexpr(\sf@size*65536)/\f@size sp}$}

\newcommand{\myscriptarrow}[1][1cm]{{%
    \vcenter{\hbox{\rule[\scriptratio\dimexpr-.2pt\relax]
               {\scriptratio\dimexpr#1\relax}{\scriptratio\dimexpr.4pt\relax}}}%
   \mkern-4mu\hbox{\let\f@size\sf@size\usefont{U}{lasy}{m}{n}\symbol{41}}}}

\makeatother

\begin{document}

\[x-a\myarrow b_{c\myscriptarrow d-e}-f\]
\[x-a\myarrow[.5cm] b_{c\myscriptarrow[.5cm] d-e}-f\]
\[x-a\myarrow[1mm] b_{c\myscriptarrow[1mm] d-e}-f\]
\end{document}

The \myscriptarrow could use \mathrel. The sole effect (in script style for which it is destined) would be to suppress the small space separating from alarge symbol (\sum, \prod, ...) either immediately preceding or following.

The code for \myscriptarrow can be simplified if one removes the two \scriptratio which scale the rule thickness and vertical shift for centering (the one scaling the width must stay).


A better choice perhaps for the thickness is to use \fontdimen8 of the extension font.

\documentclass{article}

\newcommand{\myarrow}[1][1cm]{\mathrel{%
   \vcenter{\hbox{\rule[-.5\fontdimen8\textfont3]{#1}{\fontdimen8\textfont3}}}%
   \mkern-4mu\hbox{\usefont{U}{lasy}{m}{n}\symbol{41}}}}

\makeatletter

\setbox0\hbox{$\xdef\scriptratio{\strip@pt\dimexpr
    \numexpr(\sf@size*65536)/\f@size sp}$}

\newcommand{\myscriptarrow}[1][1cm]{{%
    \vcenter{\hbox{\rule[-.5\fontdimen8\scriptfont3]
               {\scriptratio\dimexpr#1\relax}{\fontdimen8\scriptfont3}}}%
   \mkern-4mu\hbox{\let\f@size\sf@size\usefont{U}{lasy}{m}{n}\symbol{41}}}}

\makeatother

\begin{document}

\[x-a\myarrow b_{c\myscriptarrow d-e}-f\]
\[x-a\myarrow[.5cm] b_{c\myscriptarrow[.5cm] d-e}-f\]
\[x-a\myarrow[1mm] b_{c\myscriptarrow[1mm] d-e}-f\]
\end{document}

enter image description here

  • I am not sure I should actually use the [-.5\fontdimen8\textfont3] for the rule positioning. 2) in last version, the \scriptratio serves only for scaling width. It could be dropped then optional parameter gives exact width of script arrow.
  • –  Oct 07 '17 at 22:25