I gather that the figure
should be at the very top of a page, to be followed immediately by the table
environment. (Moreover, I'm taking for granted that the two environments will actually fit on a single page, right?)
You could achieve these objectives by loading the afterpage
package and "encasing" the figure
and table
environments in an \afterpage{...}
statement, as is shown in the following code fragment:
\afterpage{% % defer execution until the next page break occurs anyway
\begin{figure}[t!] % not "pt"
\centering
% remaining contents of figure environment
\end{figure}
\begin{table}[h!] % not t or b or p
\centering
% remaining contents of table environment
\end{table}
} % end of argument of `\afterpage` command
I'm further assuming that there are no deferred figure and/or table environments already waiting to be typeset. If that were the case, you should issue a \clearpage
instruction as the very first item in the argument of the \afterpage
command. (Even if there are no accumulated deferred floats to take care of, there's no harm done by issuing a \clearpage
instruction anyway at the start of the \afterpage
material; it would simply be ignored by TeX.)
In addition, if the figure and table environments combined take up most of the page (say, more than 75% of the page), you may also want to issue a second \clearpage
instruction, following the end of the table
environment. This will tell LaTeX that you want to have just those two floats on the page in question.
Here's one possible solution using the twocolumn class option and figure*
and two minipage
s to typeset the listings (since figure*
was used, the listings will appear on the top of the next page):
\documentclass[twocolumn]{article}
\usepackage{listings}
\usepackage{lipsum}
\begin{document}
\lipsum[1-6]
\begin{figure*}
\begin{minipage}[t]{0.5\textwidth}
\begin{lstlisting}
if (i<=0) then i := 1;
if (i>=0) then i := 0;
if (i<>0) then i := 0;
\end{lstlisting}
\end{minipage}%
\begin{minipage}[t]{0.5\textwidth}
\begin{lstlisting}
if (i<=0) then i := 1;
if (i>=0) then i := 0;
\end{lstlisting}
\end{minipage}%
\caption{Two side-by-side listings}
\label{fig:listings}
\end{figure*}
\lipsum[1-6]
\end{document}
And here's now another option: instead of using the twocolumn
document option, the multicol
package is used to produce the text in two-column mode; the multicols
environment is ended, the side-by-side listings are typeset using simple minipage
s (the caption
package was used to produce a possible caption using \captionof
), and then another multicols
environment begins:
\documentclass{article}
\usepackage{multicol}
\usepackage{listings}
\usepackage{caption}
\usepackage{lipsum}
\begin{document}
\begin{multicols}{2}
\lipsum[1-2]
\end{multicols}
\noindent\begin{minipage}{\textwidth}
\begin{minipage}[t]{0.5\textwidth}
\begin{lstlisting}
if (i<=0) then i := 1;
if (i>=0) then i := 0;
if (i<>0) then i := 0;
\end{lstlisting}
\end{minipage}%
\begin{minipage}[t]{0.5\textwidth}
\begin{lstlisting}
if (i<=0) then i := 1;
if (i>=0) then i := 0;
\end{lstlisting}
\end{minipage}%
\captionof{figure}{Two side-by-side listings}
\label{fig:listings}
\end{minipage}
\begin{multicols}{2}
\lipsum[1-2]
\end{multicols}
\end{document}
In this last option, the usual restriction of multicol
with floats apply.
Best Answer
You can set a multitude of things inside a floating environment. Below I've created a single
figure*
floating environment for capturing the wide (two-column) figure. However, just below it (inside the same float), I've set atable
and anotherfigure
insideminipage
s, making it seem like they are separate and columnar.The placement of the figures will always be on top and on the page following the placement within your document text.
capt-of
helps out with the placement of float-like captions.