1

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}
3
  • 1
    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)} – David Carlisle Aug 29 '13 at 21:02
  • @DavidCarlisle Thanks for the feedback. However, I am actually seeing the image and then the question label. – Shamim Hafiz Aug 29 '13 at 21:07
  • 1
    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 – David Carlisle Aug 29 '13 at 21:09
7

\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.


enter image description here

[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}
5
  • I tried using "\item[\includegraphics[scale=0.25]{graphs/fig_2a}]", I get an error.. "! Argument of \Gin@ii has an extra }." – Shamim Hafiz Aug 29 '13 at 21:22
  • 1
    @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[..]{...}.. }] – David Carlisle Aug 29 '13 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 – David Carlisle Aug 29 '13 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? – Shamim Hafiz Aug 29 '13 at 21:32
  • 1
    @ShamimHafiz example doc added – David Carlisle Aug 29 '13 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.