如何真正防止页面末尾出现单独的章节/小节标题?

如何真正防止页面末尾出现单独的章节/小节标题?

我查看了这个问题的所有解决方案,即章节或子章节的标题位于页面末尾,然后文本从下一页开始。到目前为止,我尝试的解决方案不起作用。

我努力制作了一个 MWE 来展示这个问题。它如下

\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}

这是输出 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 图形

大多数情况下,这种情况发生在我的章节或小节标题后面紧跟着一张图片时,我总是这样写

\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.....

在上面的 MWE 中,我使用了subsection,但出现了同样的问题section

我尝试过解决方案如何才能让某个部分不出现在页面的末尾
和 kquinn 的解决方案\usepackage[nobottomtitles*]{titlesec}以及使用的解决方案

 \widowpenalty=1000
 \clubpenalty=1000

没有效果。section标题仍然显示在页面底部,图片显示在下一页。

我可以尝试其他解决方案吗?但这很重要。解决方案应该是我可以在前言仅此而已。我不想手动在文档正文中添加 Latex 代码来逐一解决每个案例的问题。

谢谢

答案1

您过度使用了(在我看来,是误用了)\FloatBarrier,本质上是为了抑制有问题的 LaTeX 浮动的“浮动”行为。据我了解,\FloatBarrier如果需要防止浮动被放置,则应该使用\FloatBarrier文档中的某个点(通常是某些节标题)。使用大锤来微调节内浮动的位置并不是一个好主意。

如果你坚信必须将其figure放置在一个确切的位置——这里:紧接着小节级标题之后——我建议你加载包float并替换\begin{figure}[!htbp]\begin{figure}[H]。当然,准备好遇到大量(我的意思是,大量的) 前几页底部的空白块。

请自问是否真的有必要将figure放置在一个确切的位置。如果没有必要,请不要使用[H]

相关内容