[Tex/LaTex] How to align a system of multiline equations

arraysequationshorizontal alignmentmultline

I've got a system of equations, each of them doesn't fit the page width, so I'm searching the way to align them so that:

  • the brace should appear to the left with no indentation
  • the first line of each equation should be left-aligned
  • the last line of each equation should be right-aligned

I reached the following:
enter image description here
but I don't like the huge spacing between the brace and the 1-st letter of each equation.

The code I used is the following:

\[
\setlength{\multlinegap}{0pt}
\left\{
\begin{array}{c}
\shoveleft{A_{PP}\sin\alpha_{P1} - A_{PS}\cos\alpha_{S1} +B_{PP} \sin\alpha_{P2} +B_{PS} \cos\alpha_{S2} =} \\ \shoveright{=\sin\alpha_{P1},} \\
% 2-nd equation
\shoveleft{ A_{PP}\cos\alpha_{P1}  +A_{PS} \sin\alpha_{S1} -B_{PP}\cos\alpha_{P2} + B_{PS} \sin\alpha_{S2} = } \\
\shoveright{ =\cos\alpha_{P1},} \\
% 3-rd equation
\shoveleft{ A_{PP}\gamma_{P1} \cos 2\alpha_{S1} +A_{PS}  \gamma_{S1} \sin 2\alpha_{S1} +B_{PP}  \gamma_{P2} \cos 2\alpha_{S2} -} \\
\shoveright{- B_{PS}   \gamma_{S2} \sin 2\alpha_{S2} = \gamma_{P1} \cos 2\alpha_{S1},} \\
% 4-th equation
\shoveleft{ -A_{PP}n_1 \gamma_{S1} \sin 2\alpha_{P1} +A_{PS}  \gamma_{S1} \cos 2\alpha_{S1} +B_{PP} n_2 \gamma_{S2} \sin 2\alpha_{P2} +} \\
\shoveright{+ B_{PS} \gamma_{S2} \cos 2\alpha_{S2} = n_1 \gamma_{S1} \sin 2\alpha_{P1}.}\end{array}
\right.
\] 

Any help will be appreciated. Thanks!

Best Answer

the multlined environment from mathtools is your friend. (it loads amsmath, so there's no need to do that).

two things to note about this example:

  • \mathindent is set to zero width within a group so it will disappear after the display ends.
  • since multlined (like multline) automatically sets the first line flush left and the last line flush right, you don't want the \shove... commands on those lines. in fact, the spacing will be compromised if you do wrap those lines in \shove... arguments.

here's the code:

\documentclass{article}
\usepackage[fleqn]{mathtools}

\begin{document}

\noindent some text here
{\mathindent=0pt
\[
\setlength{\multlinegap}{0pt}
\left\{
\begin{multlined}
A_{PP}\sin\alpha_{P1} - A_{PS}\cos\alpha_{S1} +B_{PP} \sin\alpha_{P2} +B_{PS} \cos\alpha_{S2} = \\
\shoveright{=\sin\alpha_{P1},} \\
% 2-nd equation
\shoveleft{ A_{PP}\cos\alpha_{P1}  +A_{PS} \sin\alpha_{S1} -B_{PP}\cos\alpha_{P2} + B_{PS} \sin\alpha_{S2} = } \\
\shoveright{ =\cos\alpha_{P1},} \\
% 3-rd equation
\shoveleft{ A_{PP}\gamma_{P1} \cos 2\alpha_{S1} +A_{PS}  \gamma_{S1} \sin 2\alpha_{S1} +B_{PP}  \gamma_{P2} \cos 2\alpha_{S2} -} \\
\shoveright{- B_{PS}   \gamma_{S2} \sin 2\alpha_{S2} = \gamma_{P1} \cos 2\alpha_{S1},} \\
% 4-th equation
\shoveleft{ -A_{PP}n_1 \gamma_{S1} \sin 2\alpha_{P1} +A_{PS}  \gamma_{S1} \cos 2\alpha_{S1} +B_{PP} n_2 \gamma_{S2} \sin 2\alpha_{P2} +} \\
+ B_{PS} \gamma_{S2} \cos 2\alpha_{S2} = n_1 \gamma_{S1} \sin 2\alpha_{P1}.
\end{multlined}
\right.
\] }

\end{document}

enter image description here