2

I looked at all solutions for this problem, which is having section or subsection head at end of page and then the text starts at next page. So far, solution I tried did not work.

I worked hard to make a MWE to show the problem. Here it is

\documentclass[12pt]{article}%
\usepackage{graphicx}
\usepackage{placeins}%
\usepackage[english]{babel}
\usepackage{blindtext}    
\usepackage[letterpaper, margin=1.1in]{geometry}

\begin{document}
\subsection{Problem 1}%

\begin{center}
\begin{figure}[!htbp]
\rule{2cm}{2cm}
%\centering\includegraphics[width=0.8\textwidth]{images/p1}
\end{figure}
\FloatBarrier\end{center}%

\blindtext[9]

\subsection{Problem 2}%

\begin{center}
\begin{figure}[!htbp]
\rule{0.8\textwidth}{0.4\textwidth}
%\centering\includegraphics[width=0.8\textwidth]{images/p2}
\end{figure}
\FloatBarrier\end{center}%

Here comes some text. Bad break above

\end{document}

Here is the output PDF

>lualatex document.tex
This is LuaTeX, Version 1.0.4 (TeX Live 2017) 
 restricted system commands enabled.
(./document.tex
LaTeX2e <2017-04-15>
(using write cache: /home/me/.texlive2017/texmf-var/luatex-cache/generic)(using
 read cache: /usr/local/texlive/2017/texmf-var/luatex-cache/generic /home/me/.t
exlive2017/texmf-var/luatex-cache/generic)
luaotfload | main : initialization completed in 0.133 seconds
Babel <3.14> and hyphenation patterns for 1 language(s) loaded.
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/size12.clo(load luc: /home/m
e/.texlive2017/texmf-var/luatex-cache/generic/fonts/otl/lmroman12-regular.luc))
) (/usr/local/texlive/2017/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2017/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2017/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/local/texlive/2017/texmf-dist/tex/latex/graphics-def/luatex.def)))
(/usr/local/texlive/2017/texmf-dist/tex/latex/placeins/placeins.sty)
(/usr/local/texlive/2017/texmf-dist/tex/generic/babel/babel.sty
(/usr/local/texlive/2017/texmf-dist/tex/generic/babel/switch.def)
(/usr/local/texlive/2017/texmf-dist/tex/generic/babel/luababel.def)
(/usr/local/texlive/2017/texmf-dist/tex/generic/babel-english/english.ldf
(/usr/local/texlive/2017/texmf-dist/tex/generic/babel/babel.def
(/usr/local/texlive/2017/texmf-dist/tex/generic/babel/switch.def)
(/usr/local/texlive/2017/texmf-dist/tex/generic/babel/luababel.def))))
(/usr/local/texlive/2017/texmf-dist/tex/latex/blindtext/blindtext.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/tools/xspace.sty))
(/usr/local/texlive/2017/texmf-dist/tex/latex/geometry/geometry.sty
(/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/ifvtex.sty)
(/usr/local/texlive/2017/texmf-dist/tex/generic/ifxetex/ifxetex.sty))
(./document.aux)
(/usr/local/texlive/2017/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/local/texlive/2017/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2017/texmf-dist/tex/latex/oberdiek/grfext.sty
(/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty
(/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)))
(/usr/local/texlive/2017/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/etexcmds.sty
(/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/ifluatex.sty))))
(/usr/local/texlive/2017/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty)
(/usr/local/texlive/2017/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
(load luc: /home/me/.texlive2017/texmf-var/luatex-cache/generic/fonts/otl/lmrom
an12-bold.luc) [1{/usr/local/texlive/2017/texmf-var/fonts/map/pdftex/updmap/pdf
tex.map}] [2] [3] (./document.aux))
 353 words of node memory still in use:
   2 hlist, 1 vlist, 1 rule, 2 glue, 3 attribute, 45 glue_spec, 3 attribute_lis
t, 1 write nodes
   avail lists: 2:71,3:22,4:5,5:246,6:5039,7:1219,8:2,9:78,10:3,11:298
</usr/local/texlive/2017/texmf-dist/fonts/opentype/public/lm/lmroman12-regular.
otf></usr/local/texlive/2017/texmf-dist/fonts/opentype/public/lm/lmroman12-bold
.otf>
Output written on document.pdf (3 pages, 12006 bytes).
Transcript written on document.log.

Mathematica graphics

Most of the time, this happens when I have section or subsection title followed immediately by an image which I always write as

\subsection{name}   %or section

\begin{figure}[!htbp]
\centering
\includegraphics[width=0.8\textwidth]{my_images}
\end{figure}
\FloatBarrier
\end{center}%
rest of text in the section comes here.....

In the MWE above, I used subsection but same problem shows up with section

I tried solution how-can-one-keep-a-section-from-being-at-the-end-of-a-page
Both the \usepackage[nobottomtitles*]{titlesec} and the solution by kquinn and the solution that uses

 \widowpenalty=1000
 \clubpenalty=1000

No effect. I still get section title at bottom of page, with image on next page.

Any other solution I could try? But this is important. The solution should be something I can do in the preamble only. I do not want to add Latex code manually in the body of the document to solve this for each case by case.

Thank you

  • Just get rid of the \FloatBarrier directives. If you really believe strongly that the second figure must be placed immediately after the subsection-level header, load the float package and write \begin{figure}[H]. – Mico Oct 26 '17 at 4:08
  • @Mico But I need \FloatBarrier because I want the image to be there? I use this everywhere where I put an image, to make sure the images go where I want them and not somewhere else. – Nasser Oct 26 '17 at 4:09
  • See the addendum I just wrote to my comment. – Mico Oct 26 '17 at 4:10
  • @Mico thanks. But I found from my limited experience that \FloatBarrier works better than \begin{figure}[H]. Are you saying they will work the same way? ALways forcing the image to go where I want it? If so, I will switch. – Nasser Oct 26 '17 at 4:13
  • 2
    \FloadBarrier is a forced page break, so if you use it you will get a page break. LaTeX never puts a page break after a section heading normally. Also never put a figure inside a center environment, it does not centre it and just forces spurious vertical space, which may not be at the point the figure is. If you do use \FloatBarrier you should use it before a section head never after it. – David Carlisle Oct 26 '17 at 6:56
6

You're over-using (and, IMNSHO, mis-using) \FloatBarrier, to essentially suppress the "floating" behavior of the LaTeX floats in question. It is my understanding that \FloatBarrier should be used if it's necessary to prevent floats from being placed after a certain point in the document (typically, some sectioning header). It's not a good idea to use \FloatBarrier as a sledgehammer to fine-tune the placement of the float within a section.

If you strongly believe that it's essential that the figure be placed in one exact spot -- here: immediately after the subsection-level header -- I suggest you load the float package and replace \begin{figure}[!htbp] with \begin{figure}[H]. Of course, be prepared to encounter massive (and I mean, massive) blocks of whitespace at the bottoms of the preceding pages.

Do ask yourself if it's truly essential that the figure be placed in one exact spot. If it's not essential, don't use [H].

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.