# LaTex equation out of page margin

I am a LaTex beginner and I am writing my first formal document using it.
I have to write a quite long equation, and it goes out of page bounds for some reason as I show here:

Here you are the code I run:

\begin{align}
\begin{split}
f(x,y,z,w) = (x+y+z+\bar{w}) * (x+y+\bar{z}+\bar{w}) * (x+\bar{y}+z+w) * (x+\bar{y}+\bar{z}+w) * (x+\bar{y}+\bar{z}+\bar{w}) * (\bar{x}+y+z+w) * (\bar{x}+y+z+\bar{w}) * (\bar{x}+y+\bar{z}+w) * (\bar{x}+\bar{y}+z+\bar{w}) * (\bar{x}+\bar{y}+\bar{z}+w)
\end{split}
\end{align}


How can I solve this? Thank you for your patience and consideration.

• Adding line breaks somewhere (\\)?
– Fran
Apr 11, 2020 at 10:18
• @Fran Can Is there a command to make it automatic? So that if I change something in the equation it will adjust automatically. Apr 11, 2020 at 10:22
• split allows splitting across lines, but does not do it: the author has to decide where to set the line breaks. Apr 11, 2020 at 10:22

## 2 Answers

One possible solution....to split it....with edit by comment of the user.

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{align}
\begin{split}
f(x,y,z,w) & = (x+y+z+\bar{w})\cdot (x+y+\bar{z}+\bar{w})\cdot (x+\bar{y}+z+w) \\
&\cdot  (x+\bar{y}+\bar{z}+w) \cdot (x+\bar{y}+\bar{z}+\bar{w}) \cdot (\bar{x}+y+z+w) \\
&\cdot (\bar{x}+y+z+\bar{w}) \cdot (\bar{x}+y+\bar{z}+w)\\
& \cdot (\bar{x}+\bar{y}+z+\bar{w}) \cdot  (\bar{x}+\bar{y}+\bar{z}+w)
\end{split}
\end{align}
\end{document}

• Just a little problem: in the last line, there should be a \cdot instead of a = but this is what I am looking for, thank you! Apr 11, 2020 at 10:29
• @EminentEmperorPenguin I'm happy to help you..can you see, please, if is it good now? Apr 11, 2020 at 10:32
• All good now. Thank you. Apr 11, 2020 at 10:41
• Please, can you check green mark to egreg? It is the best answer than mine. Thank you very much. Apr 11, 2020 at 12:19
• @EminentEmperorPenguin There is yet, the green check mark...switch it to egreg. Thank you very much. After you choose any codes. Apr 11, 2020 at 19:32

I can propose an autosplit environment, but it's much better to split the big thing by hand as in the last example.

The optional argument to autosplit is the fraction of the display width to fill. The default is 0.9 (that is, 90%).

\documentclass{article}
\usepackage{amsmath}

\newenvironment{autosplit}[2][0.9]
{%
\settowidth{\dimen0}{$#2{}$}%
\begin{tabular}{@{}c@{}}
$\displaystyle#2{}$%
\begin{minipage}[t]{\dimexpr#1\displaywidth-\dimen0}
%\raggedright
$\displaystyle } {$\end{minipage}\end{tabular}}

\begin{document}

$$\begin{autosplit}{f(x,y,z,w) =} (x+y+z+\bar{w}) \* (x+y+\bar{z}+\bar{w}) \* (x+\bar{y}+z+w) \* (x+\bar{y}+\bar{z}+w) \* (x+\bar{y}+\bar{z}+\bar{w}) \* (\bar{x}+y+z+w) \* (\bar{x}+y+z+\bar{w}) \* (\bar{x}+y+\bar{z}+w) \* (\bar{x}+\bar{y}+z+\bar{w}) \* (\bar{x}+\bar{y}+\bar{z}+w) \end{autosplit}$$

$$\begin{autosplit}[0.8]{f(x,y,z,w) =} (x+y+z+\bar{w}) \* (x+y+\bar{z}+\bar{w}) \* (x+\bar{y}+z+w) \* (x+\bar{y}+\bar{z}+w) \* (x+\bar{y}+\bar{z}+\bar{w}) \* (\bar{x}+y+z+w) \* (\bar{x}+y+z+\bar{w}) \* (\bar{x}+y+\bar{z}+w) \* (\bar{x}+\bar{y}+z+\bar{w}) \* (\bar{x}+\bar{y}+\bar{z}+w) \end{autosplit}$$

$$\begin{split} f(x,y,z,w)={}& (x+y+z+\bar{w}) (x+y+\bar{z}+\bar{w}) (x+\bar{y}+z+w) \\ {}\cdot{}& (x+\bar{y}+\bar{z}+w) (x+\bar{y}+\bar{z}+\bar{w}) (\bar{x}+y+z+w) \\ {}\cdot{}& (\bar{x}+y+z+\bar{w}) (\bar{x}+y+\bar{z}+w) (\bar{x}+\bar{y}+z+\bar{w}) \\ {}\cdot{}& (\bar{x}+\bar{y}+\bar{z}+w) \end{split}$$

\end{document}


• autosplit is good but as I tried, I found the standard method clearer. Thank you anyway! Apr 11, 2020 at 12:43
• @EminentEmperorPenguin I mentioned it just to show the limitations with having TeX doing the breaks itself. Apr 11, 2020 at 12:59