Error tikzscale package when scaling a figure, containing two axis environments next to each other, to the text width

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$
]

\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$
]

\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?

• Is the fact that externalization is involved here relevant to the problem? If not, I'm tempted to close as a duplicate of your other question. (I can always delete my answer there, if you feel that it reduces the chance of a better one.) Or perhaps you can specify that my suggestion is not an alternative due to the problems you mentioned. Oct 2, 2015 at 13:28
• @TorbjørnT. No the externalization has nothing to with it. The difference with the question tex.stackexchange.com/questions/230974/… is that in this example, I do not use \matrix. But besides that, the problem is the same: scaling a figure to the \texwidth. Oct 2, 2015 at 14:46
• Sorry, didn't notice that, but I dont't think that matters at all to be honest. You get exactly the same error as well. Oct 2, 2015 at 15:31
• @TorbjørnT. Indeed. Any suggestions for a solution? I unfortunately don't seem to be getting a response. Surprises me a bit, since I'm sure a lot of people have the same problem. Oct 3, 2015 at 11:17
• Some years have passed and I'm running into the same issue in the last days. Have you found any solution for that? I've found out, that using at=(plot2.right of south east), and anchor=left of south west, reduce the error probability. Furthermore scaling the height (if necessary in combination with axisratio) instead of the width` reduces the error as well. But this way you cannot scale figures to the width of the line etc. Any help appreciated! Aug 24, 2021 at 18:55