5

This is my code:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{placeins}
\clubpenalty=10000
\widowpenalty=10000
\begin{document}
\section{First}
\lipsum[1-3]
\section{Second}
\FloatBarrier
\begin{table}[h!]
\caption{Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text!}
\begin{tabular}{|c|c|}
\hline  1&2  \\ 
\hline  3&4  \\ 
\hline 
\end{tabular} 
\end{table}
\FloatBarrier
\FloatBarrier
\begin{table}[h!]
\caption{Short text}
\begin{tabular}{|c|c|}
\hline  1&2  \\ 
\hline  3&4  \\ 
\hline 
\end{tabular} 
\end{table}
\FloatBarrier
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text.
\end{document}

enter image description here

I have a lot of sections in my Appendix, which contain two tables and small text. I do not like when section name appears at the bottom of the page alone without table. How I can avoid it?

P.S. \clubpenalty=10000 \widowpenalty=10000

This code does't help.

P.S.S. I need to use \FloatBarrier for many other reasons. I do not like idea to use \newpage always I see this problem.

  • You put \FloatBarrier after the section heading, the only purpose of that command is to force a page break if there are pending floats. It should never be after the heading always before. – David Carlisle May 14 '14 at 19:57
  • @David Carlisle It doesn't make any difference. – saldenisov May 14 '14 at 20:17
  • It makes a lot of difference on general even if the page break happens in same place here it is the difference between putting \clearpage before or after the heading, if you put it after the heading then you will get page breaks after the heading. – David Carlisle May 14 '14 at 20:25
  • Also you shouldn't use h on its own, which is why LaTeX warns you and changes it: LaTeX Warning: '!h' float specifier changed to '!ht'. using it in that form makes floats going to the end very likely which is why you need so many float barriers to stop them – David Carlisle May 14 '14 at 20:27
  • It does make a difference, I just tested it:-) I'll make an answer:-) – David Carlisle May 14 '14 at 20:30
5

If there are pending floats (as there are here) then \floatBarrier is essentially \clearpage so will force a page break, you have 4 !!!! of these commands after \section and before the first non-floating text of that section. If you put forced page breaks there then that naturally over-rides all LaTeX's attempts not to break after the heading.

Using [h] makes it highly likely that you have pending un-placeable floats that are drifting to the end of the document. It's meaning is not top, not bottom, not float page in other words, it disallows almost all float positions, leaving a forced \clearpage or end of document as the only possibility. To give itself a chance LaTeX issues a warning

`!h' float specifier changed to `!ht'

But even ht is pretty restrictive and htp is more reasonable.

If you do not want a float from one section to float to the next use a barrier before the heading. The package will do this automatically if you use the section option.

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage[section]{placeins}
\clubpenalty=10000
\widowpenalty=10000
\begin{document}
\section{First}
\lipsum[1-3]


\section{Second}

\begin{table}[htp]
\caption{Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text!}
\begin{tabular}{|c|c|}
\hline  1&2  \\ 
\hline  3&4  \\ 
\hline 
\end{tabular} 
\end{table}

\begin{table}[htp]
\caption{Short text}
\begin{tabular}{|c|c|}
\hline  1&2  \\ 
\hline  3&4  \\ 
\hline 
\end{tabular} 
\end{table}

Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text.
\end{document}

If you have long (or even short) sequence of tables without text, it is better to use non-floating environment such as minipage or use float package H to make table non floating. Otherwise LaTeX is holding the tables back waiting for text to fill up the page, and the text never comes. here I've commented out the final text to show it works in that case. As a non float latex tries to keep the section head with the first table, so takes both onto page 2.

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{lipsum}
%\usepackage[section]{placeins}
\usepackage{float}
\begin{document}
\section{First}
\lipsum[1-3]


\section{Second}

\begin{table}[H]
\caption{Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text!}
\begin{tabular}{|c|c|}
\hline  1&2  \\ 
\hline  3&4  \\ 
\hline 
\end{tabular} 
\end{table}

\begin{table}[H]
\caption{Short text}
\begin{tabular}{|c|c|}
\hline  1&2  \\ 
\hline  3&4  \\ 
\hline 
\end{tabular} 
\end{table}

%Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text.
\end{document}
  • It does not work for me, cause I need to have table after section name, not text (text is almost not imporatant, sometimes I even do not have text at all). – saldenisov May 14 '14 at 21:37
  • @saldenisov well perhaps you would be better with non floating tables, but in any case if you do not want a page break after a heading do not use \FloatBarrier there as the only effect of that command is to do nothing (if there are no pending floats) or to force a page break. – David Carlisle May 14 '14 at 22:56
  • @saldenisov answer updated with second answer using H floats which may be more suitable for the case you describe in comments – David Carlisle May 14 '14 at 23:17
2

The titlesec package has a nobottomtitles option; it defines a \bottomtitlespace such that section titles that are closer to the bottom margin than this distance are moved next page, while the pages where they should have appeared are bottom ragged. The default value for \bottomtitlespace is 0.2\textheight.

  • 1
    This is true although it won't help if as here latex decides there is room for the heading but then the user inserts a forced page break just after the heading before the section content. – David Carlisle May 15 '14 at 8:33

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.