所以,我一直在尋找答案這個問題並致力於使其適應分組圖,即自動將圖例放置在外側邊距上,將軸刻度和標籤放置在內側上,此後我遇到了 mwe 的兩個問題:
- 如何根據側面巧妙地打開/關閉軸標籤?一種可能的方法是 \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}