そこで私は答えを模索してきましたこの質問そして、それをグループプロットに適応させる作業を行いました。つまり、凡例を外側の余白に、軸の目盛りとラベルを内側に自動的に配置する作業です。その後、MWE で 2 つの問題に直面しています。
- 側面に応じて軸ラベルを巧みにオン/オフにするにはどうすればよいでしょうか。 \ifoddpage を別の方法で使用することもできますが、あまり美しくないと思います。 マニュアルの内容を忘れたのかもしれません。
trim axis group left/right
Jakeが提案した凡例の配置と合わせて使用する方法この質問? 軸をトリミングすると、凡例は以前の位置に配置されますが、期待どおりの結果にはなりません...
メインファイルは次のとおりです。
\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}
そして、これが図ですgroupplot.tex
:
\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}