'Keeping figure just after text in Latex
I am writng in Latex. I am new with it and need some help.
I need to add figures. I can do it with the following code
\begin{figure}[h]
\includegraphics[width = 15cm]{figures/mlpStrSingle}
\caption{MLP neural network for one single output node}
\label{fig:mlp}
\end{figure}
if I use this the figure goes to next page . I need it right after the text. then the next text should start. How can I do that?
Thanks in advance.
Solution 1:[1]
A couple of possibilities:
The best approach is to embrace the position latex found for the image and don't fight against it. Latex is pretty good to determine the best locations for floats. If an image floats away this usually means it really should be placed somewhere else, for example if there is not enough space left at the position you put it. Your image is also very wide -- 15 cm is wider than the available text width for most standard classes, so it will be hard to find a place where it fits.
The second best: try if the option
[H]
from the float package can force the position you want. Thismightwill most probably result in a suboptimal layout.If you don't want an image to float at all, don't use a float.
\documentclass{article}
\usepackage{graphicx}
\usepackage{float}
\usepackage{caption}
\usepackage{lipsum}
\begin{document}
\section{Embrace the decision of latex}
\lipsum[2]
\begin{figure}[htbp]
\includegraphics[width=3cm]{example-image-duck}
\caption{MLP neural network for one single output node}
\label{fig:mlp}
\end{figure}
\lipsum[2]
\section{Insist on the position}
\lipsum[2]
\begin{figure}[H]
\includegraphics[width=3cm,page=2]{example-image-duck}
\caption{MLP neural network for one single output node}
\label{fig:mlpa}
\end{figure}
\lipsum[2]
\section{Don't use a float}
\lipsum[2]
%\begin{figure}[htbp]
\includegraphics[width=3cm,page=3]{example-image-duck}
\captionof{figure}{MLP neural network for one single output node}
% \label{fig:mlp}
%\end{figure}
\lipsum[2]
\end{document}
Solution 2:[2]
if someone still searching about this issue
\begin{figure}[hbt!]
\centering
\includegraphics[width=8cm]{image}
\caption{caption here}
\label{fig:vue-snoc-pos}
\end{figure}
\FloatBarrier
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | samcarter_is_at_topanswers.xyz |