Failure of Inserting graphic with graphicx in Texstudio
Solution 1
The error message shows that the code you've shared is not the code which produces that message.
In your example, you have
\includegraphics[width=0.7\linewidth]{figure1}
but in the code which produces the error, you have
\includegraphics[width=0.7\linewidth]{../figure1.jpg}
Those are not the same. The first tells TeX to look in the current directory for figure1
, an image with one of the known extensions. The second tells TeX to look in the parent of the current directory for figure1.jpg
. It will not find anything if it is in the current directory instead.
./figure1
figure1
in the current directory.
figure1
figure1
in the current directory.
../figure1
figure1
in the current directory's parent directory i.e. the directory 'above' the current one.
Solution 2
@cfr is right. There's a world of difference.
I cannot offer an explanation as good as cfr. I, however, can offer what I follow as a practice.
Consider the below picture
All my .tex
files are in .tex folder
and images in Images Folder
. If I have to link to an image in Images folder I use the command \graphicspath
.
I specify the path only ONCE (before \begin{document}
) and use the images by their file name everywhere.
MWE:
\documentclass{article}
\usepackage{graphicx}
%%%%%Format:- \graphicspath{{path1}{path2}{path3}...}%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\graphicspath{{../ImagesFolder/}}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=0.7\linewidth]{LiLi-USB-Creator}
\caption{}
\label{fig:figure1}
\end{figure}
\end{document}
No matter how many images I use or how many .tex
files I create, I stick to the said structure.
AVOID SPACES IN FILE AND FOLDER NAMES. LaTeX doesn't like spaces in the files you refer to.
I tried your example in my setup -- with one alteration (graphicspath
) -- and found no errors (none, zero, zilch).
Output:
Compiler: TexLive 2015
IDE: TexStudio
OS: Ubuntu 15.10
Edit:
I have tried this with Windows 8, 8.1 and 10. \graphicspath
needed no modification.
Thanks Jan
Related videos on Youtube
Y.X.
Undergraduate student in pure mathematics. I found both the answers and references under many of my questions very useful and I can always learn something more than I expected. Thanks to the site!
Updated on December 21, 2020Comments
-
Y.X. almost 3 years
I use Texstudio and MikTex 2.9
I guess maybe there is something wrong with the package. The MikTex told me to install the package several times, but it seems that the package has not be installed.
I did put the
.tex
document and the graph in the same folder.the error says:Package pdftex.def Error: File `../figure1.jpg' not found. ...aphics[width=0.7\linewidth]{../figure1.jpg}
The following is my code.
\documentclass{article} \usepackage{graphicx} \begin{document} \begin{figure} \centering \includegraphics[width=0.7\linewidth]{figure1} \caption{} \label{fig:figure1} \end{figure} \end{document}
-
samcarter_is_at_topanswers.xyz almost 7 yearsIf they are in the same folder, then it should be
./figure1.jpg
or simplyfigure1.jpg
-
Bernard almost 7 years
.jpg
isn't even needed in general. -
Y.X. almost 7 years@Bernard I edited my code, but nothingwork:Package pdftex.def Error: File `../figure1.jpg' not found. ...aphics[width=0.7\linewidth]{../figure1.jpg}
-
Bernard almost 7 yearsJust in case: Is
graphics-def
installed? There were some changes in the architecture of latex recently. -
Y.X. almost 7 years@Bernard The MikTex asked me to install a package and I followed it. But it asked me to do the samething several times so I think maybe the installation failed.
-
Y.X. almost 7 years@Bernard I had check the MikTex, it said that it has been installed today.
-
kenivel about 4 yearsmiktex solved in URL: </br> tex.stackexchange.com/questions/511138/… </br>
-
kenivel about 4 yearsmiktex solved in URL: </br> tex.stackexchange.com/questions/511138/… </br>
-
kenivel about 4 yearsmiktex solved in URL: </br> tex.stackexchange.com/questions/511138/… </br>
-
kenivel about 4 yearsmiktex solved in URL: </br> tex.stackexchange.com/questions/511138/… </br>
-
-
Y.X. almost 7 yearsSorry but even after I correct that error it does not work...... So could you please tell me what may be wrong with that?
-
cfr almost 7 years@Y.X. 'does not work' isn't much help. What happens? Do you get a different error? Which? Does something else happen? Does your computer explode? Presumably you don't get the same error once you've corrected it, so you need to now address the next one.
-
Y.X. almost 7 yearsJust the same error, NO change happens.
-
cfr almost 7 years@Y.X. If you get exactly the same error after correcting the cause of that error i.e. the error message includes context which is not present in your file at all, delete all generated files and retry. If you still get the same error then either your TeX installation or something else is seriously screwed up. File system corruption, failing hardware, malicious OS, mixed up TeX installation ... You have serious problems if TeX thinks your file includes
../
when it does not. Certainly, those problems are well beyond me. -
Jan almost 7 yearsthis is also en excellent answer and a lesson worth learning. In my experience, you also have to avoid the usual Windows path separation character, (
`), which has a special meaning in LaTeX. Instead, you have to replace all backslashes into normal slashes (
/`).