1

So, I've been working on an answer to this question and worked on adapting it to groupplots, i.e. placing automatically legend on the outside margin, axis ticks and labels on the inside I'm facing two issues with the mwe thereafter:

  • How to cleverly turn on/off axis label according to the side ? A possible way is another use of \ifoddpage but it's rather not beautiful I think. I might have forgot something from the manual.
  • How to use trim axis group left/right together with the legend placement proposed by Jake in this question ? When triming axes, the legend is placed with the former positions, not exactly the expected results...

Here is the main file:

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usepackage{float}
\usepackage{ifoddpage}


\begin{document}

\begin{figure}[H]
  \input{groupplot}
  \caption{first figure}
\end{figure}

\newpage

\begin{figure}[H]
  \input{groupplot}
  \caption{first figure}
\end{figure}

\end{document}

And here is the groupplot.tex figure:

  \checkoddpage
  \ifoddpage
  \def\yticksside{ edge right}
  \else
  \def\yticksside{ edge left}
  \fi

  \centering
  \begin{tikzpicture}%[trim axis group left,trim axis group right]
    \begin{groupplot}[
        group style = {
          group size = 2 by 1,
          horizontal sep=0mm,
    yticklabels at=\yticksside,
        },
        width=0.5\columnwidth,
        ylabel={$y$label},
      ]

      \nextgroupplot[
        xlabel={$x$},
        legend to name=grouplegend,
    ylabel near ticks,
      ]
      \addplot coordinates { (0,0) (1,1) };
      \addlegendentry{Legend entry}

      \nextgroupplot[
        xlabel={$x$},
    ylabel near ticks,
      ]
      \addplot coordinates { (0,0) (1,1) };
    \end{groupplot}

  \checkoddpage
  \ifoddpage
  \def\legendpos{group c1r1.south west}
  \def\legendanchor{north east}
  \else
  \def\legendpos{group c2r1.south east}
  \def\legendanchor{north west}
  \fi

  \node at (\legendpos) [anchor=\legendanchor]  {\ref{grouplegend}};
  \end{tikzpicture}
Vser
  • 1,911

0 Answers0