# Lines run over PDF boundaries? [duplicate]

I have lines of equations that run over the boundary of the PDF, I would like them to fit in the PDF. However, this is what happens instead:

I have the code:

\documentclass[11pt,fleqn]{article}
\setlength {\topmargin} {-.15in}
\setlength {\textheight} {8.6in}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}

\renewcommand{\labelenumii}{\theenumii.}

\newcommand{\mname}[1]{\mbox{\sf #1}}
\newcommand{\pnote}[1]{{\langle \text{#1} \rangle}}

\begin{document}

\medskip

\noindent

\subsection*{Required Problems}

\begin{enumerate}

\item \textbf{[10 points]} Prove by weak induction
that $\sum^{n}_{i=0}i^2 = \frac{n(n+1)(2n +1)}{6}$ for all $n \in \mathbb{N}$.

\bigskip

\begin{proof}
Let $P\,n \equiv \sum^{n}_{i=0}i^2 = \frac{n(n+1)(2n +1)}{6}$. Proving $P\,n$
for all $n \in \mathbb{N}$ by weak induction.

\emph{Base case}: $n = 0$.

\begin{align*}
P\,0 & \equiv \sum_{i=0}^{0} {i}^2 = \frac{0(0+1)(2*0 +1)}{6} &
\pnote{definition of $P$}\\
& \equiv 0^2 = \frac{0(0+1)(2*0 +1)}{6} & \pnote{definition of $\sum_{i=m}^{n} f\,i$}\\
& \equiv 0 = \frac{0(1)(1)}{6} & \pnote{arithmetic}\\
& \equiv 0 = 0         & \pnote{arithmetic}
\end{align*}

\emph{Induction step}: Assuming $P\,n$. Proving $P\,(n + 1)$.

\begin{flalign*}
P\,(n+1) & \equiv \sum_{i=0}^{n + 1} {i}^2 = \frac{(n+1)(n+2)(2(n+1) +1)}{6} & \pnote{definition of $P$}\\
& \equiv {(n+1)}^2 + \sum_{i=0}^{n} {i}^2 = \frac{(n+1)(n+2)(2(n+1) +1)}{6} & \pnote{definition of $\sum_{i=m}^{n} f\,i$}\\
& \equiv {(n^2+2n+1)} + \sum_{i=0}^{n} {i}^2 =
\frac{(n^2+3n+2)(2n+3)}{6} & \pnote{arithmetic}\\
& \equiv {(n^2+2n+1)} + \sum_{i=0}^{n} {i}^2 =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{arithmetic}\\
& \equiv {(n^2+2n+1)} + \frac{n(n+1)(2n +1)}{6} =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{induction hypothesis}\\
& \equiv \frac{(6n^2+12n+6)}{6} + \frac{(n^2+n)(2n +1)}{6} =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{arithmetic}\\
& \equiv \frac{(6n^2+12n+6+2n^3+n^2+2n^2+n)}{6} =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{arithmetic}\\
& \equiv \frac{(2n^3+9n^2+13n+6)}{6} =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{arithmetic}\\
\end{flalign*}

\end{proof}

\end{enumerate}

\end{document}


Please realize that I am a complete beginner to LaTeX.

## marked as duplicate by Henri Menke, Stefan Pinnow, TeXnician, Bobyandbob, MenschJan 15 '18 at 16:05

• Make the page larger. – Henri Menke Jan 15 '18 at 3:09
• Welcome! Could you please provide an MWE, i.e. a code that starts with \documentclass and ends with \end{document}? – marmot Jan 15 '18 at 3:10
• You need to introduce some more line breaks in the maths environment. I'm not sure what you expect in an answer exactly - obviously, the lines are too long for the text block width. So either you may the lines shorter or you make the text block wider. You can do the former by breaking the lines, making the font smaller, using landscape mode for those parts of the text etc. You can do the latter by making the margins smaller or the paper bigger or using landscape for the document. What do you want to do? – cfr Jan 15 '18 at 3:42
• Suggestion: start by removing the second and third line of the preamble and using \usepackage{geometry}\geometry{height=8.6in,top=0.85in}. – cfr Jan 15 '18 at 3:44
• \sf is a few decades obsolete. Use \sffamily or \textsf{}. – cfr Jan 15 '18 at 3:47

Possibly something like this? This assumes US letter paper. (I'm guessing this is correct, as you're using inches.)

I've used geometry to widen the text block and enumitem to set the first level of enumerations at the left margin. I've also updated the obsolete \sf font command. You might want \mathsf{} or \textsf{} here instead, depending on intended usage.

\documentclass[11pt,fleqn]{article}
\usepackage[height=8.6in,hscale=.85]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{enumitem}
\setlist[enumerate,2]{label=\arabic*.}
\setlist[enumerate,1]{align=left, leftmargin=\parindent, labelwidth=*}

\newcommand{\mname}[1]{\mbox{\sffamily #1}}
\newcommand{\pnote}[1]{{\langle \text{#1} \rangle}}

\begin{document}

\subsection*{Required Problems}

\begin{enumerate}

\item  \textbf{[10 points]} Prove by weak induction
that $\sum^{n}_{i=0}i^2 = \frac{n(n+1)(2n +1)}{6}$ for all $n \in \mathbb{N}$.

\bigskip

\begin{proof}
Let $P\,n \equiv \sum^{n}_{i=0}i^2 = \frac{n(n+1)(2n +1)}{6}$. Proving $P\,n$
for all $n \in \mathbb{N}$ by weak induction.

\emph{Base case}: $n = 0$.

\begin{align*}
P\,0 & \equiv \sum_{i=0}^{0} {i}^2 = \frac{0(0+1)(2*0 +1)}{6} &
\pnote{definition of $P$}\\
& \equiv 0^2 = \frac{0(0+1)(2*0 +1)}{6} & \pnote{definition of $\sum_{i=m}^{n} f\,i$}\\
& \equiv 0 = \frac{0(1)(1)}{6} & \pnote{arithmetic}\\
& \equiv 0 = 0         & \pnote{arithmetic}
\end{align*}

\emph{Induction step}: Assuming $P\,n$. Proving $P\,(n + 1)$.

\begin{flalign*}
P\,(n+1) & \equiv \sum_{i=0}^{n + 1} {i}^2 = \frac{(n+1)(n+2)(2(n+1) +1)}{6} & \pnote{definition of $P$}\\
& \equiv {(n+1)}^2 + \sum_{i=0}^{n} {i}^2 = \frac{(n+1)(n+2)(2(n+1) +1)}{6} & \pnote{definition of $\sum_{i=m}^{n} f\,i$}\\
& \equiv {(n^2+2n+1)} + \sum_{i=0}^{n} {i}^2 =
\frac{(n^2+3n+2)(2n+3)}{6} & \pnote{arithmetic}\\
& \equiv {(n^2+2n+1)} + \sum_{i=0}^{n} {i}^2 =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{arithmetic}\\
& \equiv {(n^2+2n+1)} + \frac{n(n+1)(2n +1)}{6} =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{induction hypothesis}\\
& \equiv \frac{(6n^2+12n+6)}{6} + \frac{(n^2+n)(2n +1)}{6} =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{arithmetic}\\
& \equiv \frac{(6n^2+12n+6+2n^3+n^2+2n^2+n)}{6} =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{arithmetic}\\
& \equiv \frac{(2n^3+9n^2+13n+6)}{6} =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{arithmetic}\\
\end{flalign*}

\end{proof}

\end{enumerate}

\end{document}


An additional solution if somebody need it:

\documentclass[11pt,fleqn]{article}
\setlength {\topmargin} {-.15in} %NOT SUGGESTED
\setlength {\textheight} {8.6in} %NOT SUGGESTED

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{varwidth}

\renewcommand{\labelenumii}{\theenumii.}

\newcommand{\mname}[1]{\mbox{\sf #1}} %%%SEE cfr's comment->NOT SUGGESTED
\newcommand{\pnote}[1]{{\langle \text{#1} \rangle}}

\begin{document}

\medskip

\noindent

\subsection*{Required Problems}

\begin{enumerate}

\item \textbf{[10 points]} Prove by weak induction
that $\sum^{n}_{i=0}i^2 = \frac{n(n+1)(2n +1)}{6}$ for all $n \in \mathbb{N}$.

\bigskip

\begin{proof}
Let $P\,n \equiv \sum^{n}_{i=0}i^2 = \frac{n(n+1)(2n +1)}{6}$. Proving $P\,n$
for all $n \in \mathbb{N}$ by weak induction.

\emph{Base case}: $n = 0$.

\begin{align*}
P\,0 & \equiv \sum_{i=0}^{0} {i}^2 = \frac{0(0+1)(2*0 +1)}{6} &
\pnote{definition of $P$}\\
& \equiv 0^2 = \frac{0(0+1)(2*0 +1)}{6} & \pnote{definition of $\sum_{i=m}^{n} f\,i$}\\
& \equiv 0 = \frac{0(1)(1)}{6} & \pnote{arithmetic}\\
& \equiv 0 = 0         & \pnote{arithmetic}
\end{align*}

\emph{Induction step}: Assuming $P\,n$. Proving $P\,(n + 1)$.

\hspace*{-85pt}\begin{minipage}{0.8\textwidth}
\begin{flalign*}
P\,(n+1) & \equiv \sum_{i=0}^{n + 1} {i}^2 = \frac{(n+1)(n+2)(2(n+1) +1)}{6} & \pnote{definition of $P$}\\
& \equiv {(n+1)}^2 + \sum_{i=0}^{n} {i}^2 = \frac{(n+1)(n+2)(2(n+1) +1)}{6} & \pnote{definition of $\sum_{i=m}^{n} f\,i$}\\
& \equiv {(n^2+2n+1)} + \sum_{i=0}^{n} {i}^2 =
\frac{(n^2+3n+2)(2n+3)}{6} & \pnote{arithmetic}\\
& \equiv {(n^2+2n+1)} + \sum_{i=0}^{n} {i}^2 =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{arithmetic}\\
& \equiv {(n^2+2n+1)} + \frac{n(n+1)(2n +1)}{6} =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{induction hypothesis}\\
& \equiv \frac{(6n^2+12n+6)}{6} + \frac{(n^2+n)(2n +1)}{6} =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{arithmetic}\\
& \equiv \frac{(6n^2+12n+6+2n^3+n^2+2n^2+n)}{6} =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{arithmetic}\\
& \equiv \frac{(2n^3+9n^2+13n+6)}{6} =
\frac{(2n^3+9n^2+13n+6)}{6} & \pnote{arithmetic}\\
\end{flalign*}
\end{minipage}

\end{proof}
\end{enumerate}
\end{document}


Output:

This solution keeps the margins as they was befor for the rest of the text and just places the content in the middle ...

• Thanks cfr... Done... Didn't even show the rest of the code.... just added the different approach. – koleygr Jan 15 '18 at 4:04
• Thanks - I have a thing about these font commands, I think. (But they were made obsolete by LaTeX-2e, so it has been a while!) – cfr Jan 15 '18 at 4:10

@cfr and @koleygr are really the persons who provided the answer. But since the title of the question is very general, I'd like to provide a discussion, for the benefit of others who find this by later search.

TeX is capable of writing lines that are wider than the page width. It is also capable of (in some instances) writing things that flow out the bottom of the page. It can even write things that flow out the left and the top, if you provide more exotic code.

Believe it or not, this is allowable in PDF. That's why the TeX compiler does not halt with an error. PDF readers will be able to display the file (but with part of the text or image chopped off). The text did not vaporize; it is buried in the PDF, but you can't see it.

For all the PDF knows, that is what you are trying to do! It cannot read your mind.

In the world of commercial print production, exceeding the page edge is disallowed. Even approaching the page edge is disallowed, except under certain conditions. But that is not the issue here.

As was noted, in the original example, the code requests lines that are longer than the page is wide. There are two solutions: shorten the lines, or widen the page.

The lines can be shortened by breaking them at chosen points. In the case of mathematics, you have to choose carefully, or even re-write the expression, so that it can be understood. This is probably the best approach, if your audience will see it printed to paper.

Widening the page is easier to do, either by selecting a different page size in the document class, or by using the "geometry" package. If the audience will only see it on a computer screen, this is probably the best approach, as the reader can be scrolled left-right. If printed to paper, the text might need to shrink, to fit the physical paper size.