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?

figureandtableis 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 usuallytbp\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