46

I am writing a LaTeX document with the apacite and graphicx package. The issue is when I include an image either using figure with an enclosed \includegraphics or \includegraphics by itself it shows the image with the file name to the side.

For example:

            --------------
            |             |
            |    BOX 1    |  
            ---------------
Error1.jpg

I do not want it to write Error1.jpg. Would show the image but it seems I do not have enough rep.

This is an example tex file to show the error (with Windows XP, using Miktex 2.8).

\documentclass[man]{apa}
\usepackage{apacite}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\begin{document} 

\includegraphics{Example Error1.jpg}
\begin{figure}[htb]
\includegraphics{Example Error1.jpg}
\caption{This is the caption of the figure.}
\label{fig:fig2}
\end{figure}
\end{document}
egreg
  • 1,121,712

5 Answers5

57

Old post, but you can do the following.

\includegraphics{"Example Error1".jpg}
  • 6
    This should definitely be the chosen answer. – LondonRob Jun 09 '14 at 14:11
  • I used the answer given by Claudio Fiandrino of simply adding "" around the file name for example, \includegraphics{"Example Error1".jpg} –  Jun 23 '15 at 03:40
  • This doesn't work for me. I'm using a filename with spaces in a for loop (ie bla 001.png, bla 002.png, bla 003.png, etc) – user134593 Dec 10 '18 at 11:27
31

You should also avoid other special characters like underscores in the complete path and the name of the file. But you can use the grffile package for extended file processing. For this case, just add the following line:

\usepackage{grffile}
8

I found the answer while writing this since I wrote ExampleError1.jpg when doing the example image. The problem is that graphicx doesn't seem to like the spaces in the file name and it assumes it should write it. I tried writing Example\ Error1.jpg but it didn't like it either. The solution I propose is that write these filenames without spaces.

Werner
  • 603,163
4

The answer is simple. No need to change your existing file names or use a different package.

Do 2 things:

  1. Use {} to encircle your file name so that \includegraphics does not see the dots and spaces in your path;
  2. Use "" inside the {} so that the filename is not displayed in your pdf printout.

Example:

\usepackage{graphicx}

\begin{document}
\begin{figure}
    \includegraphics{{"../Current folder/1.This file"}.png}
\end{figure}
\end{document}

(For Windows users,) please note that the slashes all need to be forward slashes.

Argyll
  • 849
  • 2
    Using braces is quite dangerous, because it depends, how the file name is internally parsed. A change and the curly braces will become part of the file name. – Heiko Oberdiek May 31 '18 at 17:36
1

Even though you add the package graphics, you might not avoid the problem if the document class is declared as draft.

\documentclass[12pt, draft]{report}

It is worth to remove the draft in the document class so the images will be displayed.