5

I've made the equations align here using \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}

enter image description here

However, it's a bit of a hassle and it's not a very flexible method. I'd like something like \paddedtext{2em}{If} which takes the text If and adds horizontal space so that its width is 2em. Or some way to say "insert 2em minus the length of If".

H.v.M.
  • 303
  • 1
    Off-topic: Do change \renewcommand{\labelenumi}{(\roman{enumi})} to \renewcommand{\labelenumi}{\upshape(\roman{enumi})}. That way, (i), (ii) etc will be rendered in the upright font shape, making them look more "structural" and less like part of the running text. – Mico Jun 09 '21 at 06:37

3 Answers3

6

This seems like an ideal job for eqparbox, since it's flexible for variable content: \eqmakebox[<tag>][<align>]{<stuff>} sets <stuff> in a box that is widest across the same <tag> with a specific <align>ment (left, right or centre).

enter image description here

\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&quot;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 uses a \label-\ref-like system to capture the widths and therefore require multiple compilations with any change of the widest element by <tag>.

Werner
  • 603,163
  • It doesn't compile for me. The preamble generates errors: "You can't use `macro parameter character #' in math mode. \mathpalette\eqmathbox@{#3}", "Undefined control sequence. \NewDocumentCommand", "Parameters must be numbered consecutively. {\def\eqmathbox@##" etc – H.v.M. Jun 09 '21 at 08:16
  • 1
    @Blrp: This is because you don't have an up-to-date LaTeX. So you need to add \usepackage{xparse} to your preamble before the definition of \eqmathbox. – Werner Jun 09 '21 at 15:22
3

While there may be a little overhead in guessing proper values for \tabA and \tabB, it remains efficient from a typing point of view. This uses the tabto package for tabbing.

\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}

enter image description here

3

Your \paddedtext{2em}{If} should be defined using TeX primitives like this:

\def\paddedtext#1#2{\leavevmode\hbox to#1{#2\hss}\ignorespaces}
wipet
  • 74,238