0

I'm currently writing something with overleaf latex but I'm having the issue that images or tables get set to positions I don't want it to.

\begin{figure}[htb]
 \centering
 \includegraphics[width=0.8\textwidth,angle=0]{src/pics/ex.PNG}
 \caption[caption]{Image}
\label{fig:caption}
\end{figure}

\begin{table}[] \centering \begin{tabular}{c|c} & \ & \end{tabular} \caption{Caption} \label{tab:my_label} \end{table}

So the table should appear right beneath the image but gets moved to the subsection above.

Is there a way to change this?

Bernard
  • 271,350
Ronnee
  • 1
  • The only purpose of figure and table is to specify the content can be moved. \begin{table}[] actually specifies that it can be moved but is not allowed to be placed anywhere. Latex detects that and ignores the optional argument so uses the default position which is usually tbp \begin{figure}[htb] has the effect of preventing the figure being placed on a float page so makes it more likely that it goes to the end of the document. – David Carlisle Feb 17 '21 at 10:57

1 Answers1

1

Like this:

enter image description here

Insert image and table in the same float, for example figure and than for table use \captionof{table}{...} defined in the caption or capt-of package:

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}

\usepackage{lipsum}

\begin{document} \lipsum[11] \begin{figure}[htb] \centering \includegraphics[width=0.8\textwidth,angle=0]{example-image-duck}%{src/pics/ex.PNG} \caption[Image]{Long caption of the image} \label{fig:image}

\bigskip % for adding vertical distance between image and table \begin{tabular}{c|c} \hline aaaa & bbbb \ ccccc & dd \ \hline \end{tabular} \captionof{table}[Table]{Long caption of the Table} \label{tab:my_label} \end{figure} \lipsum[12] \end{document}

Zarko
  • 296,517