
我想知道如何在對齊的環境中將方程式的各個部分居中。我希望它看起來像這樣:
或這個:
目前我的程式碼如下所示,但它沒有給我我想要的結果:
$$\lvert x \rvert = \left\{ \begin{aligned}
&x,\quad & \text{for $x \geqslant 0$} \\
-&x,\quad & \text{for $x < 0$.}
\end{aligned} \right. $$
$$f(x) = \left\{ \begin{aligned}
{\textstyle\frac{3}{2}}, &\text{for $ x > 0$} \\
\text{undefined},\quad & \text{for $x=0$} \\
{\textstyle\frac{2}{3}}, & \text{for $x < 0$}
\end{aligned} \right.$$
先感謝您!
答案1
最好透過修改來定義您自己的環境cases
:
\documentclass{article}
\usepackage{amsmath,amssymb}
\makeatletter
\newenvironment{casescentered}
{\let\@ifnextchar\new@ifnextchar
\left\lbrace
\def\arraystretch{1.2}%
\array{@{}c@{\quad}l@{}}}
{\endarray\right.}
\makeatother
\begin{document}
\begin{equation*}
\lvert x \rvert =
\begin{casescentered}
x, & \text{for $x \geqslant 0$} \\
-x,& \text{for $x < 0$.}
\end{casescentered}
\end{equation*}
\begin{equation*}
f(x) =
\begin{casescentered}
\tfrac{3}{2}, & \text{for $ x > 0$} \\
\text{undefined}, & \text{for $x=0$} \\
\tfrac{2}{3}, & \text{for $x < 0$}
\end{casescentered}
\end{equation*}
\begin{equation*}
\lvert x \rvert =
\begin{cases}
x, & \text{for $x \geqslant 0$} \\
-x,& \text{for $x < 0$.}
\end{cases}
\end{equation*}
\begin{equation*}
f(x) =
\begin{cases}
\tfrac{3}{2}, & \text{for $ x > 0$} \\
\text{undefined}, & \text{for $x=0$} \\
\tfrac{2}{3}, & \text{for $x < 0$}
\end{cases}
\end{equation*}
\end{document}
無論出於何種原因,請不要$$
在 LaTeX 中使用。
答案2
您可以使用array
:
\documentclass{article}
\usepackage{amsmath,amssymb}
\begin{document}
\[\lvert x \rvert = \left\{ \begin{array}{@{}c@{\quad}l}
x, & \text{for $x \geqslant 0$} \\
-x, & \text{for $x < 0$.}
\end{array} \right. \]
\[f(x) = \left\{ \begin{array}{@{}c@{\quad}l}
\tfrac{3}{2}, & \text{for $ x > 0$} \\
\text{undefined}, & \text{for $x=0$} \\
\tfrac{2}{3}, & \text{for $x < 0$}
\end{array} \right. \]
\end{document}