如何强制字符间距?
我尝试使用零宽度框,但其内容会向左移动(不确定原因)。
\documentclass{minimal}\usepackage{fancyvrb}\textwidth=9cm
\begin{document}
\begin{Verbatim}[commandchars=\\\{\}, codes={\catcode`$=3\catcode`^=7}]
L = F(x, y) % align to this
$\mathcal{L}$ = F(x, y).mean() % $\mathcal{L}$ takes too much space
\makebox[0pt]{$\mathcal{L}$} = F(x, y).mean() % the zero box shifts left
\end{Verbatim}
\end{document}
答案1
您想要一个左对齐的 makebox(不居中)
\documentclass{minimal}\usepackage{fancyvrb}\textwidth=9cm
\begin{document}
\begin{Verbatim}[commandchars=\\\{\}, codes={\catcode`$=3\catcode`^=7}]
L = F(x, y) % align to this
\makebox[0pt][l]{$\mathcal{L}$} = F(x, y).mean() % the zero box shifts left
\end{Verbatim}
\end{document}
答案2
我更喜欢将字母空间居中(0.5em),但我还建议水平缩放符号。
\documentclass{article}
\usepackage{fancyvrb}
\usepackage{graphicx}
\makeatletter
\newcommand{\tcal}[1]{%
\sbox0{$\m@th\mathcal{#1}$}%
\scalebox{\fpeval{(0.5em)/(\wd0)}}[1]{\usebox0}%
}
\makeatother
\newcommand{\lcal}[1]{\makebox[0.5em][l]{$\mathcal{#1}$}}
\newcommand{\ccal}[1]{\makebox[0.5em]{$\mathcal{#1}$}}
\begin{document}
\begin{Verbatim}[commandchars=\\\{\}]
L = F(x, y)
\tcal{L} = F(x, y).mean()
\lcal{L} = F(x, y).mean()
\ccal{L} = F(x, y).mean()
\tcal{L}(x)+\tcal{Q}+x
\lcal{L}(x)+\lcal{Q}+y
\ccal{L}(x)+\ccal{Q}+z
\end{Verbatim}
\end{document}
比较输出并做出决定。