How to break a LaTeX formula into lines if it is too long: line breaks and alignment
When a long formula exceeds the centroid, use aligned, split, multline and other environments to break lines and align them at appropriate locations. This article provides selection methods, writing steps and a post-compilation checklist according to the situation.
Key points of this article
- When a single formula needs to be numbered, use equation to wrap aligned, use & to align the equal sign and plus sign, and use two backslashes to break the line.
- For long single-numbered formulas with the first line aligned to the left and the last line aligned to the right, multline is more appropriate.
- Use align when multiple formulas need to be aligned line by line. If not numbered, use align*. Each line will be aligned by &.
- Inline formulas cannot directly write line breaks. If they are too long, they should be changed to independent formulas, or line breaks should be allowed after relationship characters.
- View the Overfull hbox warning and PDF layout after compilation, and lines that exceed the page margins will continue to be split.
When writing a paper or lecture notes, it is very common for a formula to exceed the margins of the page halfway through writing. LaTeX does not automatically wrap lines like text. When encountering a formula that is too long, it will either press the content out of the center of the text, or issue an Overfull hbox warning during compilation. The performance on the PDF is that the right side is cut off or squeezed into the margin of the page.
This article is written for readers who are already writing formulas in LaTeX but don't know how to split long formulas into several lines in the source code. You'll learn how to determine which environment to use, how to break and align lines at equals and plus signs, and how to inspect the results. What we are talking about here is the typesetting and writing method at the source code level, which is two different things from converting formulas from other formats to LaTeX.
How to branch a long formula? One sentence conclusion: use aligned or split with & and newline characters
Let’s talk about the conclusion first: use the aligned environment inside the formula, put & where it needs to be aligned (usually before the equal sign), use two backslashes at the end of the line to break the line, and put an equation or equation* outside to provide an environment for displaying the formula. The table below provides recommended practices based on the reader's situation.
| your situation | Recommended practices | reason |
|---|---|---|
| Individual formulas need to be numbered and aligned with the equal sign | equation wraps aligned, or equation wraps split | The number only appears once, aligned is responsible for alignment, and split is more suitable to be placed inside the numbering formula. |
| A single formula is not numbered and needs to be aligned on multiple lines | Wrap equation* in aligned, or use aligned directly in \[ \] | No numbering, simple structure, and lines are aligned by & |
| Multiple formulas appear consecutively, and each line must be numbered and aligned. | align environment | Each line is automatically numbered, with & as the alignment point, so you don’t need to write aligned yourself. |
| The first line is left-aligned and the last line is right-aligned. There is only one number. | multline environment | Specially handles the situation of "a formula is very long and only needs one number", and the middle row is automatically centered |
| Inline formula (enclosed in text) is too long | Change it to an independent formula; or use a line break prompt after a relational operator or operator | Line breaks cannot be used in inline formulas, and TeX can only be used to break them at operators. |
Look at two things when choosing: whether you need numbering, and whether you have multiple formulas to line up. In most cases, a single numbered formula using equation plus aligned will do the trick.
Before you start: Confirm these points first
Before starting to modify the source code, confirm the following items first, which can save a lot of rework.
- The amsmath macro package has been loaded in the introductory area. aligned, split, multline, align all come from amsmath. Without this macro package, compilation will report an error, prompting an undefined environment.
- Can the formula itself be disconnected at the appropriate point. Long formulas usually consist of multiple terms connected by plus, minus, or equal signs. The breakpoint should be selected before and after these relational symbols or operators. After the break, the left and right sides will be complete expressions. Do not cut between parentheses or between superscripts and subscripts.
- Whether a number is required. Number determines environment selection. equation is numbered, equation is unnumbered, align is numbered on each line, and align is unnumbered on each line. When mixing them, keep them consistent throughout the document.
- Whether the journal or template has formatting requirements. Some templates stipulate the alignment of formulas, such as aligning them uniformly by the equal sign, or requiring numbers to be on the right side. At this time, the template shall prevail and do not change it to another style on your own.
- Whether the formula needs to be previewed in the web editor. If you use the UniDoc web editor (app.unidoc.top) to edit formulas, the pasted LaTeX source code should be consistent with the locally compiled writing method, but the preview effect of the editor still needs to be based on the final PDF.
Steps to split long formulas in LaTeX source code
The following takes a numbered long formula as an example to illustrate the complete process from discovering the problem to confirming the result.
- Confirm that the amsmath macro package has been written in the introductory area, which is the prerequisite for all subsequent alignment environments.
- Compile the current document, look for the Overfull hbox warning in the log, note the line number that exceeds the page margin, and find the corresponding long formula.
- Find the breakpoint in a long formula, usually before the equal sign, plus sign, or minus sign. Both parts before and after the breakpoint should be expressions that can be read independently.
- Put the formula into the equation environment and add the aligned environment internally. If the formula does not need to be aligned on multiple lines and is only split into about one line, you can also just use split.
- Add & at each breakpoint, put it before the symbol to be aligned (usually before the equal sign), and then write two backslashes at the end of the line to break the line.
- For a numbered formula with the first line aligned to the left and the last line aligned to the right, use the multline environment instead, and separate each line with two backslashes at the breakpoint. The last line will be automatically right aligned.
- Recompile, check whether there is an Overfull hbox warning in the log, and then open the PDF to see whether the formula is fully displayed and the number is in the correct position.
- If there are multiple groups of consecutive long formulas in the document, use the align environment uniformly, and confirm that the & positions of each group are consistent to facilitate readers' comparison and reading.
Check each item after completion
After getting the compilation result, check the following items one by one. Most problems can be solved using this table.
| Check items | How to see | What to do if there is a problem |
|---|---|---|
| Whether the formula exceeds the page margins | See the log for the Overfull hbox warning and check in the PDF whether the right side is truncated | Break at more operators, or reduce the number of items in the same row |
| Are the alignment points consistent? | Check whether the equal sign and plus sign are vertically aligned line by line | Check whether the & in each line is placed before the same type of symbol. If the number of lines is inconsistent, fill in or delete the redundant & |
| Is there more blank lines in line breaks? | Observe whether the spacing between rows is abnormal | Check whether a blank line is mistakenly added after \\ and remove the extra blank lines. |
| Is the number position correct? | Check whether the number is on the right side of the formula, and whether the multi-line formula has only one number | Use equation or multline for single numbering, and align for multiple line numbers. |
| Whether the inline formula breaks the line abnormally | Check whether the inline formulas in the text paragraph are cut at inappropriate positions | Change it to an independent formula, or allow line breaks after the relational character |
| Spacing between symbols and text | Check whether the spacing before and after the formula and the text is natural | Avoid manually adding a large number of spaces into the formula, and let LaTeX handle the spacing |
If all the above checks pass, the formula is fully readable in the PDF. If you use machine translation or OCR to transcribe formulas, you should also check the formula symbols one by one, and don’t just look at whether the formatting is neat.
📊 Core comparison
There are four common writing methods, and their differences are mainly in the numbering and the relationship between lines. The following table lists the applicable situations according to the writing method. You can refer to your document structure when choosing.
| Writing method | Applicable situations | Features |
|---|---|---|
| equation wraps aligned | Single numbered formula, requires multiple lines and aligned by & | Flexible writing style, common derivation formulas in papers |
| equation wraps split | A single numbered formula needs to be split into several lines internally | The semantics are close to "split a formula into several lines", which is suitable for dividing lines within numbered formulas. |
| multline | A long formula with only one number | The first row is left-aligned, the last row is right-aligned, and the middle row is centered. |
| align | Multiple formulas are arranged consecutively, and each row must be numbered and aligned | Each line is automatically numbered, often used for multi-step derivation |
❓ Frequently Asked Questions (FAQ)
1. Why don’t long formulas wrap automatically?
LaTeX's display formulas are typeset in one line and will not automatically break according to line width like ordinary text. It can only break at certain operators in inline formulas, standalone formulas require manually specified breakpoints.
2. What is the difference between aligned and split?
Both are used for multi-line formulas. aligned can be used independently and is often placed in equation or \[ \]; split must be placed in a display formula environment such as equation and is usually used for internal line splitting of a numbered formula. In daily writing, when both can be used, aligned is more versatile.
3. What should I do if the inline formula is too long?
Line breaks cannot be used in inline formulas. You can first try to break after the relational operator or operator and let TeX handle it automatically; if it still exceeds the limit, it is recommended to change it into an independent formula and use aligned or multline to split it.
4. After compilation, the number of the formula moves to the second line. What should I do?
This is usually due to poor environment selection. Single number formulas should use equation wrapped in aligned rather than writing the number inside aligned. When multiple lines need to be numbered, use align instead.
📝 Summary
The key to breaking long formulas in LaTeX is to determine your numbering and alignment requirements before choosing aligned, split, multline or align. Load the amsmath macro package, use & and two backslashes at the equal sign or plus sign to specify alignment and line wrapping. After compilation, check the Overfull warning and PDF layout, so that long formulas can be clearly arranged on the page.
Open OmniDoc and edit, convert or translate your LaTeX document


