18

I am writing a two-column paper and am trying to add images into it. I have been advised to just let LaTeX do its thing with the figures, but I find it generates large blank sections in many parts of the document. I try to move things around trying to predict where LaTeX will like things the most, but this takes hours of my time and it's infuriating.

Is there either a guideline of "always do this" to prevent this from happening or a way to tell LaTeX to shut up and let me format the document? I tend to hate when my tools try to think for me.

10
  • 10
    Right now, your posting comes across more as a rant than as a serious attempt to solicit information. Please consider applying some edits to counter this impression.
    – Mico
    May 11, 2021 at 21:43
  • 2
    @Mico what do you suggest as an edit? The problem is quite general in that I don't know how to approach designing a multi col document when lots of figures are involved.
    – Makogan
    May 11, 2021 at 21:49
  • 1
    @Teepeemm that document describes some common uses, but it doesn't have much information on how to deal with the 2 column problem. One option in a non columned document is to make the figures smaller, but in 2 column environments tex considers only the top region of the document to be valid and any figure spans the entirewidth rather than a single column. Minimpages cna be used to avoid that problem, but they introduced a bunch of formatting issues.
    – Makogan
    May 11, 2021 at 21:52
  • 2
    latex will not move images if you include them with \includegraphics it only moves figure environments, and it moves figure environments only to prevent getting large white space at page breaks. As you have given no indication of your coding it is very hard to tell you what to change. May 11, 2021 at 22:08
  • 2
    "any figure spans the entirewidth rather than a single column. " ????? single column figures are the default, you need to use the * form to make a 2-column spanning figure. Really unless you show an example document that shows your problem it is impossible to guess why you are having issues. May 11, 2021 at 22:32

4 Answers 4

30

Maybe these posts can help you along a bit:

Some general suggestions from these posts (and from me):

  1. Use options like [h] (here), [b] (bottom), [t] (top), [p] (seperate page) ... when including the figure, to tell LaTeX where it should place the figure. E.g. with \begin{figure}[bh] ... \end{figure} LaTeX will try to place the figure h and b. It always attempts figure placement using allowed places in the order h, t, b, p, regardless of the order specified by the user ([hbt] and [bth] do the same thing). Check post B and post C and this Overleaf Summary for details.
  2. Use ! to override internal parameters LaTeX uses for determining "good" float positions (as explained in the Overleaf Summary). E.g. \begin{figure}[h!] ... \end{figure} will ignore user constraints in order to place the figure "here". If you encounter many white spaces, it can also be because you use ! too often and you force latex to use worse placement to fulfil your request. For a good explanation of the ! check post B and post C.
  3. If you want to force "here" even more, use the float package and \begin{figure}[H], "which basically turns the floating figure into a regular non-float.", as pointed out in the top answer of post Aand it will place the figure precisely at the location in the LATEX code. Also check the documentation of the float package, and the explanation in post B and post C.
  4. Sometime is can help not to use floating environments (like figure) at all. Use \includegraphics directly in the text. See post A for details.
  5. Use \clearpage to force all above mentioned figures to be placed, before the text continues.
  6. Use the adjustbox package. Check the documentation for details.
  7. Play around with \vspace{} to put in deliberate white spaces that might help you to achieve your desired layout.
  8. Use the minipage environment. Check this post
  9. Slightly adjust the size of your figures if you notice that your figure almost fits in the spot where you want it, but it is moved because it is a bit too large. E.g. \includegraphics[scale=0.95]{myimage.png} or \includegraphics[width=0.95\textwidth]{myimage.png}
  10. Use wrapfigure to wrap text around figures. Check the wikibooks and the documentation for details.

Specifically for two-column documents:

If your figures are two-columns wide you need to insert them with \begin{figure*} ... \end{figure*} to make sure latex embeds them properly. Possibly you're running into weird placement issues because you're trying to include a two-column figure as a one-column figure. Check this post here for details. Also, be aware that figure* doesn't support [h] or [b].

I hope that some of these tools can help you with your fight against latex-figure-placement.

1
  • 1
    This is a pretty helpful post that addresses the main question, thank you.
    – Makogan
    May 12, 2021 at 5:42
12

You don't give any indication why you are getting large white spaces, that is not expected. As a possible aid I provide an example document using several figures. If you can modify this and add it to your question in a form that shows the problem you are having, someone would be able to suggest changes.

enter image description here

\documentclass[twocolumn]{article}

\usepackage{graphicx,float}
\raggedbottom
\begin{document}

\section{zzzz}
aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa 
aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa 
aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa 

\begin{figure}[htbp]
  \centering
  \includegraphics[width=\linewidth]{example-image}
  \caption{A floating figure}
\end{figure}

aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa 
aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa 
aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa 

\begin{figure}[htbp]
  \centering
  \includegraphics[width=\linewidth]{example-image-a}
  \caption{Another floating figure}
\end{figure}

aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa 
aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa 
aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa 

\begin{figure}[htbp]
  \centering
  \includegraphics[width=\linewidth]{example-image-b}
  \caption{Yet another floating figure}
\end{figure}

aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa 
aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa 
aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa 

\section{\raggedright A long appendix with non floating figures and no text}


\begin{figure}[H]
  \centering
  \includegraphics[width=.8\linewidth]{example-image-c}
  \caption{H figure}
\end{figure}

\begin{figure}[H]
  \centering
  \includegraphics[width=.8\linewidth]{example-image}
  \caption{H figure}
\end{figure}

\begin{figure}[H]
  \centering
  \includegraphics[width=.8\linewidth]{example-image-b}
  \caption{H figure}
\end{figure}

\begin{figure}[H]
  \centering
  \includegraphics[width=.8\linewidth]{example-image-a}
  \caption{H figure}
\end{figure}

\begin{figure}[H]
  \centering
  \includegraphics[width=.8\linewidth]{example-image}
  \caption{H figure}
\end{figure}

\begin{figure}[H]
  \centering
  \includegraphics[width=.8\linewidth]{example-image-c}
  \caption{H figure}
\end{figure}

\begin{figure}[H]
  \centering
  \includegraphics[width=.8\linewidth]{example-image}
  \caption{H figure}
\end{figure}


\end{document}
7

This might seem counter intuitive, but I always wait to the very last minute to add the figures. I simply write everything I want to say, and at the end I include the figures. Then I adjust the text or use the tricks mentioned above to get my desired output.

This alleviates most of the pressure from fidgeting with the figures.

2
  • 1
    This is what I was going to post – (a) the more text you have for LaTeX to work with in finding optimal positions, the better, and (b) the document will change when you add subsequent text anyway, so wrangling diagram positioning when it's partway done is a waste of time.
    – dbmag9
    May 12, 2021 at 20:20
  • 8
    Equivalently, of course, put the figures in as you go but don't worry about the appearance of the document until the end.
    – dbmag9
    May 12, 2021 at 20:22
7

What hasn't been mentioned so far in the responses and is not part of my longish post How to influence the position of float environments like figure and table in LaTeX? on the float algorithm (because it wasn't written back then) is the package fewerfloatpages (link to article on it) which implements an improved algorithm that resolves most of the issues around half-empty float pages (or alternatively everything at the end of the chapter/article). In its basic form all you have to do is loading the package and for most documents that's enough without any configuration.

But as David wrote in his reply, it is not really clear why you are having trouble, e.g., if you use always [H] (i.e., your floats don't really float then nothing helps and you will end up with bad page breaks or column breaks if the float is too big to fit and therefore moves to the next page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .