3

I wish to format a system of equations. I use:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$$\begin{cases}
\begin{aligned}
q_1 S_1^1 &+ q_2 S_2^1 &+ ... &+ q_n S_n^1 &= (1+r) S_0^1, \\
q_1 &+ q_2 &+ ... &+ q_n &= 1.
\end{aligned}
\end{cases}$$
\end{document}

I expect the q's and the equality sign to be below each other, but instead there is an indent in front of the q_1 and the =1 is totally on the right. How do I obtain my desired behavior?

3 Answers3

3
  1. You shouldn't use $$ in LaTeX.
  2. You don't want cases, which adds unwanted horizontal space at its right if its contents isn't a set of rows of the form <formula>&<condition>.
  3. You don't want aligned, which adds space between the columns.

With alignedat:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

[ \left{ \begin{alignedat}{5} & q_1 S_1^1 &&+ q_2 S_2^1 &&+ \dotsb &&+ q_n S_n^1 &&= (1+r) S_0^1, \ & q_1 &&+ q_2 &&+ \dotsb &&+ q_n &&= 1. \end{alignedat} \right. ]

\end{document}

enter image description here

egreg
  • 1,121,712
2

I don't think the aligned and cases machineries are all that well suited to handle the present job. I suggest you use an array environment instead.

enter image description here

The ^{} particles in row 1 assure that the subscripts associated with q and S^1 are placed at the same depth.

\documentclass{article}

\usepackage{array} % for '\newcolumntype' macro \newcolumntype{C}{>{{}}c<{{}}} % col. type for binary and relational operators \newcolumntype{L}{>{\displaystyle}l}

\begin{document}

[ \setlength\arraycolsep{0pt} \renewcommand\arraystretch{1.33} \left{ \begin{array}{ L *{4}{CL} } q^{}_1 S_1^1 &+& q^{}_2 S_2^1 &+& \cdots &+& q^{}_n S_n^1 &=& (1+r)S_0^1 \ q_1 &+& q_2 &+& \cdots &+& q_n &=& 1 ,. \end{array} \right. ]

\end{document}

Mico
  • 506,678
0

I assume that you want the q_1 S_1^1 and q_1 right-aligned, because that's what your given code outputs.

I don't understand why, but the alignment of the rightmost column comes closer to what you want if you put an extra & before the &=:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$$\begin{cases}
\begin{aligned}
q_1 S_1^1 &+ q_2 S_2^1 &+ ... &+ q_n S_n^1 &&= (1+r) S_0^1, \\
q_1 &+ q_2 &+ ... &+ q_n &&= 1.
\end{aligned}
\end{cases}$$
\end{document}

It seems to me that align treats the entries per row in groups of two or three, and also puts extra space after each triple (between the handwritten lines).

enter image description here

  • 1
    Please add all instructions needed to make your code snippet minimally compilable. – Mico Dec 19 '22 at 10:37