0

I wanted to put an image between to paragraphs. I used the following codes:

 
\documentclass[12pt,a4paper]{article}  
\usepackage{graphicx} 
\usepackage{enumerate} 
\begin{document}
\begin{enumerate}  
\item text  
\begin{figure}  
\centering  
\includegraphics[width=6cm, height=6cm]{set.png}  
\caption {$(S,\le)$}  
\label{fig:}  
\end{figure}  
\item text  
\end{enumerate}  
\end{document}

I want example (i) to be at first, then the image and then example (ii).enter image description here

enter image description here But it is appearing as the image attached here. What am I missing here?

Manjoy Das
  • 779
  • 4
  • 15
  • you have used figure which is just used to specify that the content is a float that may be moved to help with page breaking, So it is working as expected – David Carlisle Apr 05 '21 at 22:34
  • you can use \begin{figure}[htbp] then it will use the h (here) position and not move it of it fits at that position. – David Carlisle Apr 05 '21 at 22:35
  • @DavidCarlisle i tried [htbp] but still not working. the image is getting uploaded on the next page, in the very middle of the page and the writings which were supposed to be after that image are coming before the image. – Manjoy Das Apr 05 '21 at 22:38
  • https://tex.stackexchange.com/questions/2275/keeping-tables-figures-close-to-where-they-are-mentioned and https://tex.stackexchange.com/questions/8625/force-figure-placement-in-text – David Carlisle Apr 05 '21 at 22:38
  • the only thing the figure environment does is allow the figure to be moved in that way, if you include h and it still move sthen that is because it doesn't fit so moving is most likely the best thing to do. – David Carlisle Apr 05 '21 at 22:40
  • but it sets itself on the very middle of the next page.. but the texts are coming before the image. how to send them after the image? – Manjoy Das Apr 05 '21 at 22:42
  • oh you may also want to leave a blank line before \begin{figure} if you want the previous paragraph to end at that point. – David Carlisle Apr 05 '21 at 22:42
  • the texts do not move, the image moves because it is inside figure, – David Carlisle Apr 05 '21 at 22:45
  • well then how to bring the image just before the current paragraph? – Manjoy Das Apr 05 '21 at 22:46
  • you do not have to use figure \includegraphics never moves. the only reason to use figure is to allow it to move, but see the second of the lonks I gave above, or the answer I just posted. – David Carlisle Apr 05 '21 at 22:49

1 Answers1

3

As posted, the document produces

enter image description here

\documentclass[12pt,a4paper]{article}  
\usepackage{graphicx}  
\begin{document}
 text  
\begin{figure}  
\centering  
\includegraphics[width=6cm, height=6cm]{example-image.png}  
\caption {$(S,\le)$}  
\label{fig:}  
\end{figure}  
text  
\end{document}

As the float has been inserted mid-paragraph so the pargraph line breaking happens as normal (producing text text ) an and then the float is inserted at the top of the page (as the default position option is [tbp]

If you place the float between paragraphs and allow h then it appears in that place as it fits:

enter image description here

\documentclass[12pt,a4paper]{article}  
\usepackage{graphicx}  
\begin{document}
 text

\begin{figure}[htbp]
\centering
\includegraphics[width=6cm, height=6cm]{example-image.png}
\caption {$(S,\le)$}
\label{fig:}
\end{figure}

text
\end{document}

David Carlisle
  • 757,742
  • I exactly did this. But it's not working. because the first paragraph ended at most 6-7 lines prior the page end. I think that's why the image is not fitting in that page. okay that's cool!! So the image moves on to the next page. but after that when I write some texts, it goes in the previous page after the first paragraph and the image falls after the second paragraph. – Manjoy Das Apr 05 '21 at 22:53
  • @ManjoyDas isn't that what you want to happen? As far as I understand your description it sounds right. But in general if you want help with understanding latex's float postioning you should provide an example that shows your problem. It does not help if someone answers and you comment that your real case is completely different. But really this is a duplicate of the force posituion question normally we would close, I only gave a specific answer as you are new to the site. – David Carlisle Apr 05 '21 at 22:57
  • I've edited my question. Added some pictures of my problem. I think this might help you to understand. – Manjoy Das Apr 05 '21 at 23:12