I want to create a plot with a second, smaller plot as an inset. This is easy enough using the following code, where the widths of the plots are defined. However, I often use figures in several different documents like two-column papers, presentations and my thesis, each of which have different \textwidths. I therefore use tikzscale to scale the figure to the appropriate size while preserving font-sizes etc. This, however, implies, that I should not define a width for the axis environment as shown in this question. But if I don't define a fixed width for the main plot, then I also cannot define a width for the inset.
Is there a possibility to set the widthof the inset to a value relative to the main plot's width without having given the main plot an explicit width (i.e. the main plot's widthis unknown)?
\documentclass[crop,10pt]{standalone}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=12cm,
name=mainplot,
enlargelimits=false,
]
\addplot coordinates {(0,0) (1,1) (2,2)};
\end{axis}
\begin{axis}[
width=4cm,
at={($(mainplot.north west) + (rel axis cs:0.1,-0.1)$)},
anchor=north west,
enlargelimits=false,
]
\addplot coordinates {(0,2) (1,1) (2,0)};
\end{axis}
\end{tikzpicture}
\end{document}

tikzscale. Yet, I still want the inset to have a certain relative width with respect to the main plot. – Janek Jun 23 '14 at 14:29width. Because in the question your MWE doesn't contain sometikzscalecode nor it that package mentioned (in the question) at all we cannot reproduce your problem, if there would be any regarding Torbjørn's code together withtikzscale, please edit your question accordingly or the question will be closed as "unclear what you are asking" to get it of the "still open question" list. Many thanks. – Stefan Pinnow Feb 04 '17 at 08:14tikzscalebecause the problem is not related to it. The question is about creating an inset plot with a width relative to an (unknown) variable main plot width. I only mentionedtikzscaleto explain why I do not just define a fixed main plot width. You are right, however, that by deleting the line starting withwidththe code is working as intended. – Janek Jun 09 '17 at 13:49