7

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!

  • You can use \begin{array}{@{}c@{}} – Marco Daniel Jun 4 '12 at 18:20
  • Marco Daniel, that doesn't seem to help if this line is directly pasted into my code instead of the 4-th line \begin{array}{c}. I observe 2 negative effects: (1) the spacing is still there; (2) the equations do not occupy the full text width, the gap appears to the right, which is undesirable. – Alexandre Jun 4 '12 at 18:23
  • The space is removed I tested it. – Marco Daniel Jun 4 '12 at 18:26
5

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

  • @azetina -- thanks for adding the image. (i didn't have time.) – barbara beeton Jun 4 '12 at 20:44
  • @barbarabeeton Sure you are most welcome. I actually like answers and questions with resulting output. So whenever I see one I try to put in the images. – azetina Jun 4 '12 at 23:37
5

This is not directly addressing your question, but more about making the information easier to parse. I would suggest the following changes to make the pattern easier to see:

  • Eliminate the double equal signs
  • align the terms across multiple lines

enter image description here

Notes:

  • The leading minus sign on the last equation has non-standard spacing but I think it looks better in this case
  • You could also consider aligning the middle +/- signs (and perhaps even the equal signs) to make the pattern ever more obvious.

There are many ways to achieve this, so this is just to show one method.

Code:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\Phantom}{\phantom{{}+{}}}%
\newcommand{\Plus}{{}+{}}%
\newcommand{\Minus}{{}-{}}%

\begin{document}
\[\begin{cases}
\Phantom A_{PP}\sin\alpha_{P1} - A_{PS}\cos\alpha_{S1} \\
        \Plus B_{PP}\sin\alpha_{P2} + B_{PS}\cos\alpha_{S2} =
         \sin\alpha_{P1}, \\[7pt]
% 2-nd equation
\Phantom A_{PP}\cos\alpha_{P1}  +A_{PS} \sin\alpha_{S1} \\
\Minus B_{PP}\cos\alpha_{P2} + B_{PS} \sin\alpha_{S2} = \cos\alpha_{P1}, \\[7pt]
% 3-rd equation
\Phantom A_{PP}\gamma_{P1} \cos 2\alpha_{S1} +A_{PS}  \gamma_{S1} \sin 2\alpha_{S1} \\
\Plus B_{PP}  \gamma_{P2} \cos 2\alpha_{S2}
- B_{PS}   \gamma_{S2} \sin 2\alpha_{S2} = \gamma_{P1} \cos 2\alpha_{S1}, \\[7pt]
% 4-th equation
\Minus A_{PP}n_1 \gamma_{S1} \sin 2\alpha_{P1} +A_{PS}  \gamma_{S1} \cos 2\alpha_{S1} \\
\Plus 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{cases}\]
\end{document}
  • Thank you for the comment. I can't eliminate the double signs because the Russian typographical tradition requires the sign to be repeated if the equation is split at this sign (1st time - at the end of the line; 2nd - in the beginning of the new line). I agree that the equations are more readable if using your way :), but currently I've got to follow the publisher's requirements (most of them on the alignment are specified in the question) – Alexandre Jun 4 '12 at 19:09
2

To remove the space between the row and the brace you can use the declaration @{}. The declaration @{} is described here:

Spaces between rows and cols in a table - Better ways than mine?

To provide an equation about the whole contents you can use the command \resizebox. Note this results in an unwanted size of the equation.

\documentclass{article}
\usepackage{showframe}
\usepackage{array}
\usepackage{amsmath}
\usepackage{graphicx}
\begin{document}
\[
\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.
\] 


\noindent\resizebox{\linewidth}{!}{%
$\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.
$} 
\end{document}

enter image description here

  • maybe some options in the document preamble prevent the space from disappearing? I tried your code, and I see that the letters are increased, the width is ok, but the spacing is still there. – Alexandre Jun 4 '12 at 18:43
  • @Alexandre: Did you try my example. As you can see in the picture I got no space. – Marco Daniel Jun 4 '12 at 18:45
  • yep, I tried it. That's what I get: img542.imageshack.us/img542/2811/70308726.png . – Alexandre Jun 4 '12 at 18:52
1
\documentclass[a4paper]{article}
\usepackage{amsmath,tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}

\noindent
\begin{tabularx}{\linewidth}{@{}l@{\kern-10pt}X@{}}
$\left\{\rule{0pt}{4\normalbaselineskip}\right.$
&
\begin{multline}
A_{PP}\sin\alpha_{P1} - A_{PS}\cos\alpha_{S1} +B_{PP} \sin\alpha_{P2} 
           +B_{PS} \cos\alpha_{S2} = \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} =\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{multline}
\end{tabularx}

\end{document}

enter image description here

  • Thanks, but with my doc properties the alignment is messed with this solution (the equations cross the brace). I finally used the multlined variant proposed. Thanks again for the help – Alexandre Jun 4 '12 at 18:58
0

Analyzing the problem carefully, it is a dcases environment of multi-line equations, whose second parts should be right justified (or right aligned, or \shoveright, or \MoveEqRight... you name it).

You need the nested multline environment multilined[t] for each equation, inside an \aligned environment, inside a dcases environment.

I am against this practice:

the brace should appear to the left with no indentation

Thus, I haven't included it in my code.

In the following example, Eq. (1) is not aligned while Eq. (2) is.

enter image description here

\documentclass{article}

\usepackage{mathtools}
\usepackage[nopar]{lipsum} % for dummy text only
\begin{document}

\lipsum[66] 
%%                  FIRST EQ
\begin{equation}
    \begin{dcases}
        \begin{multlined}[t]
            A_{PP}\sin\alpha_{P1} - A_{PS}\cos\alpha_{S1} +B_{PP} \sin\alpha_{P2} +B_{PS} \cos\alpha_{S2} =\\
            =\sin\alpha_{P1},
        \end{multlined}
        \\
        \begin{multlined}[t]
            A_{PP}\cos\alpha_{P1}  +A_{PS} \sin\alpha_{S1} -B_{PP}\cos\alpha_{P2} + B_{PS} \sin\alpha_{S2} = \\
            =\cos\alpha_{P1},
        \end{multlined}
        \\
        \begin{multlined}[t]
            A_{PP}\gamma_{P1} \cos 2\alpha_{S1} +A_{PS}  \gamma_{S1} \sin 2\alpha_{S1} +B_{PP}  \gamma_{P2} \cos 2\alpha_{S2} -\\
            - B_{PS}   \gamma_{S2} \sin 2\alpha_{S2} = \gamma_{P1} \cos 2\alpha_{S1},
        \end{multlined}
        \\
        \begin{multlined}[t]
            -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}
    \end{dcases}
\end{equation}
\lipsum[66]
%%                  SECOND EQ
\begin{equation}
\begin{dcases}
    \begin{aligned}
        \begin{multlined}[t]
            A_{PP}\sin\alpha_{P1} - A_{PS}\cos\alpha_{S1} +B_{PP} \sin\alpha_{P2} +B_{PS} \cos\alpha_{S2} =\\
            =\sin\alpha_{P1},
        \end{multlined}
        \\
        \begin{multlined}[t]
            A_{PP}\cos\alpha_{P1}  +A_{PS} \sin\alpha_{S1} -B_{PP}\cos\alpha_{P2} + B_{PS} \sin\alpha_{S2} = \\
            =\cos\alpha_{P1},
        \end{multlined}
        \\
        \begin{multlined}[t]
            A_{PP}\gamma_{P1} \cos 2\alpha_{S1} +A_{PS}  \gamma_{S1} \sin 2\alpha_{S1} +B_{PP}  \gamma_{P2} \cos 2\alpha_{S2} -\\
            - B_{PS}   \gamma_{S2} \sin 2\alpha_{S2} = \gamma_{P1} \cos 2\alpha_{S1},
        \end{multlined}
        \\
        \begin{multlined}[t]
            -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}
    \end{aligned}
\end{dcases}
\end{equation}
\lipsum[66]
\end{document}

I came across the solution after two hours of playing around with align, gather, multline, split, alignat, flalign and all its variants; just before I was about to contact Lars Mad­sen (main­tainer of the mathtools package) for an upgrade. It had to be something with an automated format, in pure LaTeX style, not through the use of \quad or \hspace or \vphantom or the like.

It is amazing how such a basic typesetting feature is so unknown. I mean, I couldn't find a solution on the whole Internet. It ought to be included in the the guides and tutorials. Multi-line equations are so common!

I knew there had to be more people demanding a solution to this, which I'm now sharing throughout the forum. It also proves how robust the coding of the mathtools package is, responding successfully to this workaround.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.