[Tex/LaTex] How to force text and figures to be on the same page when minipage, samepage, nopagebreak do not work

floatsminipagepage-breaking

I'm trying to get four figures (centered on a page in a 2×2 grid) to show up on the same page as the section heading ("Appendix").

The following puts the word "Appendix" on one page (all by itself) and then the four figures on their own page.

I've messed with \nopagebreak, \begin{samepage}...\end{samepage}, \begin{minipage}...\end{minipage} with no luck.

\bibliographystyle{plain}
\bibliography{sid}
\vfill\eject
\appendix
\label{sec:ads}
\begin{figure*}
\centering
\subfigure[]{
  \includegraphics[height=150pt]{./figs/jjj.png}
  \label{fig:jjj}
} \quad
\subfigure[]{
  \includegraphics[height=150pt]{./figs/xxx.png}
  \label{fig:xxx}
} \quad
\subfigure[]{
  \includegraphics[height=150pt]{./figs/nnn.png}
  \label{fig:nnn}
} \quad
\subfigure[]{
  \includegraphics[height=150pt]{./figs/aaaa.png}
  \label{fig:aaa}
} \quad
\caption{blah  }
\label{fig:aaaa}
\end{figure*}

The \vfill\eject business is to get the word "Appendix" to appear at the top of a new page, not right after the bibliography. BTW, \appendix has this entry in the cls file:

 \def\appendix{\par
 \section*{APPENDIX}
 \setcounter{section}{0}
 \setcounter{subsection}{0}
 \def\thesection{\Alph{section}} }

Best Answer

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

Related Question