2 列以上をalignatで揃えますか?

2 列以上をalignatで揃えますか?

このMWEを、ケース環境における条件の調整:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
  f(x) = \left\{\begin{alignedat}{3}
    & mx^2 +nx +1, &\text{if } & x \le -1 \\
    & 2m e^{|x|-1} + \sin \pi x - 3n, \qquad  &\text{if } -1 < {}&x < 1 \\
    & 3x^2 - (m+n)x, &\text{otherwise} &
  \end{alignedat}\right.
\]
\end{document}

結果は次のようになります:

テスト.png

ifs と の両方otherwiseを揃え、 s を揃えたいと思いますx

それは で実行できますか{aligned}? もしそうなら、どこが間違っているのでしょうか?

答え1

&&条件を左揃えにするには を使用する必要があります。xも揃えるには、この場合は を使用することをお勧めします\hphantom

ここに画像の説明を入力してください

ノート:

  • 2 番目のケースでは、 が二項演算子ではなく単項演算子として扱われる{-1}ように、を使用する必要があります。-

コメントからのご質問にお答えします:

  • それぞれが左右の位置合わせポイント&を提供します。つまり、テキストrl前に&右揃えで、テキストはは揃えられ&ますl。したがって、最初の はを右に&揃えf(x) = {、後続の式を左に揃えます。次に、後続のテキスト (条件の先頭) を揃える必要がありますl。つまり、 が必要です &&。最初の はight の揃え&になりr、2 番目の はeft の&揃えが確保されますl
  • を使用すると\hphantom、目的の配置を簡単に得ることができます。 もちろん を使用してもかまいませんが、テキストのために、ある種のマクロ&を使用する必要がありました。 不等式がテキストと重なっていることに注意してください。\lapotherwiseotherwise

他の 2 つのアプローチの結果は次のとおりです。

ここに画像の説明を入力してください

コード:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\noindent
Recommended approach: use a \verb|\hphantom{}|: 
\[
      f(x) = \left\{\begin{alignedat}{3}
        & mx^2 +nx +1,                            &&\text{if } \hphantom{-1 <{}}   x \le -1 \\
        & 2m e^{|x|-1} + \sin \pi x - 3n, \qquad  &&\text{if } {-1} < x < 1 \\
        & 3x^2 - (m+n)x,                          &&\text{otherwise} 
      \end{alignedat}\right.
    \]
Use additional \verb|&| instead of \verb|\hphantom{}|:
\[
  f(x) = \left\{\begin{alignedat}{4}
    & mx^2 +nx +1,                            &&\text{if } &      &&  &x \le -1 \\
    & 2m e^{|x|-1} + \sin \pi x - 3n, \qquad  &&\text{if } & {-1} &&{}< {}&x < 1 \\
    & 3x^2 - (m+n)x,                          &&\text{otherwise} 
  \end{alignedat}\right.
\]
With \verb|mathllap|:
\[
  f(x) = \left\{\begin{alignedat}{4}
    & mx^2 +nx +1,                            &&\text{if } &      &&  &x \le -1 \\
    & 2m e^{|x|-1} + \sin \pi x - 3n, \qquad  &&\text{if } & {-1} &&{}< {}&x < 1 \\
    & 3x^2 - (m+n)x,                          &&\text{\rlap{otherwise}} 
  \end{alignedat}\right.
\]
\end{document}

答え2

代替案としては、環境を使用することですcases。ここでは、配置を犠牲にしてアンパサンドが少なくて済みますxが、個人的には、その方がエレガントだと思います。

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
  f(x) = \begin{cases}
    mx^2 +nx +1, &\text{if }  x \le -1 \\
    2m e^{|x|-1} + \sin \pi x - 3n,  &\text{if } -1 < x < 1 \\
    3x^2 - (m+n)x,  &\text{otherwise}
  \end{cases}
\]
\end{document}

ここに画像の説明を入力してください

答え3

これを使えば

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
  f(x) = \left\{\begin{alignedat}{3}
    & mx^2 +nx +1,                             &&\text{if }         &    & x \le -1 \\
    & 2m e^{|x|-1} + \sin \pi x - 3n, \qquad   &&\text{if }         &-1< & x < 1 \\
    & 3x^2 - (m+n)x,                           &&\text{otherwise}   &&
  \end{alignedat}\right.
\]
\end{document}

編集: 画像:

テスト.png

編集(bbeeton による): 調整された画像:

調整されたコードの出力

ここでの違いは、2 行目の左側の<記号の周りのスペースにあります。これは、次の 2 つの方法のいずれかで実現できます。

  • ... &-1<{} & x < 1
  • という事実を利用してバツ両方の行の幅は同じで、次のように入力します。

    & mx^2 +nx +1,                             &&\text{if }         &     x &\le -1 \\
    & 2m e^{|x|-1} + \sin \pi x - 3n, \qquad   &&\text{if }         & -1< x &< 1 \\
    

&演算および関係の記号の周囲の適切な間隔は、記号の前に揃える場合にのみ保証されます 。

関連情報