30

I know that includegraphics can be used in Latex to include images into the document, but how can I specify a path for that file?

\includegraphics[]{picture-name}

Instead of asdd.jpg I want to specify C:\Documents and Settings\Nina\asdd.jpg, because that's where the image is.

lockstep
  • 250,273
  • There is a LaTeX-specific page in the StackExchange network. Consider that one. – 0xC0000022L Apr 09 '11 at 15:36
  • And what's with that {imgs/RTS}? where it is located? i need the image asdd.jpg from C:\Documents and Settings\Nina folder. How can i specify this?? – qwerty Apr 09 '11 at 15:43
  • @qwerty: Rather than "answering" your question, you should edit the original question to include the additional information. (You may have to register at tex.se in order to do so.) – lockstep Apr 09 '11 at 15:46
  • But tell me, how can i specify that folder and the image wihtin that folder? – qwerty Apr 09 '11 at 15:47
  • I just told you - you place the full path in the {image} field. Works for me. – TomMD Apr 09 '11 at 15:49
  • So, if i replace {image} with {C:\Documents and Settings\Nina\asdd.jpg}, is this correct? – qwerty Apr 09 '11 at 15:57
  • No. Read my answer. You don't specify the file extension (the .jpg). Also, JPG is only ok if you're using pdflatex and not pslatex. See the [wikibooks article(http://en.wikibooks.org/wiki/LaTeX/Importing_Graphics#Supported_image_formats)]. – TomMD Apr 09 '11 at 16:10
  • @qwerty: As TomMD already stated in his answer (which is pretty detailed already), the spaces in the path name between "Documents", "and" and "Settings" might pose problems, so that you'd have to replace it by {C:\Documents\ and\ Settings\Nina\asdd} – MostlyHarmless Apr 09 '11 at 16:11
  • qwerty: I moved your answer post to a comment under you question where it belongs. Please register yourself here and connect with your stackoverflow account to take ownership of the question. You answer created a new unregistered and independent account. I will merge them later if you register here. Thanks. – Martin Scharrer Apr 09 '11 at 16:41
  • This also doens't work: \includegraphics[scale=.3]{C:/Users/Johannes/SBW/Logos/sbw+neue-medien_cmyk.eps} – theking2 Jul 23 '17 at 11:54

6 Answers6

38

You need to write the \ as / because (La)TeX follows the Unix style (which is also used for WWW addresses). Also the spaces in the filename are a problem. You can load the grffile package with the space option to make things easier as mentioned by Herbert in How to include graphics with spaces in their path?. If it wouldn't be for the \vs./ your question would be a duplicate of it. Alternatively try to enclose the file base in { } as explained in \includegraphics: Dots in filename.

% Preamble
\usepackage{graphicx}
\usepackage[space]{grffile}
%...
% Document
\includegraphics{C:/Documents and Settings/Nina/asdd.jpg}
Martin Scharrer
  • 262,582
7

You may use following command:

\graphicspath{{<your path>}}

Also see this and this.

David Carlisle
  • 757,742
5

I had no issues when I put the path directly where the picture name belongs, for example:

\begin{figure}[t]
  %\epsfig{figure=RTS.eps,height=5.5cm}
  \includegraphics[height=5.5cm]{imgs/RTS}
  \caption{The run-time system intercepts calls that cross protection domains, allocating
  new stacks, updating memory permissions and tracking old stack and credential values
  for use once the callee returns.}
  \label{fig:rts}
\end{figure}

In the above "imgs" is the immediate (local) directory and RTS is the file minus the extension. I have "RTS.pdf" and "RTS.eps" files in that directory containing my image.

pslatex or pdflatex will use the correct file for their respective needs.

EDIT: And yes, if I place the full path (/home/username/..., the Linux equal of C:\Documents and Settings\...)instead of just a relative path (the immediate sub-directory of imgs) then it also works fine.

If you're still having trouble then perhaps you need to escape the spaces in your path: C:\Documents\ and\ Settings\...

TomMD
  • 151
3

If the images are in the same folder, use \graphicspath{}

Emre
  • 6,337
0

There are a number of options. Say tex files are in folder "/my/report/" and your graph "graph.jpg" is in "/my/report/graphs/"

Option 1 : use the full path : \includegraphics{/my/report/graphs/graph.jpg}

Option 2 : use a relative path : \includegraphics{../graphs/graph.jpg}

Option 3 : Use "graphics path" as in this website https://texblog.org/2017/12/05/the-path-to-your-figures/

The weakness of the first : move your files folder, and the tex file will fail. The weakness of the third : redefining variables is a pain. => I prefer the second.

*p.s. there's something odd with the relative path : since the form "../" means "one level up in the directory structure", it seems to point to the wrong location as far as I'm concerned. It should be "./graphs", not ../graphs"

To spell this out, if I have a folder "/texts" an subfolder "/texts/graphs", and am compiling my tex files in /texts, I'd expect to point to graphs by "./graphs" But that's the way it is : "../graphs" is the form to use.*

James
  • 1
0

I use double periods to specify the path. \begin{figure}[h!] \centering \includegraphics[width=0.8\textwidth]{../../Pictures/stong2} \caption{On top of a mountain}\label{fig:st} \end{figure}

If you are not sure about the path, try right click on the image and click properties. It'll show the folder path.

NW FS
  • 1