整列した数式環境での式の中央揃え

整列した数式環境での式の中央揃え

整列した環境で方程式の一部を中央に配置する方法を知りたいです。次のようになります。
ここに画像の説明を入力してください
またはこれ:
ここに画像の説明を入力してください
現在、私のコードは以下のとおりですが、期待する結果が得られません。

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

[1]: https://i.stack.imgur.com/dY8cr.png

関連情報