[Tex/LaTex] ieeetran: how to start page with (wide) figure on top

ieeetran

I would like to force ieeetran to start a new page with a wide (i.e. 2-column) figure on top, and render text below it. So far I've been unable to achieve this behavior in a "deterministic" way, and the only workaround I've found for having wide figures on the top of pages is to move their instantiation back to some previous portions of text code–through a cumbersome trial-and-error process–, but this results in chaos as I end up having seemingly-random instantiations all over my code. Instead, I'd like to keep the figure instantiations within the code of the sections where they belong, but if I do so, it seems impossible to force them to be rendered at the top of the page. How can I achieve this? Thanks, Jorge.

Example:

\documentclass[journal]{IEEEtran}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{lipsum}

\begin{document}

\begin{figure*}[!t]
\centering
    \subfloat[]{\includegraphics[width=0.4\linewidth]{example-image-a}}
    \hfill
    \subfloat[]{\includegraphics[width=0.4\linewidth]{example-image-b}}
    \caption{Some dummy figures.}
    \label{fig1}
\end{figure*}

\section{This text should follow Fig. \ref{fig1}, not precede it!}
\lipsum[1-6]

% Problem happens also after a \clearpage
\clearpage
\begin{figure*}[!t]
\centering
    \subfloat[]{\includegraphics[width=0.8\linewidth,height=0.2\textheight]{example-image-c}}
    \caption{Another figure.}
    \label{fig2}
\end{figure*}

\section{This text should follow Fig. \ref{fig2}, not precede it!}
\lipsum[1-6]

\end{document} 

Output:

enter image description here

Best Answer

The approach is similar to here, but easier. Note that a figure without a caption does not show up in the list of figures.

\documentclass[journal]{IEEEtran}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{lipsum}
\usepackage{afterpage}

\makeatletter
\newcommand{\setcaptype}[1]{\def\@captype{#1}}
\makeatother

\newsavebox{\tempbox}

\begin{document}

\savebox{\tempbox}{\begin{minipage}{\textwidth}% measuer height of figure
\setcaptype{figure}%
\centering
    \subfloat[]{\includegraphics[width=0.4\linewidth]{example-image-a}}
    \hfill
    \subfloat[]{\includegraphics[width=0.4\linewidth]{example-image-b}}
    \caption{Some dummy figures.}
    \label{fig1}
\end{minipage}}

\begin{figure}[t]
\rlap{\usebox\tempbox}
\end{figure}
\afterpage{\begin{figure}[t]% next column
\rule{0pt}{\dimexpr \ht\tempbox+\dp\tempbox}
\end{figure}}

\section{This text should follow Fig. \ref{fig1}, not precede it!}
\lipsum[1-6]

% Problem happens also after a \clearpage
\clearpage
\savebox{\tempbox}{\begin{minipage}{\textwidth}% measuer height of figure
\setcaptype{figure}%
\centering
    \subfloat[]{\includegraphics[width=0.8\linewidth,height=0.2\textheight]{example-image-c}}
    \caption{Another figure.}
    \label{fig2}
\end{minipage}}

\begin{figure}[t]
\rlap{\usebox\tempbox}
\end{figure}
\afterpage{\begin{figure}[t]% next column
\rule{0pt}{\dimexpr \ht\tempbox+\dp\tempbox}
\end{figure}}

\section{This text should follow Fig. \ref{fig2}, not precede it!}
\lipsum[1-6]

\end{document}