I use tikzpicture and axis environment to generate graphs. In one document I want that graph axes are vertically aligned with the text. So that ticks and labels are in the margins. If there is only one axes environment inside tikzpicture I use trim axis option and set the axis width to \textwidth and get the desired output
But problems arise when I have, lets say, two axis environments inside tikzpicture. In that case the trim axis option trims the left graph and the second graph is placed to the beginning of the line. This is how I attempted to do this and how the result looks like.
\documentclass{article}
\usepackage{blindtext}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{figure}
\begin{tikzpicture}[trim axis left, trim axis right]
\begin{axis}[
xmin=0, xmax=1, xtick={0.2,0.5,0.8}, xlabel=x, ymin=0, ymax=1, ytick={0,0.5,1},ylabel=A, height=0.49\textwidth,
width=0.49\textwidth,
scale only axis,
name=first]
\end{axis}
\begin{axis}[
xmin=0, xmax=1, xtick={0.2,0.5,0.8}, xlabel=x, ymin=0, ymax=1, ytick={0,0.5,1},ylabel=B, height=0.49\textwidth,
at=(first.south east),
anchor=south west,
xshift=0.02\textwidth,
yticklabel pos=right,
ylabel near ticks,
width=0.49\textwidth,
scale only axis]
\end{axis}
\end{tikzpicture}
\caption{\blindtext}
\end{figure}
\end{document}
How to trim only the ticks and labels? Not the whole graph.