我怎样才能分割和对齐这一系列方程式?

我怎样才能分割和对齐这一系列方程式?

我知道这是一个经常出现的问题,但是在使用所有建议的示例(breqn、amsmath;split、align 等)时我不断遇到问题。

以下是我所拥有的:

\documentclass[11pt]{article}
\usepackage[margin=1in,paperwidth=8.5in,paperheight=11in]{geometry}
\usepackage[shortlabels]{enumitem}
\usepackage{amsmath}
\usepackage{xfrac}
\usepackage{breqn}

\begin{document}

% << Other stuff that compiled fine. >>

\begin{enumerate}[(a)]

\item What is the global CPI for each implementation?

We can use this equation to find the overall CPI for each implementation:

\begin{equation}
\begin{align*}
CPI_{total} & = \frac{\sum (IIC) (CCI)}{IC} \\

CPI_{P1,total} &= 
\frac{(1 \times 10^5~class~instructions \cdot 1~\sfrac{cycle}{instruction}) \\+ 
(2 \times 10^5~class~instructions \cdot 2~\sfrac{cycles}{instruction}) \\+ 
(5 \times 10^5~class~instructions \cdot 3~\sfrac{cycles}{instruction}) \\+ 
(2 \times 10^5~class~instructions \cdot 3~\sfrac{cycles}{instruction})}
{1 \times 10^6~instructions} \\

& = 2.6~\sfrac{average~cycles}{instruction} \\

CPI_{P2,total} & = 
\frac{(1 \times 10^5~class~instructions \cdot 2~\sfrac{cycles}{instruction}) \\+ 
(2 \times 10^5~class~instructions \cdot 2~\sfrac{cycles}{instruction}) \\+ 
(5 \times 10^5~class~instructions \cdot 2~\sfrac{cycles}{instruction}) \\+ 
(2 \times 10^5~class~instructions \cdot 2~\sfrac{cycles}{instruction})}
{1 \times 10^6~instructions}

& = 2.0~\sfrac{average~cycles}{instruction} \\
\end{align*}
\end{equation}

% << More list items >>

\end{enumerate}
\end{document}

代码确实属于枚举列表,但注释掉列表似乎不会影响它。当删除拆分尝试并将它们与对齐时,代码也可以编译成功eqnarray

我收到一个Paragraph ended before \align was complete错误。

编辑:问题格式。

编辑2:进展!

splitfrac好的,经过一番搜索后我终于明白了如何使用\frac{ \splitfrac{<numsplit1>}{<numsplit2>} } {<denom>}——使用这里的代码:

\begin{eqnarray*}
CPI_{total} &=& \frac{\sum (IIC) (CCI)}{IC} \\
&=& \frac{\splitfrac{(1 \times 10^5~instructions \cdot 1~\sfrac{cycle}{instruction})+(2 \times 10^5~instructions \cdot 2~\sfrac{cycles}{instruction})}{+(5 \times 10^5~instructions \cdot 3~\sfrac{cycles}{instruction})+(2 \times 10^5~instructions \cdot 3~\sfrac{cycles}{instruction})}}{1 \times 10^6~instructions} \\
\end{eqnarray*}

编译通过,但是它给了我1分子中多余的和分散注意力的东西,如下所示:

带有随机“1”的方程

知道这里发生什么事吗?

答案1

您可以使用array在大分子中堆叠内容:

在此处输入图片描述

\documentclass[11pt]{article}

\usepackage[margin=1in,paperwidth=8.5in,paperheight=11in]{geometry}
\usepackage[shortlabels]{enumitem}
\usepackage{amsmath,xfrac,breqn}

\newcommand{\CI}{\text{class instructions}}
\newcommand{\CS}{\sfrac{\text{cycle}}{\text{instruction}}}
\newcommand{\CPI}{\text{CPI}}

\begin{document}

% << Other stuff that compiled fine. >>

\begin{enumerate}[(a)]

  \item What is the global CPI for each implementation?

  We can use this equation to find the overall CPI for each implementation:

  \begin{align*}
    \CPI_{\text{total}} & = \frac{\sum (IIC) (CCI)}{IC} \\
    \CPI_{P1,\text{total}} &= 
      \frac{\begin{array}{@{}r@{}}
          (1 \times 10^5\ \CI \cdot 1\ \CS) \\ {}+
          (2 \times 10^5\ \CI \cdot 2\ \CS) \\ {}+ 
          (5 \times 10^5\ \CI \cdot 3\ \CS) \\ {}+ 
          (2 \times 10^5\ \CI \cdot 3\ \CS)
        \end{array}}    
        {1 \times 10^6\ \text{instructions}} \\
      & = 2.6\ \sfrac{\text{average cycles}}{\text{instruction}} \\
    \CPI_{P2,\text{total}} & = 
      \frac{\begin{array}{@{}r@{}}
          (1 \times 10^5\ \CI \cdot 2\ \CS) \\ {}+ 
          (2 \times 10^5\ \CI \cdot 2\ \CS) \\ {}+ 
          (5 \times 10^5\ \CI \cdot 2\ \CS) \\ {}+ 
          (2 \times 10^5\ \CI \cdot 2\ \CS)
        \end{array}}
      {1 \times 10^6\ \text{instructions}} \\
      & = 2.0\ \sfrac{\text{average cycles}}{\text{instruction}} \\
  \end{align*}

  % << More list items >>

\end{enumerate}
\end{document}

一些指导原则:

  • 使用\text{<stuff>}设置<stuff>为文本;
  • 为你经常使用的东西定义宏 - 它促进一致性
  • 考虑使用缩写的“单元”来表示“类别指令”(可能\text{ci})和“周期/指令”(可能\text{cpi}),以避免信息明显重复(和混乱)。

相关内容