0

I followed this post to get a figure to be aligned in a grid. I am using double column format to my text, and it seems like whenever the figure reaches the end of a column, it pushes all of the content of that was supposed to be in that column to the bottom of the page and floats out of the page (screenshot).

I found that adding an extra paragraphs of text so that the figure starts on the right column will make it so that everything looks okay. Are there any elegant solutions to this, or do i just have to live with making sure that the figure never hits the bottom of the page?

To avoid confusion, I use the subcaption package for the subfigures.

Code below:

\lipsum[1-10]
\begin{figure}
\centering
\begin{subfigure}{.4\columnwidth}
    \includegraphics[width=\columnwidth]{a.png}
    \caption{a caption}
    \label{fig:a}
\end{subfigure}
\begin{subfigure}{.4\columnwidth}
    \includegraphics[width=\columnwidth]{b.png}
    \caption{b caption}
    \label{fig:b}
\end{subfigure}
\begin{subfigure}{.4\columnwidth}
    \includegraphics[width=\columnwidth]{c.png}
    \caption{c}
    \label{fig:c}
\end{subfigure}
\begin{subfigure}{.4\columnwidth}
    \includegraphics[width=\columnwidth]{d.png}
    \caption{d caption}
    \label{fig:d}
\end{subfigure}

\caption{fig caption} \label{fig:fig_all} \end{figure}

Screenshot of the LaTeX

3 Answers3

1

I don't know what the rest of your code is and perhaps it alters LaTeX'es default settings. By default floats are top aligned and followed by text. Nothing should be pushed downwards.

Depending on amount of text before an image is requested, float will be placed in either a left- or a right-hand side column, or even on another page; e.g. in the code, change commented lines to \kant[1-2] and \kant[3]. If you append [tbh] to \begin{figure}, the float can also be placed between paragraphs

enter image description here

\documentclass[twocolumn]{article}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{tabularx}
\usepackage{kantlipsum}

\begin{document} \kant[1-2] % \kant[1] \begin{figure} \centering \begin{tabularx}{1.0\linewidth}{@{}XX@{}} \subfloat[]{\label{fig:a}% \includegraphics[width=\linewidth]{example-image}} & \subfloat[]{\label{fig:b}% \includegraphics[width=\linewidth]{example-image}} \ \subfloat[]{\label{fig:c}% \includegraphics[width=\linewidth]{example-image}} & \subfloat[]{\label{fig:d}% \includegraphics[width=\linewidth]{example-image}} \end{tabularx} \caption{fig caption}\label{fig:fig_all} \end{figure} \kant[3] % \kant[2-3] \end{document}

Celdor
  • 9,058
1

You could add the "placement specifier parameter" for floats, to suggest LaTeX were to put the figure. If you don't the figure will go to the top of the left column.

To add some space between the figures of each row (here \hfill) and between rows no other package is needed.

The best read: influence the position of float environments like figure and table

A

\documentclass[12pt, twocolumn]{article}

\usepackage{graphicx}
\usepackage{subcaption} \usepackage{lipsum}

\begin{document}

\lipsum[1-10]

\begin{figure}[htb!] % placement specifier parameter <<<< \begin{subfigure}{0.4\columnwidth} \includegraphics[width=\columnwidth]{example-image-a} \caption{a caption} \label{fig:a} \end{subfigure} \hfill \begin{subfigure}{0.4\columnwidth} \includegraphics[width=\columnwidth]{example-image-a} \caption{b caption} \label{fig:b} \end{subfigure} \vspace*{3ex}%some vertical space

\begin{subfigure}{.4\columnwidth}
    \includegraphics[width=\columnwidth]{example-image-b}
    \caption{c caption}
    \label{fig:c}
\end{subfigure}\hfill
\begin{subfigure}{.4\columnwidth}
    \includegraphics[width=\columnwidth]{example-image-b}
    \caption{d caption}
    \label{fig:d}
\end{subfigure}

\caption{fig caption}
\label{fig:fig_all}

\end{figure}

\lipsum[1-10] \end{document}

Simon Dispa
  • 39,141
0

One more solution with using subfloat environment:

\documentclass[twocolumn]{article}
\usepackage{graphicx}
\usepackage{subcaption}  % must be version 1.3 or later
\usepackage{lipsum}

\begin{document} \lipsum[1-2] \begin{figure}[htb] % <--- \centering \setkeys{Gin}{width=0.47\linewidth} % assumed that allimages have the same size \subfloat[ \label{fig:a}]% {\includegraphics{example-image}} \hfil \subfloat[ \label{fig:b}]% {\includegraphics{example-image}}

\medskip \subfloat[ \label{fig:c}]% {\includegraphics{example-image}} \hfil \subfloat[ \label{fig:d}]% {\includegraphics{example-image}}

\caption{fig caption} \label{fig:fig_all} \end{figure}

\lipsum[3-4]

See images `\ref{fig:a} \ref{fig:b}, \ref{fig:c} and \ref{fig:d} in figure \ref{fig:fig_all} \end{document}

enter image description here

Zarko
  • 296,517