4

I want to include a jpg to a LaTeX document, which I have done many times. Normally, I use put it in a figure environment, the code looks like this:

\documentclass[twoside]{article}
\usepackage{graphicx}

\begin{figure}
\includegraphics{myfig.jpg}
\end{figure}

When I try compiling this the document compiles, but no figure shows up. If I do not wrap the \includegraphics in a figure environment then the pdf compiles with the image. I want the figure environment, because I want to add captions/labels.

I can't figure out why this method does not work for this document, when it worked fine for other documents that I have made. The jpg is saved in the same directory as my tex file, so that is not the issue.

Any ideas?

  • Are you compiling with pdflatex? That is a requirement in order to include JPG files. – Werner May 22 '13 at 22:53
  • 2
    Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner May 23 '13 at 1:57
  • 3
    You shouldn't use an extension in the argument of \includegraphics, but that should not cause the issue. Can you edit in the .log file you get, in particular any warnings or errors? – Joseph Wright May 23 '13 at 6:07
  • "no figure shows up" - are there any warnings/errors in the logfile? – Reinstate Monica - M. Schröder May 29 '13 at 8:49
3

Probably you (or a package) have disabled \clearpage (\let\clearpage\relax). Do not do this, because \clearpage is needed. Apart from starting a new page it also forces LaTeX to output all pending floats. Thus \clearpage is automatically called at the start of \chapter and at the end of the document, for instance.

Thus if the figure is not yet output, \clearpage is disabled, and \end{document} is reached, then the figure "vanishes" and is not set in the document.

Frank Mittelbach has explained \include in this answer. If you do not want page breaks by \include, then use \input.

0

Try using the 'center' environment.

\begin{figure}
\begin{center}
\includegraphics[width=10cm]{myfig.jpg}
\caption{Blah blah blah...}
\end{center}
\end{figure}

Your figure should now show up!

  • 1
    Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner May 23 '13 at 1:58
  • 2
    instead of the center environment use \centering. It dowsn't add additional vertical space, what \caption already does. – user2478 May 23 '13 at 5:55
  • 1
    The center environment is not recommended for images, see Should I use center or centering for figures and tables? for an explanation. – Martin Scharrer May 23 '13 at 6:00

Your Answer

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