If "- Head -" is a normal text line \\*
should work. If not we need to know what it is. In a lot of case solutions with \@afterheading
can be used, e.g.:
\makeatletter
\def\mynobreakpar{\par\nobreak\@afterheading}
\def\mynobreakline{\par\nobreak\vspace{-\parskip}\@afterheading\noindent}
\makeatother
Obviously, in this case, you don't want your figures to float, so the natural approach would be not to use float environments. You can use minipage
s to properly align your subfigures, and using the \captionof
command provided by the caption and subcaption
packages you can give a caption to your subfigures and to your figure, allowing corresponding labels for cross-references. Here's a little example:
\documentclass{book}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[demo]{graphicx}
\begin{document}
\appendix
\chapter{Test Appendix}\label{sec:ads}
\noindent\begin{minipage}{\textwidth}
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[height=150pt]{./figs/jjj.png}
\captionof{subfigure}{First subfigure.}
\label{fig:jjj}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[height=150pt]{./figs/xxx.png}
\captionof{subfigure}{Second subfigure.}
\label{fig:xxx}
\end{minipage}\\
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[height=150pt]{./figs/nnn.png}
\captionof{subfigure}{Third subfigure.}
\label{fig:nnn}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[height=150pt]{./figs/aaaa.png}
\captionof{subfigure}{Fourth subfigure.}
\label{fig:aaa}
\end{minipage}
\captionof{figure}{A figure with four subfigures.}
\label{fig:aaaa}
\end{minipage}
\end{document}
I added the demo
option to the graphicx
package in order to make my example compilable for everyone; do not use that option in your actual code.
As a side note, you seem to be using the subfigure
package; this package is obsolete and shouldn't be used anymore; you can use the subcaption
package instead.
Best Answer
\nopagebreak
makes it infinitely bad to break at that point. So TeX will not break at that node However it is possible that it breaks at that point visually for exampleThen TeX will not break above the invisible rule, but may break after the invisible rule. So it may seem that adding
\nopagebreak
has not worked.In complicated macros like section headings that are adding multiple penalties and spaces, each of which separately introduces a potential breakpoint it can be quite hard to prevent page breaking with a single
\nopagebreak
but the details depend on the exact details of the macro, and where it is inserting vertical space and penalties.In answer to the question in comments, usually a single
\nopagebreak
will prevent a page break as long as there is another feasible break point on that page, for example if you uncomment the\pagebreak
here The break at that point is avoided by taking two extra lines over to the next page.