I have a standalone document that contains two plots. See MWE:
\documentclass[tikz]{standalone}
% PACKAGES LOADING
\usepackage{pgfplots} % To draw plots.
% TIKZ & PGFPLOTS LIBRARIES & SETTINGS
\pgfplotsset{compat=1.6}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{fit, calc, matrix, positioning, arrows.meta, intersections, through, backgrounds, patterns}
\pgfplotsset{compat=1.17}
\usetikzlibrary{arrows.meta,
intersections,
positioning}
\pgfplotsset{width=6cm, height=6cm, % <---
axis lines=middle,
xlabel={$\cdot$},
xlabel style={anchor=west},
ylabel={$u(\cdot)$},
ylabel style={anchor=south},
xtick=\empty, ytick=\empty,
clip=false,
ylabel style={overlay},
yticklabel style={overlay},
}
\tikzset{
ddline/.append style = {draw=gray, densely dotted},
tick/.style = {inner sep=2pt, font=\footnotesize, align=right}
}
% FIGURES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
% Figure 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tikzpicture}[baseline]
\begin{axis}[
axis x line shift={-ln(0.1)}, % <---
xmin = 0,
domain = 0.1:5,
samples = 100,
scale = 1.5
]
\addplot [thick] {ln(\x)};
%
\draw[ddline]
(0.5,{ln(0.1)}) node[tick,below,yshift=-1.97pt] {$x$} |- coordinate[pos=0.5] (ux)
(0,{ln(0.5)}) node[tick,left] {$u(x)$};
\draw[ddline, name path=B]
(2,{ln(0.1)}) node[tick,below,xshift=20pt] {$px+(1-p)y$} |-
(0,{ln(2)}) node[tick,left] {$u(px+(1-p)y)$};
\draw[ddline]
(4,{ln(0.1)}) node[tick,below,yshift=-1.97pt] {$y$} |- coordinate[pos=0.5] (uy)
(0,{ln(4)}) node[tick,left] {$u(y)$};
\draw[name path=A, semitransparent] (ux) -- (uy);
\draw[name intersections={of=A and B, by=s}, ddline]
(s) -- (s -| 1.2,1.2) node[tick,left] {};
\draw[ddline]
(1.2,{ln(0.1)}) node[tick,below] {$c(F,u)$} |-
(0,{ln(1.22)}) node[tick,left] {$pu(x)+(1-p)u(y)$};
\end{axis}
\end{tikzpicture}%
% Figure 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tikzpicture}[baseline]
\begin{axis}[
axis x line shift={-ln(0.1)}, % <---
xmin = 0,
domain = 0.1:5,
samples = 100,
scale = 1.5,
]
\addplot [thick] {ln(\x)};
%
\draw[ddline]
(0.5,{ln(0.1)}) node[tick,below,yshift=-1.97pt] {$x-\varepsilon$} |- coordinate[pos=0.5] (ux)
(0,{ln(0.5)}) node[tick,left] {$u(x-\varepsilon)$};
\draw[ddline, name path=B]
(2,{ln(0.1)}) node[tick,below] {$(b)$} |-
(0,{ln(1.22)}) node[tick,left] {$(a)=u(x)$};
\draw[ddline]
(4,{ln(0.1)}) node[tick,below,yshift=-1.97pt] {$x+\varepsilon$} |- coordinate[pos=0.5] (uy)
(0,{ln(4)}) node[tick,left] {$u(x+\varepsilon)$};
\draw[name path=A, semitransparent] (ux) -- (uy);
\draw[ddline]
(1.2,{ln(0.1)}) node[tick,below,yshift=-1.97pt] {$x$} |-
(1.2,{ln(1.22)}) node[tick,left] {};
\end{axis}
\end{tikzpicture}%
\end{document}
I then include these plots in my main .tex file via \includepraphics[]{} as follows:
\documentclass{article}
% PACKAGES LOADING
\usepackage{graphicx}
% DOCUMENT ITSELF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{figure}
\centering
\includegraphics[page=1]{MWE 1.pdf}
\caption{Caption}
\end{figure}
\begin{figure}
\centering
\includegraphics[page=2]{MWE 1.pdf}
\caption{Caption}
\end{figure}
\end{document}
As you can see in the picture, the plots are not aligned by the y-axis, as I desire. I've seen questions that are similar to mine, but none of them solves my issue. Some answers use the trim axis option, but that does not work well in standalone document class because it erases whatever is on left of the y-axis. I have also tried to play with baseline, overlay and use as bounding box options to no avail. How can I align these plots by their y-axis?


\draw (0,0) node[tick,left] {\phantom{$pu(x)+(1-p)u(y)$}};– Ivan Feb 26 '21 at 13:56\pgfplotsset{yticklabel style={text width=<width>,align=right}}to specify the amount of space the y labels are to take. See Aligning subplots in a pgfplots figure. – Peter Grill Mar 09 '21 at 18:36