我正在尝试定义一个上面带有美元符号的漂亮箭头(不要太小以确保易于阅读,也不要太大以确保不会过多改变行高)。
我想到了下面的解决方案,但我遇到了一个问题:在下标中,我的字体没有变化,这意味着我的美元在下标中太大(美元超出了 的顶部{
)。此外,在下标版本中,我的箭头前后的间距看起来有点小:
有没有办法定义我的符号,使其在下标和普通文本中看起来(按比例)相同?
梅威瑟:
\documentclass[]{article}
\usepackage{amsmath}
\newcommand\sample{\mathrel{\overset{\vbox to.7ex{\hbox{\fontsize{6}{0}\selectfont\vspace{.5ex} \$}}}{\leftarrow}}}
\begin{document}
\section{Introduction}
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello $b \sample \{0,1\}$ Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
Here is an equation:
\begin{align}
b \sample \{0,1\}
\end{align}
Another
\begin{align}
\Pr_{b \sample \{0,1\}}{1=1}
\end{align}
And the final one $\Pr_{b \sample \{0,1\}}{1=1}$.
\end{document}
答案1
我最喜欢的游乐场,即\ooalign
:
\documentclass[twocolumn]{article} % twocolumn just for smaller picture
\usepackage{amsmath}
\makeatletter
\newcommand{\sample}{\mathrel{\mathpalette\sample@\relax}}
\newcommand{\sample@}[2]{%
\ooalign{%
\hfil\raisebox{0.7\height}{$\m@th\demotestyle{#1}\mathdollar$}\cr
$\m@th#1\leftarrow$\cr
}%
}
\newcommand{\demotestyle}[1]{%
\ifx#1\displaystyle\scriptstyle\else
\ifx#1\textstyle\scriptstyle\else
\scriptscriptstyle\fi\fi
}
\makeatother
\begin{document}
Here is an equation:
\begin{equation*}
b \sample \{0,1\}
\end{equation*}
Another
\begin{equation*}
\Pr_{b \sample \{0,1\}}{1=1}
\end{equation*}
And the final one $\Pr_{b \sample \{0,1\}}{1=1}$.
\end{document}