对齐对齐方程

对齐对齐方程

我有一系列方程式,其中一些方程式有多个步骤,我已设法在各自的环境中对齐它们。但我希望每组方程式也通过“=”对齐,同时方程式右侧的注释也保持彼此对齐。

\documentclass[11pt]{article}
\usepackage{amsmath}    
\usepackage[makeroom]{cancel}
\begin{document}

\begin{align*} \tag{a}
Y = f(x_0) + \epsilon_0
    && \text{By assumptions}
\end{align*}
\begin{align*} \tag{c}
E\big[Y\big] & = E\big[f(x_0)+\epsilon_0\big]
    && \text{By (a)}
\\& = E\big[f(x_0)\big] + \cancel{E\big[\epsilon_0\big]}
    && \text{By Linearity}
\\&= E\big[f(x_0)\big]
    && \text{By Expectation of $\epsilon$}
\end{align*}
\begin{align*} \tag{e.i}
&E\big[f(x_0)] = f(x_0)
    && \text{As $x_0$ is fixed and deterministic}
\\&\text{$f(x_0)$ is constant.} \tag{e.ii}
\\&\text{$f(x_0)$ and $\hat{f}(x_0)$ are independent.} \tag{e.iii}
\end{align*}

\end{document}

我仍在学习 LateX,所以如果这很明显,我很抱歉。我非常感谢任何帮助,不要害怕解释小步骤,因为这确实有助于我的理解!提前感谢您的时间和帮助。

答案1

为了保持每个方程组的一致性,考虑使用相同的align结构:

enter image description here

\documentclass{article}

\usepackage{amsmath}
\usepackage[makeroom]{cancel}

\begin{document}

\begin{align}
  Y &= f(x_0) + \epsilon_0
      && \text{Assumption} \tag{a}\label{eq:a} \\
  E\bigl[ Y \bigr] &= E\bigl[ f(x_0) + \epsilon_0 \bigr]
      && \text{by \eqref{eq:a}} \tag{c} \\
    &= E\bigl[ f(x_0) \bigr] + \cancel{E\bigl[ \epsilon_0 \bigr]}
      && \text{by linearity} \notag \\
    &= E\bigl[ f(x_0) \bigr]
      && \text{by expectation of $\epsilon$} \notag \\
  E\bigl[ f(x_0) \bigr] &= f(x_0)
      && \text{$x_0$ is fixed \& deterministic} \tag{e.i} \\
  \makebox[0pt][l]{$f(x_0)$ is constant.}
    \phantom{E\bigl[ f(x_0) \bigr]} \tag{e.ii} \\
  \makebox[0pt][l]{$f(x_0)$ and $\hat{f}(x_0)$ are independent.}
    \phantom{E\bigl[ f(x_o) \bigr]} \tag{e.iii}
\end{align}

\end{document}

将最后两行设置在零宽度框中可以提供一些额外的空间,因为它们在右侧没有描述。

答案2

您可以alignat对最后两行使用一个小技巧。

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage[makeroom]{cancel}

\begin{document}

\begin{alignat*}{2}
\tag{a}
Y &= f(x_0) + \epsilon_0
    &\qquad& \text{By assumptions}
\\
\tag{c}
E[Y] & = E[f(x_0)+\epsilon_0]
    && \text{By (a)}
\\
& = E[f(x_0)] + \cancel{E[\epsilon_0]}
    && \text{By Linearity}
\\
& = E[f(x_0)]
    && \text{By Expectation of $\epsilon$}
\\
\tag{e.i}
E[f(x_0)] & = f(x_0)
    && \text{As $x_0$ is fixed and deterministic}
\\
\tag{e.ii}
&\settowidth{\dimen0}{$E[f(x_0)]$}
\makebox[0pt][l]{\hspace{-\dimen0}$f(x_0)$ is constant.}
\\
\tag{e.iii}
&\settowidth{\dimen0}{$E[f(x_0)]$}
\makebox[0pt][l]{\hspace{-\dimen0}$f(x_0)$ and $\hat{f}(x_0)$ are independent.}
\end{alignat*}

\end{document}

enter image description here

我删除了所有\big看起来没那么有用的命令。如果你喜欢更大的括号,它们应该是这样的E\bigl[Y\bigr],这样括号就会有它们适当的栅栏性质。

答案3

我不确定最后三个等式是否应该在标志上对齐=,因此我提出了两种略有不同的布局,基于alignat*

\documentclass[11pt]{article}
\usepackage{mathtools}
\usepackage[makeroom]{cancel}

\begin{document}

\begin{alignat*}{3} \tag{a}
   & & Y & = f(x_0) + \epsilon_0
   & & \text{by assumptions} \\
   & & E\big[Y\big] & = E\big[f(x_0)+\epsilon_0\big]\tag{c}
   & & \text{by (a)} \\
   & & & = E\big[f(x_0)\big] + \cancel{E\big[\epsilon_0\big]}
   & \qquad & \text{by linearity} \\
   & & & = E\big[f(x_0)\big]
   & & \text{by expectation of $\epsilon$} \\[1.5ex]
   & \mathrlap{E\big[f(x_0)] = f(x_0)}
   & & & & \text{as $x_0$ is fixed and deterministic}\tag{e.i} \\
   & \rlap{$f(x_0)$ is constant.} \tag{e.ii} \\
   & \rlap{$f(x_0)$ and $\hat{f}(x_0)$ are independent.} \tag{e.iii}
\end{alignat*}

\begin{alignat*}{3} \tag{a}
  Y & = & & f(x_0) + \epsilon_0
               & & \text{by assumptions} \\
  E\big[Y\big] & = {} & & E\big[f(x_0)+\epsilon_0\big]\tag{c}
               & & \text{by (a)} \\
               & = {} & & E\big[f(x_0)\big] + \cancel{E\big[\epsilon_0\big]}
               & \qquad & \text{by linearity} \\
               & ={} & & E\big[f(x_0)\big]
               & & \text{by expectation of $\epsilon$} \\[1.5ex]
               & & & \mathrlap{E\big[f(x_0)] = f(x_0)}
               & & \text{as $x_0$ is fixed and deterministic}\tag{e.i} \\
               & & & \rlap{$f(x_0)$ is constant.} \tag{e.ii} \\
               & & & \rlap{$f(x_0)$ and $\hat{f}(x_0)$ are independent.} \tag{e.iii}
\end{alignat*}

\end{document} 

enter image description here

答案4

enter image description here

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage[makeroom]{cancel}

\begin{document}

\begin{align*}
Y            & = f(x_0) + \epsilon_0 & & \text{By assumptions} \tag{a} \\[2ex]
E\big[Y\big] & = E\big[f(x_0)+\epsilon_0\big] & & \text{By (a)} \tag{c} \\
             & = E\big[f(x_0)\big] + \cancel{E\big[\epsilon_0\big]} & & \text{By Linearity} \\
             & = E\big[f(x_0)\big] & & \text{By Expectation of $\epsilon$} \\[2ex]
E\big[f(x_0)] & = f(x_0) \tag{e.i} & &    \text{As $x_0$ is fixed and deterministic} \\
              & \phantom{xx} f(x_0) \text{ is constant.} \tag{e.ii} \\
              & \phantom{xx} f(x_0) \text{ and } \hat{f}(x_0) \text{ are independent.} \tag{e.iii}
\end{align*}

\end{document}

相关内容