I'm writing my PhD thesis and I have just discovered the matlab2tikz script for MATLAB so I wanted to convert my plots and put them in the document using pgfplots. My thesis is already very big and when I compile it takes a long time so I wanted to make use of the standalone package to compile the graphs externally so as to speed up the process. matlab2tikz outputs a .tex or .tikz file with the necessary code, an example is:
\begin{tikzpicture}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
\draw (23,42) .. controls (23,28.19) and (34.19,17) .. (48,17) .. controls (61.81,17) and (73,28.19) .. (73,42) .. controls (73,55.81) and (61.81,67) .. (48,67) .. controls (34.19,67) and (23,55.81) .. (23,42) -- cycle ;
\end{tikzpicture}
\end{tikzpicture}
In this case, I saved the file as a .tex. Then, following the instructions of the standalone package manual, I modified the file as follows
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
\draw (23,42) .. controls (23,28.19) and (34.19,17) .. (48,17) .. controls (61.81,17) and (73,28.19) .. (73,42) .. controls (73,55.81) and (61.81,67) .. (48,67) .. controls (34.19,67) and (23,55.81) .. (23,42) -- cycle ;
\end{tikzpicture}
\end{document}
and saved it as test.tex. When I try to compile the document, whether I have \includestandalone[width=\textwidth]{test} or \input{test} I get Can be used only in preamble error. I'm sure it has to do with the fact that test.tex is not in the main document folder, it's instead in the same folder as all the images. My question is, therefore, this: What should be included in the preamble to point to the folder that contains the files with the TikZ plots? Below is my preamble with a minimal working example:
\documentclass[11pt,english,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{setspace}
\usepackage[acronym,nopostdot,style=index,nogroupskip,nomain]{glossaries-extra}
\usepackage{epsfig}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{graphicx}
\usepackage{comment,array,url}
\usepackage[font={small,it},center]{caption}
\usepackage[list=true]{subcaption}
\usepackage{multirow}
\usepackage{geometry}
\usepackage{framed}
\usepackage[Conny]{fncychap}
\usepackage[toc,page]{appendix}
\usepackage{bibentry}
\nobibliography*
\usepackage{gensymb}
\usepackage{standalone}
\usepackage{pgfplots}
\usepackage[hidelinks]{hyperref}
\makeglossaries
\setabbreviationstyle[acronym]{long-short}
\loadglsentries{D:/Dropbox/NTU/Research/Resources/03_glossary.tex}
\graphicspath{{D:/Dropbox/NTU/Research/Resources/02_All_images/}{}}
\begin{document}
\begin{figure}
\includestandalone[width=\textwidth]{test}
\caption{Caption}
\end{figure}
\end{document}


tikzpictures. always setcompatlevel when using PGFPlots. – hpekristiansen Feb 25 '24 at 07:38