9

How can we define the path if our file is at another place?

I got this one that in preamble, we will write

\usepackage{graphicx}

Then for uploading graphics we will use

\includegraphics{File.extension}

But what in case if file is at another place, how will I give the path to it, how will I center it and how can I add text to it?

Speravir
  • 19,491
Gurpreet
  • 423

3 Answers3

8

For the sake of synchronizing our mind, lets assume:

  • the main input file is in a folder named Current (for example),
  • the folder Current is in a folder named Parent,
  • a folder named diagrams containing diagrams is also in the folder Parent,
  • a folder named photos containing photos is in the folder Current.

By using \graphicspath you can declare the paths to the photos and diagrams you want to refer in you main input file. Each path must be enclosed in {} and must be ended with /.

The remaining should be clear.

\documentclass{article}
\usepackage{graphicx}
\graphicspath{{photos/},{../diagrams/}}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=0.8\linewidth]{filename}% no need to specify the file extension
\caption{Karl's students }
\label{fig:Karlsstudents}
\end{figure}
\end{document}
5

General advice: place all graphics file in a 'pictures' subdirectory directly under your path. You can then load the files using

\includegraphics{./pictures/File.extension}

Using the Dot-Notation you can also use directories above. The following line would go one directory level up (from the directory where your TeX file is), would then go to the 'myfiles/pictures' directory and use 'File.extension'

\includegraphics{../myfiles/pictures/File.extension}

I would not recommend you to separate the TeX files and the graphics files completely. Having everything together makes moving the document directory much easier.

Uwe Ziegenhagen
  • 13,168
  • 5
  • 53
  • 93
  • If you want to go three levels up, how do you do: ../../.. or ....? I don't remember where, but I have seen both ways of doing it, and just don't know which one does TeX uses. – Manuel Apr 06 '13 at 20:19
  • 1
    '../../..' is correct. – Uwe Ziegenhagen Apr 07 '13 at 04:12
  • Somehow, I got it by doing one thing, defining path name and then giving file name and its extension. Anyways, Thank you very much.. – Gurpreet Apr 09 '13 at 06:53
3

I'm using the current setup for figures:

\begin{figure}[htbp]
    \centering
    \includegraphics[width = 0.8\textwidth]{path/figurefile}
    \caption{Somecaption \label{fig:somelabel}}
\end{figure}

It is also possible to specify \graphicspath{path} in the preamble such that you can omit path/ in includegraphics. LaTeX will then search for figurefile in path, but not subfolders of path, them you will have to specify in \includegraphics.

Holene
  • 6,920