4

For this MWE, I have 8 plots where only 6 are printed where the last two are overlooked. So, is there a way to make PGFplots split the groupplots over multiple pages based on the size of the plot/page?

\documentclass[a4paper,twocolumn]{article}
\usepackage{pgfplots,mathtools}
\usepackage[showframe]{geometry}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{groupplot}[
group style={
    group name=G,
    group size=2 by 3,
}, xtick=\empty, ytick=\empty, ztick=\empty
]
\nextgroupplot[title=1]
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
%
\nextgroupplot[title=2]
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
%
\nextgroupplot[title=3]
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
%
\nextgroupplot[title=4]
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
%
\nextgroupplot[title=5]
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
%
\nextgroupplot[title=6]
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
%
\nextgroupplot[title=7,colorbar horizontal,]
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
%
\nextgroupplot[title=8]
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{groupplot}
\end{tikzpicture}
\caption{some caption}
\end{figure}
\end{document}

enter image description here


Edit

For this MWE, how to protect the longtable and prevent it from being discontinued by another content such as another exemplary figure here?

Additionally, how to make the caption of the longtable be treated as that of the figure in order to not have conflicts of figures with the same numbers?

\documentclass[a4paper]{article}
\usepackage{pgfplots,mathtools}
\usepackage[showframe]{geometry}
\usepackage{longtable,lipsum}
\usepackage{caption}
\pgfplotsset{compat=1.16}
\pgfplotsset{my group style/.style={title style = {at={(0.5,1)}, above}
, xtick=\empty, ytick=\empty, ztick=\empty}}
\begin{document}

%\lipsum[1] 
\captionsetup[longtable]{name=Figure}
\begin{longtable}{cc}
\endfoot
\caption{A table that pretends to be a figure.}\label{fig:ManyPlots}
\endlastfoot
\begin{tikzpicture}
\begin{axis}[my group style,title=1] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}& 
\begin{tikzpicture}
\begin{axis}[my group style,title=2] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}\\
\begin{tikzpicture}
\begin{axis}[my group style,title=3] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}& 
\begin{tikzpicture}
\begin{axis}[my group style,title=4] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}\\
\begin{tikzpicture}
\begin{axis}[my group style,title=5] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}& 
\begin{tikzpicture}
\begin{axis}[my group style,title=6] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}\\
\begin{tikzpicture}
\begin{axis}[my group style,title=7] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}& 
\begin{tikzpicture}
\begin{axis}[my group style,title=8] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}
\end{longtable}
\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{example-image}
    \caption{caption}
\end{figure}

\end{document}

enter image description here

5
  • 1
    Oh WOW, I'm really impressed by the impact of @percusse's answer ... (just kidding ;-) but +1
    – user121799
    Aug 5, 2018 at 22:43
  • 1
    @marmot XD improvise, adapt, overcome X))
    – Diaa
    Aug 5, 2018 at 22:46
  • 1
    Are you aware that the plots get swallowed because of group size=2 by 3, (instead of group size=2 by 4,)? I am not saying that will make the plots fit, rather I think you need to do two group plots, either 2 by 3 and 2 by 1 or two times 2 by 2.
    – user121799
    Aug 5, 2018 at 22:50
  • @marmot I really forget that but still, the last two were swallowed, which made me look for a clever way to make all the plots be printed smoothly over multiple pages without having to worry about the size of the plot/page.
    – Diaa
    Aug 5, 2018 at 22:55
  • @marmot I clearly understand your point. I googled this question but found nothing similar, which made me think that it might be possible. Anyway, I will keep the question hoping that someday it can get an answer.
    – Diaa
    Aug 5, 2018 at 23:04

1 Answer 1

3

This is at best an emergency proposal. However, I do not think that it is straightforward to split a tikzpicture over more than one pages, and the current version of group plots is within a tikzpicture. One can, however, resort to a package from the previous millennium: longtable. (Note that I was not able to use \captionof{figure}{...} in the caption of a longtable, guess that would be a separate question. Solved, big thanks to Alan Munn!) This will take care of the page breaks and if you define styles for the universal things then the additional effort in typing is not too bad. EDIT: Hope to have cured the counter problem mentioned in the updated version of the question.

\documentclass[a4paper]{article}
\usepackage{pgfplots,mathtools}
\usepackage[showframe]{geometry}
\usepackage{longtable,lipsum}
\usepackage{caption}
\pgfplotsset{compat=1.16}
\pgfplotsset{my group style/.style={title style = {at={(0.5,1)}, above}
, xtick=\empty, ytick=\empty, ztick=\empty}}
\begin{document}

%\lipsum[1] 
\captionsetup[longtable]{name=Figure}
\captionlistentry[figure]{longtable}
\begin{longtable}{cc}
\endfoot
%\captionsetup{type=figure}
\caption[figure]{A table that pretends to be a figure.}\label{fig:ManyPlots}
\endlastfoot
\begin{tikzpicture}
\begin{axis}[my group style,title=1] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}& 
\begin{tikzpicture}
\begin{axis}[my group style,title=2] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}\\
\begin{tikzpicture}
\begin{axis}[my group style,title=3] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}& 
\begin{tikzpicture}
\begin{axis}[my group style,title=4] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}\\
\begin{tikzpicture}
\begin{axis}[my group style,title=5] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}& 
\begin{tikzpicture}
\begin{axis}[my group style,title=6] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}\\
\begin{tikzpicture}
\begin{axis}[my group style,title=7] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}& 
\begin{tikzpicture}
\begin{axis}[my group style,title=8] 
\addplot3 [
surf,
domain=-2:2,
domain y=-1.3:1.3,
] {exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}
\end{longtable}
\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{example-image}
    \caption{caption}
\end{figure}

\end{document}

enter image description here

5
  • \captionof requires either the caption package or simply the capt-of package, I think.
    – Alan Munn
    Aug 6, 2018 at 0:14
  • Actually I think with longtable you just use regular \caption and it turns it into a mulicolumn entry automatically. No caption package needed.
    – Alan Munn
    Aug 6, 2018 at 1:30
  • @AlanMunn Sometimes one only has to listen to the linguists and do a texdoc caption. ;-) THANKS!
    – user121799
    Aug 6, 2018 at 1:44
  • @marmot Sorry for the long silence since I was away from the PC. Thanks for your answer, and kindly, take a look at my question edit to see if it can be handled.
    – Diaa
    Aug 6, 2018 at 17:25
  • 1
    @Diaa Yes, the counter issue was clearly a bug. As for the second issue, this is a general issues with floats: they float. There is an endless discussion about this in the forum, and I am probably the least competent source of information on that. Personally I would just issue a \clearpage after the longtable or change the option of the second figure to [b].
    – user121799
    Aug 6, 2018 at 18:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .