15

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?

  • 1
    Real quick: Did you read the postings Is it wrong to use \clearpage instead of \newpage? and -- on the subject of float placement -- How to influence the position of float environments like figure and table in LaTeX? Are you maybe uncertain what the terms "float", "pending float" and "flushing from the stack" mean in a LaTeX context? Please advise. – Mico Dec 14 '18 at 5:04
  • I just read the question you shared so I guess this question may fall of as a duplicate. I know the term "float" as a figure or a table. But I don't understand the other terms such as "pending float" and especially "flushing from the stack". – billyandriam Dec 14 '18 at 5:38
  • Not to make it worse, but there is also \pagebreak (with an optional argument ranging from 0-4 for the priority)! ;-) It does not add a page break directly but tells LaTeX that this would be a good place to add a natural page break. There is also the opposite \nopagebreak. – Martin Scharrer Dec 14 '18 at 6:38
24

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}
  • I tried the code and it is now easy to notice the difference. Thank you very much. – billyandriam Dec 14 '18 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.