Preventing images from floating out of position

I am using includegraphics to place images. These are basically answers to questions, therefore I would like to images to appear immediately below the question label. However, I the images just keep floating out of position and appear on top of the question label. How can I prevent this?

Sample code below:

\documentclass[12pt]{article}

\usepackage{graphicx}
\usepackage{epstopdf}

\DeclareMathSizes{11}{11}{11}{11}

\begin{document}

\setlength\parindent{0pt}

\textbf{1.} [Nothing to submit]

\textbf{2. (a)}
\includegraphics[scale=0.25]{graphs/fig_2a.eps}

\textbf{2. (b)}
\includegraphics[scale=0.25]{graphs/fig_2b.eps}

\end{document}

• images only float of you put them in a floating environment such as figure with your example the images will always appear exct;y where placed in the source. (Unrelated but it is almost always better to use a structura; environment such as a list and \item rather than numbering by hand \textbf{2. (b)} Aug 29, 2013 at 21:02
• @DavidCarlisle Thanks for the feedback. However, I am actually seeing the image and then the question label. Aug 29, 2013 at 21:07
• No, as noted below they are just side by side on the same line, but the image is bigger, just as if you had gone {\textbf (1a)} {\Huge X} The X doesn't float but its top is above that of 1a Aug 29, 2013 at 21:09

\includegraphics never floats, it is positioned in the same way as a letter such as X.

\textbf{2. (a)}
\includegraphics[scale=0.25]{graphs/fig_2a.eps}


Is the same as

\textbf{2. (a)} \includegraphics[scale=0.25]{graphs/fig_2a.eps}


so if the image fits, it puts a word space after the number then the image with its base on the baseline of the text.

As for text, if you want it to come underneath, put it in a new paragraph

\textbf{2. (a)}

\includegraphics[scale=0.25]{graphs/fig_2a.eps}


Although as noted in comments it is better to number automatically and just have

\item \includegraphics[scale=0.25]{graphs/fig_2a}


together with a suitable list definition.

[demo] just for the example, remove from real code.

\documentclass{article}

\usepackage[demo]{graphics}

\renewcommand\labelenumii{\theenumi. (\theenumii)}
\begin{document}

\begin{enumerate}

\item the first lot
\begin{enumerate}

\item \mbox{}\\\includegraphics{1.a}
\item \mbox{}\\\includegraphics{1.b}

\end{enumerate}

\item the second lot

\begin{enumerate}

\item \mbox{}\\\includegraphics{2.a}
\item \mbox{}\\\includegraphics{2.b}

\end{enumerate}
\end{enumerate}

\end{document}

• I tried using "\item[\includegraphics[scale=0.25]{graphs/fig_2a}]", I get an error.. "! Argument of \Gin@ii has an extra }." Aug 29, 2013 at 21:22
• @ShamimHafiz sorry, I fixed the code fragment: it is a general issue in latex that if you need to use one [] argument inside another you need to "hide" it inside a {} group. So \item[{... \includegraphics[..]{...}.. }] Aug 29, 2013 at 21:25
• @ShamimHafiz sorry again: please see updated code. In this case you don't want the optional argument of item (or it will not number) you would also want a modified list environment (eg enumitem package) that puts a line break after the number, so the image comes on the next line Aug 29, 2013 at 21:28
• Thanks for the update. I tried using enumitem package, but the numbering is not still fixed. Would you be able to add some sample code? Aug 29, 2013 at 21:32
• @ShamimHafiz example doc added Aug 29, 2013 at 22:07