Graphics, Figures & TablesUsing float in a figure

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
qb170300
Posts: 3
Joined: Sat Mar 08, 2025 10:34 pm

Using float in a figure

Post by qb170300 »

Hi

I have this figure that I want to show sideways because it looks nicer that way. I do this:

Code: Select all

\begin{sidewaystable}
\begin{figure}[H]
\centering
\captionsetup{justification=centering}
\includegraphics[scale=.99]{Figures/hbar_pop_auf.pdf}
\end{figure}
\end{sidewaystable}
However, overleaf puts this figure AFTER some other figures... to avoid that I used the float package:

Code: Select all

\usepackage{float}
\begin{sidewaystable}
\begin{figure}[H]
\centering
\captionsetup{justification=centering}
\includegraphics[scale=.99]{Figures/hbar_pop_auf.pdf}
\end{figure}
\end{sidewaystable}
Now the figure appears in the correct order, but I have an annoying word: float .... appearing before the figure.

Does anyone know how to make the word "float" disappear or suggest a better strategy?

thanks

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Re: Using float in a figure

Post by Stefan Kottwitz »

Welcome to the forum!

That's not caused by the code you showed. See here, and click "Run LaTeX here" to check:

Code: Select all

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{rotating}
\usepackage{caption}
\usepackage{float}
\begin{document}
\begin{sidewaystable}
\begin{figure}[H]
\centering
\captionsetup{justification=centering}
\includegraphics[scale=.99]{Figures/hbar_pop_auf.pdf}
\end{figure}
\end{sidewaystable}
\end{document}
It's somewhere else in your code, like in a macro redefinition in your preamble. Perhaps show a complete short Infominimal working example.

Stefan
LaTeX.org admin
qb170300
Posts: 3
Joined: Sat Mar 08, 2025 10:34 pm

Re: Using float in a figure

Post by qb170300 »

Thanks, Stefan,

However, I cannot find anywhere else in my code where I use the word ´float´and this issue only occurred when I typed \usepackage{float}... I'll keep thinking about it...

david
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Re: Using float in a figure

Post by Stefan Kottwitz »

Hi David,

you can follow the "hacking down" procedure from the Infominimal working example explanation (making a copy of your code and reduce it, so it can be posted here without unrelated content) and post the result here. I'm sure that when you post the code that prints 'float', we will find the cause.

Stefan
LaTeX.org admin
qb170300
Posts: 3
Joined: Sat Mar 08, 2025 10:34 pm

Re: Using float in a figure

Post by qb170300 »

Stefan, I found the error!

Instead of using \begin{sidewaystable} I am now using \begin{landscape}. After all, this is a figure, not a table, so I guess latex went crazy not understanding why I was treating a figure like a table. When I do this, everything works nicely!

Code: Select all

\begin{landscape}
\begin{figure}[H]
\centering
\captionsetup{justification=centering}
\includegraphics[scale=.99]{Figures/hbar_pop_auf.pdf}
\end{figure}
\end{landscape}
Thanks

David
Post Reply