Центрирование уравнения в выровненной математической среде

Центрирование уравнения в выровненной математической среде

Мне интересно, как центрировать части уравнений в выровненной среде. Я хочу, чтобы это выглядело так:
введите описание изображения здесь
или это:
введите описание изображения здесь
В настоящее время мой код выглядит так, как показано ниже, однако он не дает мне желаемого результата:

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

Связанный контент