#StackBounty: #pgfplots #floats #scaling #tikzscale Error `tikzscale` package when scaling a figure, containing two axis environments n…

Bounty: 50

I have a figure environment with which I depict two pgfplots axis environments next to each other. I want to scale the figure such that it uses the full textwidth. I attempt to do so by means of the tikzscale package. I however, get the error

! Package pgfplots Error: Error: Plot width `-144.19234pt' is too small. This cannot be implemented while maintaining constant size for labels. Sorry, label sizes are only approximate. You will need to adjust your width..

while there is plenty of room to scale the figure.

The minimum working example is as follows.

documentclass{article}

usepackage{currfile}
usepackage{float} % Improved interface for floating objects.
usepackage{lipsum} % For test purposes.
usepackage{pgfplots}
usepackage{showframe}
usepackage{tikzscale}

% TikZ libraries.
usetikzlibrary{calc}
usetikzlibrary{external}
tikzset{external/system call={lualatex -shell-escape -halt-on-error -interaction=batchmode -jobname "image" "texsource"}}
tikzexternalize
usetikzlibrary{plotmarks}

begin{document}
    lipsum[1]
    begin{figure}[H]
        begin{center}
            tikzset{external/remake next}
            tikzsetnextfilename{currfiledir tikzpicture}
            includegraphics[width=textwidth]{currfiledir tikzpicture.tikz}
        end{center}
        caption{Test caption.}
    end{figure}
    lipsum[2]
end{document}

The content of tikzpicture.tikz is represented by

begin{tikzpicture}

    begin{loglogaxis}
    [
        name=plot_left,
        xlabel=$x$,
        ylabel=$y$
    ]

        addplot {x};

    end{loglogaxis}

    begin{loglogaxis}
    [
        name=plot_right,
        at={($(plot_left.outer east)+(5mm,0)$)},
        anchor=outer west,
        legend style=
        {
            at={(1,1)},
            anchor=north west,
            draw=none,
            fill=none
        },
        legend cell align=left,
        xlabel=$x$,
        ylabel=$y$
    ]

        addplot {x};

        legend
        {
            $l_1$
        }

    end{loglogaxis}

    draw[dashed,line width=0pt] (plot_left.outer south west) rectangle (plot_left.outer north east);
    draw[dashed,line width=0pt] (plot_right.outer south west) rectangle (plot_right.outer north east);

end{tikzpicture}

How do I resolve this error?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.