3

To implement the approach discussed here: Automatic detection of Overleaf for fallback images I wanted to give my tikz-files their own names, such that I can either include the tikz-file when compiling locally or the pdf-file when working on overleaf (which is significantly easier when knowing the file name of the PDF beforehand). Therefore, I included tikzsetnextfilename in my tikzfiles. Unfortunately, that seems to disable the scaling possibility given by includegraphics and tikzscale. As example, with two files main.tex and sub.tikz:

main.tex:

\documentclass{article}
\usepackage{standalone}
\usepackage{tikz}
\usetikzlibrary{external}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage{tikzscale}
\begin{filecontents*}{file1.dat}
    x y
    0 0
    1 1
    2 2
    3 3
    4 4
    5 5
\end{filecontents*}
\usepackage{subcaption}
\tikzexternalize[prefix=tikz-cache/]
\tikzset{external/force remake}
\usetikzlibrary{pgfplots.groupplots}

\pgfplotsset{every axis/.append style={ label style={font=\footnotesize\bfseries}, tick label style={font=\footnotesize}, legend style={font=\footnotesize} }, y axis/.append style={align=center}} \tikzset{Line Label/.style={font=\footnotesize,scale=2}} \newcommand{\figurefontsize}{\footnotesize}

\begin{document} \begin{figure}[htpb] \centering \includegraphics[width=7\linewidth]{sub.tikz} \caption{Image I} \end{figure} \end{document}

sub.tikz:

\pgfplotstableread{file1.dat}{\tablea}
\tikzsetnextfilename{sub}
\begin{tikzpicture} 
    \begin{axis}[
        ymin=0, ymax=30,
        xmin=0, xmax=5,
        xlabel={$x$},
        ylabel={$y$},
        grid=major,
        legend entries={\(y_1\),\(y_2\),\(y_1+y_2\)},
        legend pos = north west
        ]
        % Select appropriate columns
        \addplot [blue, mark=*] table [x=x,y=y] {\tablea};
    \end{axis}
\end{tikzpicture}

When disabling tikzsetnextfilename, scaling works, and the graph is scaled appropriately. Enabling it leads to a fixed scaling factor of 1, though, without any log errors or warnings. Is there a solution or an explanation (or possibly both)?

arc_lupus
  • 1,781

1 Answers1

1

For me, moving \tikzsetnextfilename{extname} out and before the \includegraphics[opts]{filename.tikz}, rather than having it inside filename.tikz solved the problem.

Enlico
  • 2,592