我使用以下方法使方程式对齐\hphantom{}
:
\begin{theorem}[Möbius inversion]
Let $n \in \mathbb{Z}^+$, and let $g$ and $h$ be complex-valued functions defined on $\mathbb{Z}^+$ or on the set of divisors of $n$.
\renewcommand{\labelenumi}{(\roman{enumi})}
\begin{enumerate}
\item If\hphantom{then} $\displaystyle h(k) = \sum\limits_{d \mid k} g(d) \hphantom{\mu(k/d)}$ \quad for all $k$, \\\\
then\hphantom{If} $\displaystyle g(k) = \sum\limits_{d \mid k} \mu(k/d) h(d)$ \quad for all $k$. \\
\item If\hphantom{then} $\displaystyle h(k) = \sum\limits_{k \mid d \mid n} g(d) \hphantom{\mu(d/k)}$ \quad for all $k$, \\\\
then\hphantom{If} $\displaystyle g(k) = \sum\limits_{k \mid d \mid n} \mu(d/k) h(d)$ \quad for all $k$.
\end{enumerate}
\end{theorem}
但是,这有点麻烦,而且不是一种非常灵活的方法。我想要类似这样的方法,\paddedtext{2em}{If}
它获取文本If
并添加水平空间,使其宽度为2em
。或者某种方式说“插入 2em 减去 If 的长度”。
答案1
虽然猜测\tabA
和的正确值可能会有点开销\tabB
,但从输入的角度来看它仍然很高效。这使用tabto
包进行制表。
\documentclass{article}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{tabto}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}[M\"obius inversion]
Let $n \in \mathbb{Z}^+$, and let~$g$ and~$h$ be complex-valued functions defined on $\mathbb{Z}^+$ or on the set of divisors of~$n$.
\renewcommand{\labelenumi}{(\roman{enumi})}
\newcommand\tabA{\tabto{.35in}}
\newcommand\tabB{\tabto{1.8in}}
\begin{enumerate}
\item If\tabA $\displaystyle h(k) =
\sum\limits_{d \mid k} g(d)$\tabB for all $k$,
then\tabA $\displaystyle g(k) =
\sum\limits_{d \mid k} \mu(k/d) h(d)$\tabB for all $k$.
\item If\tabA $\displaystyle h(k) =
\sum\limits_{k \mid d \mid n} g(d)$\tabB for all $k$,
then\tabA $\displaystyle g(k) =
\sum\limits_{k \mid d \mid n} \mu(d/k) h(d)$\tabB for all $k$.
\end{enumerate}
\end{theorem}
\end{document}
答案2
这似乎是eqparbox
,因为它可以灵活地容纳可变的内容:在最宽的框中\eqmakebox[<tag>][<align>]{<stuff>}
设置特定的ment(eft、ight 或entre)。<stuff>
<tag>
<align>
l
r
c
\documentclass{article}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{eqparbox}
\newtheorem{theorem}{Theorem}
% https://tex.stackexchange.com/a/34412/5764
\makeatletter
\NewDocumentCommand{\eqmathbox}{o O{c} m}{%
\IfValueTF{#1}
{\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}}
{\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}}
\mathpalette\eqmathbox@{#3}
}
\makeatother
\begin{document}
\begin{theorem}[M\"obius inversion]
Let $n \in \mathbb{Z}^+$, and let~$g$ and~$h$ be complex-valued functions defined on $\mathbb{Z}^+$ or on the set of divisors of~$n$.
\renewcommand{\labelenumi}{(\roman{enumi})}
\begin{enumerate}
\item \eqmakebox[ifthen][l]{If} $\displaystyle \eqmathbox[hg][r]{h(k)} =
\eqmathbox[mobsum][l]{\sum\limits_{d \mid k} g(d)}$ for all $k$,
\eqmakebox[ifthen][l]{then} $\displaystyle \eqmathbox[hg][r]{g(k)} =
\eqmathbox[mobsum][l]{\sum\limits_{d \mid k} \mu(k/d) h(d)}$ for all~$k$.
\item \eqmakebox[ifthen][l]{If} $\displaystyle \eqmathbox[hg][r]{h(k)} =
\eqmathbox[mobsum][l]{\sum\limits_{k \mid d \mid n} g(d)}$ for all~$k$,
\eqmakebox[ifthen][l]{then} $\displaystyle \eqmathbox[hg][r]{g(k)} =
\eqmathbox[mobsum][l]{\sum\limits_{k \mid d \mid n} \mu(d/k) h(d)}$ for all~$k$.
\end{enumerate}
\end{theorem}
\end{document}
eqparbox
使用类似\label
-\ref
的系统来捕获宽度,因此对于最宽元素的任何更改都需要进行多次编译<tag>
。
答案3
你\paddedtext{2em}{If}
应该使用如下的 TeX 原语来定义:
\def\paddedtext#1#2{\leavevmode\hbox to#1{#2\hss}\ignorespaces}