2

I came up with a tikZ figure, which I have written in a file, lets call it A.tex. This figure uses image files (.jpg, ...), which are included as nodes using \includegraphics. Now obvisously, I'd like to \import the figure A.tex in my main document file main.tex, but it seems like LaTeX can't find the individually loaded jpgs. My filesystem structure is as:

document_root_dir
     |
     -----main.tex
     -----figures
             |
             ---A.tex
             ---neededImage1.jpg
             ---neededImage2.jpg

Instead of \importI also tried \include which does not throw an error, but also does not load/display the figure. Therefore I am wondering, what am I doing wrong?

Thanks!

main.tex

\documentclass[./report.tex]{subfile}

\begin{figure}[ht!]
    \begin{center}
        \import{figures/A.tex}
    \end{center}
\end{figure}

A.tex

\documentclass[tikz,border=1cm]{standalone}
\usetikzlibrary{shapes,positioning, backgrounds,scopes,calc}

\begin{document}
\begin{tikzpicture}

\node[inner sep=0pt] (img1) at (0.5,0.5) {\includegraphics[width=1cm]{neededFile.jpg}};

\end{tikzpicture}
\end{document}
2

Here is a solution that allows compilation of main.tex and also of A.tex separately:

  • Call the \import command with two arguments (path and filename): \import{./figures/}{A.tex}
  • Load the packages standalone, tikz and import in the main file.

Here is a working example. Note that I use article instead of subfile and that the image filename neededFile.png might be different in your case.

main.tex

\documentclass{article}
\usepackage{tikz}
\usepackage{standalone}
\usepackage{import}

\begin{document}
\begin{figure}[ht!]
    \begin{center}
        \import{./figures/}{A.tex}
    \end{center}
\end{figure}
\end{document}

A.tex

\documentclass[tikz,border=1cm]{standalone}

\usetikzlibrary{shapes,positioning, backgrounds,scopes,calc}

\begin{document}
\begin{tikzpicture}

\node[inner sep=0pt] (img1) at (0.5,0.5) {\includegraphics[width=1cm]{neededFile.png}};

\end{tikzpicture}
\end{document}
  • 1
    Thanks! It works nicely, but now obviously the figure alone can't be compiled. Isn't it also possible somehow to do this? Thats why I had the standaloneat the figure. – avermaet Nov 9 '19 at 11:17
  • 1
    @avermaet See updated answer using the import package, which now allows compilation of the figure alone. I guess the only thing that you were missing was \import{./figures/}{A.tex} – wimi Nov 9 '19 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.