# How to add graphics in LaTeX

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}


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

-
That’s in no way related to TeXnicCenter, therefore I made an edit to the title. – Speravir Apr 6 '13 at 20:15
Related (no duplicate): How to include graphics with spaces in their path?. – Speravir Apr 6 '13 at 20:27

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.

-
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 6 '13 at 20:19
'../../..' is correct. – Uwe Ziegenhagen Apr 7 '13 at 4: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 9 '13 at 6:53

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.

-
Yeah, I got it. – Gurpreet Apr 9 '13 at 6:54
Yeah I got it. Thank you Holena.. – Gurpreet Apr 9 '13 at 6:55

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}

-