简体   繁体   English

如何对齐分段函数

[英]How to align piecewise functions

I thought a properly aligned piecewise function should be something like this:我认为正确对齐的分段 function 应该是这样的:

正确对齐的分段函数

Commas and character x s are perfectly aligned in two lines.逗号和字符x s 在两行中完美对齐。

I tried我试过了

\vert x \vert =
\begin{cases} 
  x, &x \geq 0 \\
 -x, &x < 0  \\
\end{cases}

which only aligned the domain parts like this:它只对齐域部分,如下所示:

域部分对齐

In that way, the commas come after x and -x is not aligned, which looks strange.这样,逗号在x之后, -x没有对齐,这看起来很奇怪。

I tried to solve that problem by adding spaces preceding the x in first line, which is:我试图通过在第一行的x之前添加空格来解决该问题,即:

\vert x \vert =
\begin{cases} 
 \enspace \; x, &x \geq 0 \\
 -x, &x < 0  \\
\end{cases}

It gives the correct result (as above) but this solution seems rather strange, if the second line changes, then the first line have also to be modified to keep the spaces fit.它给出了正确的结果(如上所述)但是这个解决方案看起来很奇怪,如果第二行发生变化,那么第一行也必须修改以保持空间合适。 I reckon there must be some better way to do it.我认为必须有一些更好的方法来做到这一点。

The default alignment behaviour of cases is l eft- l eft for the value and domain components. cases的默认l行为是l值和域组件的。 In this specific case (for aesthetic reasons), you can insert a \phantom negation to align the values:在这种特定情况下(出于审美原因),您可以插入一个\phantom否定来对齐值:

在此处输入图像描述

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\[
  \lvert x \rvert = \begin{cases}
     x, & x \geq 0 \\
    -x, & x < 0
  \end{cases}
\]

\[
  \lvert x \rvert = \begin{cases}
    \phantom{-}x, & x \geq 0 \\
    -x, & x < 0
  \end{cases}
\]

\end{document}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM