
基本上,我正在為教科書上的練習編寫解決方案。我想要這樣的東西:
正如您所看到的,子問題在問題編號之後對齊,公式在每個子問題之後對齊。
我已經嘗試過\tabular
,但我無法得到我想要的東西。有什麼建議嗎?
答案1
為了實現良好對齊的結果,可以輕鬆使用該align
環境,該環境是套件的一部分amsmath
。
您可以使用以下程式碼來完成此操作:
\documentclass{article}
\usepackage[fleqn]{mathtools}
\begin{document}
\begin{align*}
\intertext{2.4-14}
\intertext{(a)}
f(x) &= \begin{dcases}
\frac{125}{216} & x = -1,\\
\frac{75}{216} & x = 1,\\
\frac{15}{216} & x = 2,\\
\frac{1}{216} & x = 3;
\end{dcases} \\
\intertext{(b)}
\mu &= (-1) \cdot \frac{125}{216} + (1) \cdot \frac{75}{216} + (2) \cdot \frac{15}{216} + (3) \cdot \frac{1}{216} = -\frac{17}{216};\\
\sigma^2 &= E(X^2) - \mu^2 = \frac{269}{216} - \left( -\frac{17}{216} \right) = 1.2392;\\
\sigma &= 1.11; \\
\intertext{(c)}
& \text{See Figure 2.4-14.} \\
\intertext{(d)}
\overline{x} &= \frac{-1}{100} = -0.01; \\
s^2 &= \frac{100(129)-(-1)^2}{100(99)} = 1.30.29; \\
s &= 1.14.
\end{align*}
\end{document}
使用該包是因為的答案中的環境mathtools
需要它。該包會自動載入您也需要的套件。dcases
(a)
mathtools
amsmath
結果如下:
答案2
這是另一種方法,使用tabbing
with aligned
from amsmath
。請記住,它aligned
可以在線使用,也可以在顯示器中使用,並且該[t]
選項將確保第一行與當前基線對齊。請注意,cases
使用時,局部基線是大括號之前的部分,因此它不是“頂部”,而是在新行上開始,並垂直“退格”。
這是代碼。
\documentclass{article}
\usepackage{amsmath}
\newcommand{\0}{\phantom{0}}
\begin{document}
\begin{tabbing}
\0 2.4-14\enspace \=(a)\enspace \= \\[-\baselineskip]
\>\> $\begin{aligned}
f(x) &=
\begin{cases}
125/216, & x = -1, \\
\0 75/216, & x = 1, \\
\0 15/216, & x = 2, \\
\0\0 1/216, & x = 3;
\end{cases}
\end{aligned}$\\[6pt]
\>(b) \>
$\begin{aligned}[t]
\enspace \mu\ \ &={}\ (-1) \cdot \frac{125}{216}
+ (1) \cdot \frac{75}{216}
+ (2) \cdot \frac{15}{216}
+ (3) \cdot \frac{1}{216} = -\frac{17}{216}\,;\\
\sigma^2 \ \ &={}\ E(X^2) - \mu^2 = \frac{269}{216}
-\bigl( -\frac{17}{216} \bigr)^2 = 1.2392;\\
\sigma \ \ &={}\ 1.11;
\end{aligned}$\\[6pt]
\>(c) \>See Figure 2.4-14.\\[6pt]
\>(d) \>
$\begin{aligned}[t]
\enspace \overline{x}\ \ &={}\ \frac{-1}{100} = -0.01;\\
s^2 \ \ &={}\ \frac{100(129) - (-1)^2}{100(99)} = 1.3029;\\
s \ \ &={}\ 1.14.
\end{aligned}$
\end{tabbing}
\end{document}