3

I have some long equations and I want to have my equal signs aligned. I tried using \usepackage{amsmath} and here is a part of my code:

\begin{aligned}
\\ch_8 & = \frac{1}{2^2\cdot 3^1\cdot 7^1}[+\frac{1^1}{2^5\cdot 3^1\cdot
  5^1}c_1^8-\frac{1^1}{2^2\cdot 3^1\cdot
  5^1}c_1^6c_2+\frac{1^1}{2^2\cdot 3^1\cdot
  5^1}c_1^5c_3+\frac{1^1}{2^3\cdot 3^1}c_1^4c_2^2-\frac{1^1}{2^2\cdot
  3^1\cdot 5^1}c_1^4c_4-\frac{1^1}{3^1\cdot
  5^1}c_1^3c_2c_3+\frac{1^1}{2^2\cdot 3^1\cdot
  5^1}c_1^3c_5-\frac{1^1}{2^1\cdot 3^1\cdot
  5^1}c_1^2c_2^3+\frac{1^1}{2^2\cdot
  5^1}c_1^2c_2c_4+\frac{1^1}{2^3\cdot
  5^1}c_1^2c_3^2-\frac{1^1}{2^2\cdot 3^1\cdot
  5^1}c_1^2c_6+\frac{1^1}{2^2\cdot 5^1}c_1c_2^2c_3-\frac{1^1}{2^1\cdot
  3^1\cdot 5^1}c_1c_2c_5-\frac{1^1}{2^1\cdot 3^1\cdot
  5^1}c_1c_3c_4+\frac{1^1}{2^2\cdot 3^1\cdot
  5^1}c_1c_7+\frac{1^1}{2^4\cdot 3^1\cdot
  5^1}c_2^4-\frac{1^1}{2^2\cdot 3^1\cdot
  5^1}c_2^2c_4-\frac{1^1}{2^2\cdot 3^1\cdot
  5^1}c_2c_3^2+\frac{1^1}{2^2\cdot 3^1\cdot
  5^1}c_2c_6+\frac{1^1}{2^2\cdot 3^1\cdot
  5^1}c_3c_5+\frac{1^1}{2^3\cdot 3^1\cdot
  5^1}c_4^2-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_8]
\\ch_9 & = \frac{1}{2^5\cdot 3^1\cdot 7^1}[+\frac{1^1}{2^2\cdot 3^3\cdot 5^1}c_1^9-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^7c_2+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^6c_3+\frac{1^1}{2^2\cdot 5^1}c_1^5c_2^2-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^5c_4-\frac{1^1}{2^2\cdot 3^1}c_1^4c_2c_3+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^4c_5-\frac{1^1}{2^1\cdot 3^2}c_1^3c_2^3+\frac{1^1}{3^1\cdot 5^1}c_1^3c_2c_4+\frac{1^1}{2^1\cdot 3^1\cdot 5^1}c_1^3c_3^2-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^3c_6+\frac{1^1}{2^1\cdot 5^1}c_1^2c_2^2c_3-\frac{1^1}{2^2\cdot 5^1}c_1^2c_2c_5-\frac{1^1}{2^2\cdot 5^1}c_1^2c_3c_4+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^2c_7+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1c_2^4-\frac{1^1}{2^2\cdot 5^1}c_1c_2^2c_4-\frac{1^1}{2^2\cdot 5^1}c_1c_2c_3^2+\frac{1^1}{2^1\cdot 3^1\cdot 5^1}c_1c_2c_6+\frac{1^1}{2^1\cdot 3^1\cdot 5^1}c_1c_3c_5+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1c_4^2-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1c_8-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_2^3c_3+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_2^2c_5+\frac{1^1}{2^1\cdot 3^1\cdot 5^1}c_2c_3c_4-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_2c_7+\frac{1^1}{2^2\cdot 3^2\cdot 5^1}c_3^3-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_3c_6-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_4c_5+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_9]
\end{aligned}

Each line has one equal sign, but for some reason, the equations get out of the page (if I don't use the align package, the equation are continued on several rows, the way I want, but the equal signs of different equations are not aligned). I think I can put multiple & signs and make sure I cut the equations at the right place, before they get out of the page, but I have hundreds of them and it would take too long. Is there a way to align the equal signs and continue the equations on the next row (I don't need necessary the equation to start on the next row from under the equal, even from the beginning of the line would be fine, but I want them to not go out of the page). Thank you!

6

aligned only splits where you tell it to. We can use alignat so we have more alignment points without added space between them. We'll do

  1. a right aligned column for the left hand sides
  2. a left aligned column for the fraction and the bracket
  3. a right aligned empty column
  4. a left aligned column for the continuation lines

Here's the code.

\documentclass{article}
\usepackage{amsmath}

\usepackage{showframe} % just to show the page margins, remove it at the end

\begin{document}

\begin{alignat*}{2}
ch_8 & = \frac{1}{2^2\cdot 3^1\cdot 7^1}\biggl[ &&
\frac{1^1}{2^5\cdot 3^1\cdot 5^1}c_1^8
-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^6c_2
+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^5c_3
\\&&&
+\frac{1^1}{2^3\cdot 3^1}c_1^4c_2^2
-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^4c_4
-\frac{1^1}{3^1\cdot 5^1}c_1^3c_2c_3
\\&&&
+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^3c_5
-\frac{1^1}{2^1\cdot 3^1\cdot 5^1}c_1^2c_2^3
+\frac{1^1}{2^2\cdot 5^1}c_1^2c_2c_4
\\&&&
+\frac{1^1}{2^3\cdot 5^1}c_1^2c_3^2
-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^2c_6
+\frac{1^1}{2^2\cdot 5^1}c_1c_2^2c_3
\\&&&
-\frac{1^1}{2^1\cdot 3^1\cdot 5^1}c_1c_2c_5
-\frac{1^1}{2^1\cdot 3^1\cdot 5^1}c_1c_3c_4
+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1c_7
\\&&&
+\frac{1^1}{2^4\cdot 3^1\cdot 5^1}c_2^4
-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_2^2c_4
-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_2c_3^2
\\&&&
+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_2c_6
+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_3c_5
+\frac{1^1}{2^3\cdot 3^1\cdot 5^1}c_4^2
\\&&&
-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_8
\biggr]
\\
ch_9 & = \frac{1}{2^5\cdot 3^1\cdot 7^1}\biggl[ &&
\frac{1^1}{2^2\cdot 3^3\cdot 5^1}c_1^9
-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^7c_2
+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^6c_3
\\&&&
+\frac{1^1}{2^2\cdot 5^1}c_1^5c_2^2
-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^5c_4
-\frac{1^1}{2^2\cdot 3^1}c_1^4c_2c_3
\\&&&
+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^4c_5
-\frac{1^1}{2^1\cdot 3^2}c_1^3c_2^3
+\frac{1^1}{3^1\cdot 5^1}c_1^3c_2c_4
\\&&&
+\frac{1^1}{2^1\cdot 3^1\cdot 5^1}c_1^3c_3^2
-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^3c_6
+\frac{1^1}{2^1\cdot 5^1}c_1^2c_2^2c_3
\\&&&
-\frac{1^1}{2^2\cdot 5^1}c_1^2c_2c_5
-\frac{1^1}{2^2\cdot 5^1}c_1^2c_3c_4
+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^2c_7
\\&&&
+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1c_2^4
-\frac{1^1}{2^2\cdot 5^1}c_1c_2^2c_4
-\frac{1^1}{2^2\cdot 5^1}c_1c_2c_3^2
\\&&&
+\frac{1^1}{2^1\cdot 3^1\cdot 5^1}c_1c_2c_6
+\frac{1^1}{2^1\cdot 3^1\cdot 5^1}c_1c_3c_5
+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1c_4^2
\\&&&
-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1c_8
-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_2^3c_3
+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_2^2c_5
\\&&&
+\frac{1^1}{2^1\cdot 3^1\cdot 5^1}c_2c_3c_4
-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_2c_7
+\frac{1^1}{2^2\cdot 3^2\cdot 5^1}c_3^3
\\&&&
-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_3c_6
-\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_4c_5
+\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_9\biggr]
\end{alignat*}

\end{document}

You may want to add \allowdisplaybreak in the preamble, if you have several of these monster formulas.

enter image description here

3

You might be interested in using the autobreak package as shown in the following MWE.

\documentclass{article}
\usepackage{amsmath}
\usepackage{autobreak}

\begin{document}
\begin{align}
\begin{autobreak}
ch_8  = 
  \frac{1}{2^2\cdot 3^1\cdot 7^1}
  \biggr[+\frac{1^1}{2^5\cdot 3^1\cdot5^1}c_1^8
  -\frac{1^1}{2^2\cdot 3^1\cdot5^1}c_1^6c_2
  +\frac{1^1}{2^2\cdot 3^1\cdot5^1}c_1^5c_3
  +\frac{1^1}{2^3\cdot 3^1}c_1^4c_2^2
  -\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^4c_4
  -\frac{1^1}{3^1\cdot 5^1}c_1^3c_2c_3
  +\frac{1^1}{2^2\cdot 3^1\cdot5^1}c_1^3c_5
  -\frac{1^1}{2^1\cdot 3^1\cdot5^1}c_1^2c_2^3
  +\frac{1^1}{2^2\cdot 5^1}c_1^2c_2c_4
  +\frac{1^1}{2^3\cdot 5^1}c_1^2c_3^2
  -\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1^2c_6
  +\frac{1^1}{2^2\cdot 5^1}c_1c_2^2c_3 
  -\frac{1^1}{2^1\cdot 3^1\cdot 5^1}c_1c_2c_5 
  -\frac{1^1}{2^1\cdot 3^1\cdot 5^1}c_1c_3c_4
  +\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_1c_7
  +\frac{1^1}{2^4\cdot 3^1\cdot 5^1}c_2^4
  -\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_2^2c_4
  -\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_2c_3^2
  +\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_2c_6
  +\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_3c_5
  +\frac{1^1}{2^3\cdot 3^1\cdot 5^1}c_4^2
  -\frac{1^1}{2^2\cdot 3^1\cdot 5^1}c_8\biggr]
\end{autobreak}
\end{align}
\end{document}

In order to determine, where a line can be broken,

autobreak interprets all new line characters appearing between \begin{autobreak} and \end{autobreak} as breakable points, at which any line breaks can be logically inserted. (See: autobreak manual)

You will therefor need to do some manual adjustments to the code. In the above MWE, I have additionally used \biggr in order to achieve larger [ and ].

enter image description here

For unnumbered equations, one can use the align* environment instead of align.

  • Thank you for this, it looks like a good way to do it. However when I try to add the package autobreak I get this: ! LaTeX Error: File `autobreak.sty' not found. Is there anything else I need to do? (Sorry if this is silly, I am new to latex) – BillKet Apr 8 '18 at 19:13
  • @BillKet: You recieve this error because the package autobreak is not installed. How you can install additional packages depends on the distribution (miktex, texlive) you use. – leandriis Apr 8 '18 at 19:45
  • Thanks, I managed to install the package, and it is working now. One last thing, how can I get rid of equations numbering (the (1) after the equation)? I have multiple equations in a box, and I want to label the whole box (I know how to do that), not each equation within the box. – BillKet Apr 8 '18 at 21:32
  • You can remove the equation numbers using the align* environment instead of align. – leandriis Apr 8 '18 at 21:36

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.