The user marmot has posted a really nice approach of adding legend items into one single box below a multigraph diagram by placing them inside a \node.
Based on this initial situation I have tried to separate the legend items into three rows above each other, but the result is missleading.
Minimum Working Example (MWE):
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{positioning}
\pgfplotsset{compat=newest, scale only axis}
\begin{document}
\begin{tikzpicture}
\begin{scope}[local bounding box=plots]
\begin{axis}[
axis y line* = left,
legend to name = legA,
legend style = {draw=none,
legend columns = 3,
/tikz/every even column/.append style = {column sep=0.5cm},
/tikz/every odd column/.append style = {column sep=0.15cm},
},
]%
\addplot coordinates {(0,0) (1,1)};
\addplot coordinates {(1,0) (0,1)};
\addplot coordinates {(0,1) (1,1)};
\legend{Graph 1, Graph 2, Graph 3};
\end{axis}%
%
\begin{axis}[
axis x line = none,
axis y line* = right,
legend to name = legB,
legend style = {draw=none,
legend columns = 3,
/tikz/every even column/.append style = {column sep=0.5cm},
/tikz/every odd column/.append style = {column sep=0.15cm},
},
]%
\addplot coordinates {(0,1) (1,0)};
\addplot coordinates {(0,0.5) (1,0.5)};
\addplot coordinates {(0,0.15) (1,0.15)};
\legend{Graphinggraph 4, Graphinggraph 5, Graphinggraph 6};
\end{axis}%
%
\begin{axis}[
axis x line = none,
axis y line* = right,
legend to name = legC,
legend style = {draw=none,
legend columns = 3,
/tikz/every even column/.append style = {column sep=0.5cm},
/tikz/every odd column/.append style = {column sep=0.15cm},
},
]%
\pgfplotsset%
{%
every outer y axis line/.style = {xshift=2cm},
every tick/.style = {xshift=2cm},
every y tick label/.style = {xshift=2cm},
}%
\addplot coordinates {(0.5,0) (0.5,1)};
\addplot coordinates {(0.6,0) (0.6,1)};
\addplot coordinates {(0.7,0) (0.7,1)};
\legend{Graphgraph 7, Graphgraph 8, Graphgraph 9};
\end{axis}%
\end{scope}
\node[below=3.5em of plots.south] (legA) {\ref{legA}};
\node[below=-0.5em of legA] (legB) {\ref{legB}};
\node[below=-0.5em of legB] (legC) {\ref{legC}};
\draw (legA.north west) rectangle (legC.south east);
\end{tikzpicture}
\end{document}
Screenshot of the result:
Description of the issue:
As you can see,
- the border does not fit with the outer dimension of the legend items,
- the legend items are not precisely aligned below each other.
So my questions are: How to solve this and make it look nice?

