I am trying to draw a pgfplot with to different y-axis with their respective label in a full line width and I can't get an alignment of the whole tikzpicture within the margins. The problem seems to come from the ylabel which, on the left axis shift the plot to the right, and on the right axis is plotted out of the picture, ie in the margin. I try to add the ylabel style={overlay} so I get the plot centered but both ylabel are this time in the margins. For sure, I can put a 0.95\linewidth but I don't find this solution good enough since it isn't generalist.
Does anyone knows how can I fix this small example in an automatically way (meaning that pgfplot or tikz finds the right width alone)?
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\centering{}
\hrule{}
I\hfill I\hfill I\\
\begin{tikzpicture}
\begin{axis}[
width=\linewidth,
xmin=-5,xmax=5,
axis y line*=left,
axis x line*=top,
ylabel={$y=x^{2}$ label},
]
\addplot {x^2};
\end{axis}
\begin{axis}[
width=\linewidth,
xmin=0,xmax=15,
domain=0:15,
axis y line*=right,
axis x line*=bottom,
ylabel={$y=x$ label},
]
\addplot[red] {x};
\end{axis}
\end{tikzpicture}
\end{document}
which produces this badly aligned plot

width=\linewidthto something else? – cmhughes Feb 5 '12 at 21:10tikzpicturefind the good width automatically so the solution will be the same for all my plots. Anyway, thanks for the answer. – Sigmun Feb 5 '12 at 21:150.95\linewidthit seems to work fine. If you want precise calculations you would need to adjust for the axis labels (which may be of different sizes). – Peter Grill Feb 5 '12 at 22:06ylabelwhich, on the left axis shift the plot to the right, and on the right axis is plotted out of the picture, ie in the margin" in the description of the problem but due to the picture within the post, I can't edit it anymore since I earn some reputation. – Sigmun Feb 5 '12 at 22:47