DEV Community

latexteada
latexteada

Posted on

LaTeX Images: Images and Files in another path

Hello, how are you? :)

Do you remember that we talked about figures, the graphicx package, and the \includegraphics command?

Well, we were supposing that our images were on the same level of our document, it is, in the same folder. But what can we do if that is not our case, what if our image is in another folder? What can we do? There are three options, let's check them all

  1. Images in the same level
  2. Images in a folder that is inside the current folder
  3. Images in a folder that is outside the current folder

These situations also work with another kind of files, for example, other LaTeX documents, you just change the \includegraphics for the desired command

Option 1. Images in the same level

If the image is at the same level, we just use the \includegraphics command in the usual way

\includegraphics{nameOfTheImage.extension}
Enter fullscreen mode Exit fullscreen mode

Option 2. Images in a folder that is inside the current folder

To illustrate this, we are going to suppose that the folder where the images are is called Images, so

  • Just one folder
\includegraphics{Images/nameOfTheImage.extension}
Enter fullscreen mode Exit fullscreen mode
  • More than one folder

If our images are inside the folder Images which is inside Fn-1, and so on until F1

\includegraphics{F1/.../Fn-1/Images/nameOfTheImage.extension}
Enter fullscreen mode Exit fullscreen mode

Did you catch the idea? You need to put the name of all the folders until reach the folder where the image is

Option 3. Images in a folder that is outside the current folder

The way that we tell the computer to go back is with .., yes, two dots ..

The .. command goes back one level in our directory

Yes? Let me explain this with an example:

Let's suppose that we are in the directory Documents/MyFolders/LaTeX, and that in MyFolders we also have the folders Music, Pics, Videos (and also LaTeX) but we are already there, so, if we are in Documents/MyFolders/LaTeX and we write .. it tells to the computer go back one level, this is going to place us in Documents/MyFolders and now we can access any of the folders that are in that level, these are Music, Pics, Videos and LaTeX. Let's take this structure to illustrate the examples

  • Let's suppose we have our image one level up of our current folder, we need to write
\includegraphics{../nameOfImage.extension}
Enter fullscreen mode Exit fullscreen mode

So according to our example, the image is in the MyFolders folder

  • What happens if my image is in the Pics folder?, well if we are in the LaTeX folder we need to go back and then go tho the Pics folder, this is
\includegraphics{../Pics/nameOfImage.extension}
Enter fullscreen mode Exit fullscreen mode

Did you catch the idea? You first need to reach the folder where is the folder which has the image and then go to the desired folder

Top comments (0)