Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I break a long equation over lines?

Tags:

latex

equation

I am trying to add an equation in a new line. The problem is that the equation is too long for the line, and I need to break it manually. Otherwise, it just overlaps to the right column, or to the right margins (and looks ugly...). Is there a way LaTeX can brake the equation for me, so it seems nice?

I'm attaching my latex code:

\begin{align*}
f(n)-f(0) &= A(n)-B(n)-C(n)-D(n)\cdot d-\left(A(0)-B(0)-C(0)-D(0)\cdot d\right) \\
          &= A(n)-0-X-D(n)\cdot d-\left(0-0-0-0\right) \\
          &= A(n)-X-D(n)\cdot d
\end{align*}

The problematic line is the first line, which is too long.

like image 541
Anna Avatar asked Sep 09 '25 19:09

Anna


2 Answers

The breqn package is designed to split long equations automatically. It works very well in the majority of situations, but it's not as mature as the amsmath package. Here's how you'd write your example equation:

\documentclass{article}
\usepackage{breqn}
\begin{document}
\begin{dmath}
f(n)-f(0) = A(n)-B(n)-C(n)-D(n)\cdot d-\left(A(0)-B(0)-C(0)-D(0)\cdot d\right)
          = A(n)-0-X-D(n)\cdot d-\left(0-0-0-0\right)
          = A(n)-X-D(n)\cdot d
\end{dmath}
\end{document}

Note there is no markup for alignment or newlines, but the output looks essentially the same as if you used align.

like image 137
Will Robertson Avatar answered Sep 13 '25 15:09

Will Robertson


I usually prefer to handle this by using the amsmath package and using the split structure. There are a bunch of useful structures in there for splitting equations across lines, but that's usually the simplest to use.

Many TeX installations will already have the package, but you can also get it from the AMS website.

like image 45
Stephen Canon Avatar answered Sep 13 '25 14:09

Stephen Canon