[Tex/LaTex] How to add graphics in LaTeX

graphics

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?

Best Answer

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}
Related Question