如何在同一個地方寫兩個字元?
特別是,我想寫一個箭頭$\rightarrow$
,然後寫一個字母,讓箭頭穿過字母。我發現了一些類似的問題(字元上的範圍符號,將一個字元替換為另一個字元 (Lualatex)等等)但它們並不是完全相同的問題。
答案1
不清楚你想要的是文字還是數學...
\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}
另外,尚不清楚您是否希望考慮箭頭的寬度:
\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}
上面可以輕鬆調整的其他內容包括水平對齊(目前居中)以及箭頭放置的垂直高度(目前放置在其自然高度)。
一旦決定了用例的具體細節,就可以輕鬆地將其封裝在巨集中。
下面,跟上egregs的步伐,我\overarrow
為數學實現了一個巨集版本(),保留了數學風格:
\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}
答案2
答案3
這是兩個版本的文字:
\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}
對於數學:
\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}
答案4
如果您想要一點靈活性,並且需要箭頭來調整其所經過的內容的寬度,您可能需要使用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}