TransWikia.com

Using tikzsetnextfilename for naming external tikz-files disables tikzscale

TeX - LaTeX Asked on May 31, 2021

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=footnotesizebfseries},
        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=7linewidth]{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)?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP