4

How can I write two characters in the same place?

In particular, I want to write an arrow $\rightarrow$, and then write a letter such that the arrow strikes through the letter. I found some similar questions (Range symbol over character, Substitute a character by another one (Lualatex), etc.) but they are not exactly the same question.

  • 5
    Since an arrow is wider than almost every character, what do you plan to do with the excess? – egreg Feb 19 at 13:45
  • A simple but probably naive way is \rlap{$\rightarrow$}x. Like egreg wrote, you need to figure out which way the excess should go. Note that the adjustbox package give further ways to lap content to all directions. – Martin Scharrer Feb 19 at 14:45
12

Not clear if you want it in text or math...

\documentclass{article}
\usepackage{stackengine}
\begin{document}
In te\stackengine{0pt}{x}{$\rightarrow$}{O}{c}{F}{T}{L}t...

$\ensurestackMath{\stackengine{0pt}{y}{\rightarrow}{O}{c}{F}{T}{L}} = mx + b$
\end{document}

enter image description here

Also, it is not clear if you want the arrow's width to be accounted for:

\documentclass{article}
\usepackage{stackengine}
\begin{document}
In te\stackengine{0pt}{x}{$\rightarrow$}{O}{c}{F}{F}{L}t...

$\ensurestackMath{\stackengine{0pt}{y}{\rightarrow\!}{O}{c}{F}{F}{L}} = mx + b$
\end{document}

enter image description here

Other things that can be easily adjusted above include horizontal alignment (currently centered) as well as vertical height of arrow placement (currently placed at its natural height).

Once the specifics are decided on the use case, this can be easily encapsulated in a macro.

Below, keeping up with the egregs, I implement a macro version (\overarrow) for math that preserves the math style:

\documentclass{article}
\usepackage{stackengine,scalerel}
\newcommand\overarrow[1]{\ThisStyle{\ensurestackMath{%
  \stackengine{0pt}{\SavedStyle#1}{\SavedStyle\rightarrow\!}{O}{c}{F}{F}{L}}}}
\begin{document}
$\overarrow{y} = mx_{\overarrow{z}} + b$
\end{document}

enter image description here

9

A simple \makebox[0pt]{..} can achieve this. Depending on your real use case, this may require a bit of tuning.

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

$\makebox[0pt][l]{$\rightarrow$}A$

\end{document}

enter image description here

7

Here's for text in two versions:

\documentclass{article}

\DeclareRobustCommand{\asA}[1]{% arrow strike
  \leavevmode\begingroup
  \vphantom{#1}%
  \ooalign{\hidewidth$\mathsurround0pt\rightarrow$\hidewidth\cr#1\cr}%
  \endgroup
}
\DeclareRobustCommand{\asB}[1]{% arrow strike
  \leavevmode\begingroup
  \vphantom{#1}%
  \ooalign{$\mathsurround0pt\rightarrow$\cr\hidewidth#1\hidewidth\cr}%
  \endgroup
}

\begin{document}

st\asA{r}uck

st\asB{r}uck

\end{document}

enter image description here

For math:

\documentclass{article}

\makeatletter
\DeclareRobustCommand{\as}[1]{% arrow strike
  {\vphantom{#1}\mathpalette\erel@as{#1}}%
}

\newcommand{\erel@as}[2]{%
  \ooalign{\hfil$\m@th#1\rightarrow$\hfil\cr\hfil$\m@th#1#2$\hfil\cr}%
}
\makeatother

\begin{document}

$a+\as{b}+c_{\as{x}}$

\end{document}

enter image description here

4

In case you want a bit of flexibility and the arrow to adjust to the width of the stuff it is running through, you may want to use tikzmark.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\newcounter{atm}
\newcommand{\arrowthrough}[2][]{\stepcounter{atm}\tikzmarknode[path picture={
\draw[->,#1] (path picture bounding box.west) --
(path picture bounding box.east);}]{atm-\theatm}{#2}}
\begin{document}
 \arrowthrough{x}
 \[ E=\arrowthrough{m}c^2\]
 \arrowthrough[red,-latex]{Hello} \arrowthrough[latex-,thick,blue]{World!}
\end{document}

enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.