Consider this minimal example:
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.18}
\pgfplotsset{
sub plots/.style args={#1 by #2}{
width=8cm,
height=4cm,
group/group size={#1 by #2},
group/horizontal sep=3cm,
}
}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
sub plots={2 by 2}, % applies the sub plots style as expected
group/vertical sep=.5cm, % sets vertical sep as expected
width=4cm, % overrides width from sub plots style as expected
group/horizontal sep=.5cm, % does not override horizontal sep from sub plots style. Why?
]
\nextgroupplot
\addplot [domain=0:360] {sin(x)};
\nextgroupplot
\addplot [domain=0:360] {sin(x)};
\nextgroupplot
\addplot [domain=0:360] {sin(x)};
\nextgroupplot
\addplot [domain=0:360] {sin(x)};
\end{groupplot}
\end{tikzpicture}
\end{document}
Here is the output: Why can't I override the "group/horizontal sep" option from within the groupplot options but overriding "width" works fine? As you can see, setting groupplot options if they were not previously set by my "sub figure" style works (as demonstrated by "group/vertical sep"). So what is going on and how can I fix that?