3

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?

Adriaan
  • 3,675
  • 2
  • 21
  • 41
  • 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. – Torbjørn T. Oct 02 '15 at 13:28
  • @TorbjørnT. No the externalization has nothing to with it. The difference with the question http://tex.stackexchange.com/questions/230974/conflict-tikzscale-and-matrix-group-plot?noredirect=1#comment650030_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. – Adriaan Oct 02 '15 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. – Torbjørn T. Oct 02 '15 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. – Adriaan Oct 03 '15 at 11:17
  • Nothing very good, no. You might want to contact the author of tikzscale and tell him of this, perhaps he can find a fix for the package. – Torbjørn T. Oct 03 '15 at 15:23
  • @TorbjørnT. I already did on 20-03-2015. Unfortunately, I did not get a response from him. I'll send him a reminder. – Adriaan Oct 03 '15 at 16:06
  • 3
    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!

    – Nivek Aug 24 '21 at 18:55

0 Answers0