Graphics, Figures & TablesFigure appearing above subsection title

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
JefVL
Posts: 13
Joined: Sat Mar 22, 2014 10:27 pm

Figure appearing above subsection title

Post by JefVL »

Hi all,

I'm currently writing my thesis... It's almost finished but there are a few minor things that I still need to work on. One of them is a large picture (or rather 4 pictures combined with the subcaption package) that refuses to stay in place.

Example code:

Code: Select all

\documentclass[11pt,a4paper,oneside]{article}

\usepackage{a4wide}
\usepackage[dutch]{babel}
\usepackage{amsmath}
\usepackage{url}
\usepackage{graphicx}
\usepackage[latin1]{inputenc}
\usepackage[small,bf,hang]{caption}
\usepackage{xspace}
\usepackage[per-mode=symbol, output-decimal-marker={,}, separate-uncertainty=true, exponent-product=\cdot]{siunitx}
\usepackage{microtype}
\usepackage[fixlanguage]{babelbib}
\selectbiblanguage{dutch}
\usepackage[hidelinks]{hyperref}
\usepackage{booktabs}
\usepackage{subcaption}
\captionsetup{margin=10pt,font=small,labelfont=bf}
\usepackage[usenames]{xcolor}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage{textcomp}
\usepackage[nottoc,numbib]{tocbibind}
\usepackage[top=2.5cm, bottom=2.5cm, left=3cm, right=3cm]{geometry}
\usepackage[section,below]{placeins}

\begin{document}
stuff
\section{section}
\subsection{subsection}
\subsubsection{subsubsection}
more stuff
\subsubsection{subsubsection}
even more stuff
\begin{figure}
        \centering
        \begin{subfigure}[t]{0.4\textwidth}
                \includegraphics[width=\textwidth]{LagenA}
        \end{subfigure}
        \quad
        \begin{subfigure}[t]{0.4\textwidth}
                \includegraphics[width=\textwidth]{LagenB}
        \end{subfigure}
        
        \begin{subfigure}[t]{0.5\textwidth}
                \includegraphics[width=\textwidth]{LagenC}
        \end{subfigure}
        \caption{My caption}\label{fig:Figure}
\end{figure}
last stuff
\end{document}
Now, the annoying part is: when I build my code, the picture appears right above the subsubsection title that it was placed under, at the top of the page, so the page looks like this:

[picture]
[subsubsection]
[even more stuff]

After that page, there are a few pages of text. Before it, there's another page with a large picture with a similar set-up (subfigures), which occupies the entire page.

I've tried using the float package, but that only made all my large pictures appear at the very end of the section. I tried the placeins package, which did nothing, and I've tried changing the location specifier to [h] and [!h] but LaTeX just gives a warning saying that it changed it to [ht]. I can't use a non-floating environment because the subfigure command won't work then.

Any suggestions are very welcome!

Thanks in advance,
Jef

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

JefVL
Posts: 13
Joined: Sat Mar 22, 2014 10:27 pm

Re: Figure appearing above subsection title

Post by JefVL »

Anyone, please?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Figure appearing above subsection title

Post by Stefan Kottwitz »

Hi Jef,
JefVL wrote:I tried the placeins package, which did nothing
just loading does nothing, that's correct. You need to insert the \FloatBarrier in addition, before the figure or after \subsubsection, respectively.

Besides that, it's good practice to let pictures float to the top of the page, so it doesn't break the text flow, it's commonly a preferred place. Especially because it got a number for referencing and a caption. That's traditionally for floating. It's not very meaningful to write "see figure 1 about <thing>" and immediately follows "Figure 1: the <thing>" with the image. This method is for looking up images which were put elsewhere at a good place. Which many people like to be the top. ;)

Stefan
LaTeX.org admin
JefVL
Posts: 13
Joined: Sat Mar 22, 2014 10:27 pm

Re: Figure appearing above subsection title

Post by JefVL »

Thanks Stefan, the \FloatBarrier command worked!

Iknow LaTeX places the float on the position it thinks is best, and usually I don't have a problem with that, but in my thesis I cannot place a picture before the beginning or after the end of the sub(sub)section it is cited in first :)

Thanks!
Post Reply