[Tex/LaTex] A simpler explanation of \clearpage

page-breaking

I have read the manual, so am not trolling here. I REALLY don't understand the use of \clearpage. Especially, its difference with \newpage. A common explanation is that it "flushes" all pending floats from the stack.

What does it even mean? Can anybody explain it in simpler terms?

Best Answer

1) \newpage could mean "start a new page" or "start the second column" (only two column documents, of course) while \clearpage always starts a new page.

2) \newpage only breaks the page (or column) at that point; but \clearpage, as you said, also flushes out (i.e., print) all pending floats from the stack before the start of the new page. That means "do not wait anymore to print the damn figures and tables that I coded before this point". Mainly, this makes sense before the start of a new section, to prevent jumping of some images or tables of one section to the text of the next section (but makes no sense in \chapter, because the \clearpage is already added automatically).

Therefore, in a simple long text at one column, you could see the same effect with both commands (just only a new page) but in a document with two columns and/or floats, probably you will see substantial changes.

In the next example, if you switch to a document of two columns, the first \newpage will produce a first page with two columns, two paragraphs and three images, but if it is changed by \clearpage, you will have only one column with one paragraph and no image.

Undo all the changes. You will see that there are also four images after the last line of text, but after change the second \newpage by \clearpage all the images will be printed before that line. Is the difference clearer now?

\documentclass{article} 
%\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage{graphicx}
\begin{document}
\def\myfloat{\begin{figure}[htp]\includegraphics[scale=.1]{example-image}\end{figure}}
\lipsum[1]
\newpage % same as \clearpage?  compare it in twocolumn mode !!
%\clearpage
\lipsum[2]

\myfloat\myfloat\myfloat\myfloat\myfloat\myfloat\myfloat\myfloat\myfloat

\newpage % last line in 2nd page, four floats go AFTER the last line. 
%\clearpage % last line in 3th page , all floats printed before.  

This is the last line.

\end{document}