Graphics, Figures & Tablestables and figures are not where they are supposed to be

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
frcom
Posts: 4
Joined: Fri Feb 01, 2019 1:32 pm

tables and figures are not where they are supposed to be

Post by frcom »

Hi,
I'd like to include a graphic/table to my .tex-doc. My code looks like this:
\begin{table}[h]
\caption[text]{some more text}
\begin{tabular}{l|l|l}
text & text & text
\end{tabular}
\end{table}

But this table is not where I want it to be. It depends on how much space on the current page is left. Sometimes it's right and sometimes its the hell where. If there is not enough space left, i'd like to have it directly on the next page, but it is not even in the right section but in one of the following sections. I have the same issue with some pictures which I include with \usepackage{graphicx}
...
\begin{figure}
\includegraphics[width=1\textwidth]{plot.png}
\caption[text]{some more text}
\end{figure}


can someone help me?
thanks and have a good day

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

Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

tables and figures are not where they are supposed to be

Post by Stefan Kottwitz »

Hi,

welcome to the forum!

LaTeX tries to position figures and tables depending on the space on the page. If there's enough space, it's placed right "here" in the text where you put it. If there's not so much space, or if the page break would be better, it would put the figure or table on top of the next page and let the following text fill up the page before.

You can get the easiest and most flexible positioning with optimal automatic page breaks by declaring all possible positioning options:

Code: Select all

\begin{table}[htbp!]
...
\begin{figure}[htbp!]
...
Stefan
LaTeX.org admin
frcom
Posts: 4
Joined: Fri Feb 01, 2019 1:32 pm

tables and figures are not where they are supposed to be

Post by frcom »

Hi,
Thank you for your reply! [htbp!] does not work with me... My Table is still in another section... e.g.:
\section{1}
some text
\begin{table}[htbp!]
...
\section{2}
some text


and if I compile this, the table is shown in section 2... I don't really care wheres the table in section 1 but I cant work with it if the table is in section 2

hope you know what to do...
greetings
User avatar
Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

tables and figures are not where they are supposed to be

Post by Stefan Kottwitz »

The default is to keep tables in the chapter. This way you can keep them in the same section:

Code: Select all

\usepackage[section]{placeins}
Stefan
LaTeX.org admin
Post Reply