4

Problem Description

This is a continuation of a question I had here: Numbering and captioning pgfplots/tikzpicture

Where We solved how to name Graphs in a specific way and in-turn generate a \listofgraphs at the beginning of the document.

When I follow that code, I can't seem to get 2 of my graphs to appear side by side. I assumed using a \subfigure environment would work but from what I tried, I could not get it to work. Another suggestion from @koleygr was: Try using \captionof{Graph}{Bla Bla} inside minipages next to each other. But this is where I got lost.

MWE

For simplicity I am just using the same graph twice:

\documentclass [a4paper,10pt,draft]{report}

\usepackage{xcolor} \usepackage{tikz} \usetikzlibrary{calc} \usetikzlibrary{arrows} \usepackage{pgfplots} \pgfplotsset{compat=1.6}

\usepackage{newfloat} \usepackage{caption} \DeclareFloatingEnvironment[placement={!ht},name=Graph]{Graph} \captionsetup[Graph]{} \counterwithin{Graph}{chapter}

\begin{document}

\listofGraph

\section{Two graphs should be side by side}

\begin{Graph}[!ht] \centering \caption{glued in cables 1} \label{graph: pull out results} \begin{tikzpicture}[trim axis left, trim axis right] \begin{axis}[ %title={Pull-out glue strength for blocks with glued in cables}, axis lines=box, xlabel={Block Number}, ylabel={Failure Load (N)}, xmin=1, xmax=5, ymin=0, ymax=9000, xtick={}, ytick={}, ymajorgrids=true, xmajorgrids=true, grid style=dashed, enlargelimits=true, ]

        \addplot[red,mark=square,mark size=2.9pt]coordinates{(1,6507) (2,6009) (3,5936) (4,5843) (5,6234)
        };\label{Blocks A}
        \addplot[blue,mark=square,mark size=2.9pt]coordinates{(1,1966) (2,1577) (3,2052) (4,1869) (5,2122)
        };\label{Blocks B}
        \addplot[green,mark=square,mark size=2.9pt]coordinates{(1,8435) (2,8027) (3,7648) (4,7865) (5,8123)
        };\label{Blocks C}
        \addplot[magenta,mark=square,mark size=2.9pt]coordinates{(1,3266) (2,2894) (3,3024) (4,2976) (5,3234)
        };\label{Blocks D}
        \addplot[orange,mark=square,mark size=2.9pt]coordinates{(1,6324) (2,6879) (3,5796) (4,6432) (5,6183)
        };\label{Blocks E}
        \addplot[violet,mark=square,mark size=2.9pt]coordinates{(1,2509) (2,2136) (3,2768) (4,2346) (5,2465)
        };\label{Blocks F}

    \end{axis}
\end{tikzpicture}

\end{Graph}% \hspace{3pt} % \begin{Graph}[!ht] \centering \caption{glued in cables 2} \label{graph: pull out results} \begin{tikzpicture}[trim axis left, trim axis right] \begin{axis}[ %title={Pull-out glue strength for blocks with glued in cables}, axis lines=box, xlabel={Block Number}, ylabel={Failure Load (N)}, xmin=1, xmax=5, ymin=0, ymax=9000, xtick={}, ytick={}, legend pos=outer north east, ymajorgrids=true, xmajorgrids=true, grid style=dashed, enlargelimits=true, ]

        \addplot[red,mark=square,mark size=2.9pt]coordinates{(1,6507) (2,6009) (3,5936) (4,5843) (5,6234)
        };\label{Blocks A}
        \addplot[blue,mark=square,mark size=2.9pt]coordinates{(1,1966) (2,1577) (3,2052) (4,1869) (5,2122)
        };\label{Blocks B}
        \addplot[green,mark=square,mark size=2.9pt]coordinates{(1,8435) (2,8027) (3,7648) (4,7865) (5,8123)
        };\label{Blocks C}
        \addplot[magenta,mark=square,mark size=2.9pt]coordinates{(1,3266) (2,2894) (3,3024) (4,2976) (5,3234)
        };\label{Blocks D}
        \addplot[orange,mark=square,mark size=2.9pt]coordinates{(1,6324) (2,6879) (3,5796) (4,6432) (5,6183)
        };\label{Blocks E}
        \addplot[violet,mark=square,mark size=2.9pt]coordinates{(1,2509) (2,2136) (3,2768) (4,2346) (5,2465)
        };\label{Blocks F}

    \end{axis}
\end{tikzpicture}

\end{Graph}

\end{document}

This produces the following result:

enter image description here

Desired Output/Solution

Whereas I would like something like this:

enter image description here

itc
  • 657

2 Answers2

5

Use two minipages inside a single Graph environment.

\documentclass [a4paper,10pt,draft]{report}

\usepackage{xcolor} \usepackage{tikz} \usetikzlibrary{calc} \usetikzlibrary{arrows} \usepackage{pgfplots} \pgfplotsset{compat=1.6}

\usepackage{newfloat} \usepackage{caption}

\DeclareFloatingEnvironment[placement={!ht},name=Graph]{Graph} \captionsetup[Graph]{} \counterwithin{Graph}{chapter}

\begin{document}

\listofGraph

\section{Two graphs should be side by side}

\begin{Graph}[!htp]

\begin{minipage}{0.5\textwidth} \centering

\caption{glued in cables 1} \label{graph: pull out results 1} \begin{tikzpicture}[trim axis left, trim axis right,scale=0.6] \begin{axis}[ %title={Pull-out glue strength for blocks with glued in cables}, axis lines=box, xlabel={Block Number}, ylabel={Failure Load (N)}, xmin=1, xmax=5, ymin=0, ymax=9000, xtick={}, ytick={}, ymajorgrids=true, xmajorgrids=true, grid style=dashed, enlargelimits=true, ] \addplot[red,mark=square,mark size=2.9pt] coordinates { (1,6507) (2,6009) (3,5936) (4,5843) (5,6234) }; \addplot[blue,mark=square,mark size=2.9pt] coordinates { (1,1966) (2,1577) (3,2052) (4,1869) (5,2122) }; \addplot[green,mark=square,mark size=2.9pt] coordinates { (1,8435) (2,8027) (3,7648) (4,7865) (5,8123) }; \addplot[magenta,mark=square,mark size=2.9pt] coordinates { (1,3266) (2,2894) (3,3024) (4,2976) (5,3234) }; \addplot[orange,mark=square,mark size=2.9pt] coordinates { (1,6324) (2,6879) (3,5796) (4,6432) (5,6183) }; \addplot[violet,mark=square,mark size=2.9pt] coordinates { (1,2509) (2,2136) (3,2768) (4,2346) (5,2465) }; \end{axis} \end{tikzpicture} \end{minipage}% \begin{minipage}{0.5\textwidth} \centering \caption{glued in cables 2} \label{graph: pull out results 2} \begin{tikzpicture}[trim axis left, trim axis right,scale=0.6] \begin{axis}[ %title={Pull-out glue strength for blocks with glued in cables}, axis lines=box, xlabel={Block Number}, ylabel={Failure Load (N)}, xmin=1, xmax=5, ymin=0, ymax=9000, xtick={}, ytick={}, legend pos=outer north east, ymajorgrids=true, xmajorgrids=true, grid style=dashed, enlargelimits=true, ] \addplot[red,mark=square,mark size=2.9pt] coordinates { (1,6507) (2,6009) (3,5936) (4,5843) (5,6234) }; \addplot[blue,mark=square,mark size=2.9pt] coordinates { (1,1966) (2,1577) (3,2052) (4,1869) (5,2122) }; \addplot[green,mark=square,mark size=2.9pt] coordinates { (1,8435) (2,8027) (3,7648) (4,7865) (5,8123) }; \addplot[magenta,mark=square,mark size=2.9pt] coordinates { (1,3266) (2,2894) (3,3024) (4,2976) (5,3234) }; \addplot[orange,mark=square,mark size=2.9pt] coordinates { (1,6324) (2,6879) (3,5796) (4,6432) (5,6183) }; \addplot[violet,mark=square,mark size=2.9pt] coordinates { (1,2509) (2,2136) (3,2768) (4,2346) (5,2465) }; \end{axis} \end{tikzpicture} \end{minipage}

\end{Graph}

\end{document}

enter image description here

egreg
  • 1,121,712
2

You can use the subcaption package which creates a subGraph environment for your custom Graph environment automatically. You probably need to take care of the size of the plots and of the labels, of course.

You can adjust the way the numbering is done using several commands of which I put some in the code below. You should refer to the manual of the subcaption package for detailed information.

On a second thought and after reading the older question you link however, this is probably not exactly what you're after, because both subGraphs would then belong to the same Graph and hence share the same label. I still leave it here for reference.

\documentclass[a4paper,10pt,draft]{report}

\usepackage{pgfplots} \pgfplotsset{compat=1.6}

\usepackage{newfloat} \usepackage{subcaption}

\DeclareFloatingEnvironment[placement={!ht}, name=Graph]{Graph} \captionsetup[Graph]{}

\DeclareCaptionSubType*{Graph} \renewcommand\thesubGraph{Graph \theGraph (\alph{subGraph})} \captionsetup[subGraph]{labelformat=simple, labelsep=colon}

\begin{document}

\listofGraph

\section{Two graphs should be side by side}

\begin{Graph}[!ht] \centering \begin{subGraph}[b]{0.45\textwidth} \centering \caption{glued in cables 1} \label{graph: pull out results} \begin{tikzpicture}[trim axis left, trim axis right, scale=0.6] \begin{axis}[ %title={Pull-out glue strength for blocks with glued in cables}, axis lines=box, xlabel={Block Number}, ylabel={Failure Load (N)}, xmin=1, xmax=5, ymin=0, ymax=9000, xtick={}, ytick={}, ymajorgrids=true, xmajorgrids=true, grid style=dashed, enlargelimits=true, ]

            \addplot[red,mark=square,mark size=2.9pt]coordinates{(1,6507) (2,6009) (3,5936) (4,5843) (5,6234)
            };\label{Blocks A}
            \addplot[blue,mark=square,mark size=2.9pt]coordinates{(1,1966) (2,1577) (3,2052) (4,1869) (5,2122)
            };\label{Blocks B}
            \addplot[green,mark=square,mark size=2.9pt]coordinates{(1,8435) (2,8027) (3,7648) (4,7865) (5,8123)
            };\label{Blocks C}
            \addplot[magenta,mark=square,mark size=2.9pt]coordinates{(1,3266) (2,2894) (3,3024) (4,2976) (5,3234)
            };\label{Blocks D}
            \addplot[orange,mark=square,mark size=2.9pt]coordinates{(1,6324) (2,6879) (3,5796) (4,6432) (5,6183)
            };\label{Blocks E}
            \addplot[violet,mark=square,mark size=2.9pt]coordinates{(1,2509) (2,2136) (3,2768) (4,2346) (5,2465)
            };\label{Blocks F}

        \end{axis}
    \end{tikzpicture}
\end{subGraph}
\begin{subGraph}[b]{0.45\textwidth}
    \centering
    \caption{glued in cables 2}
    \label{graph: pull out results 2}
    \begin{tikzpicture}[trim axis left, trim axis right, scale=0.6]
        \begin{axis}[
            %title={Pull-out glue strength for blocks with glued in cables},
            axis lines=box,
            xlabel={Block Number},
            ylabel={Failure Load (N)},
            xmin=1, xmax=5,
            ymin=0, ymax=9000,
            xtick={},
            ytick={},
            legend pos=outer north east,
            ymajorgrids=true,
            xmajorgrids=true,
            grid style=dashed,
            enlargelimits=true,
            ]

            \addplot[red,mark=square,mark size=2.9pt]coordinates{(1,6507) (2,6009) (3,5936) (4,5843) (5,6234)
            };\label{Blocks A 2}
            \addplot[blue,mark=square,mark size=2.9pt]coordinates{(1,1966) (2,1577) (3,2052) (4,1869) (5,2122)
            };\label{Blocks B 2}
            \addplot[green,mark=square,mark size=2.9pt]coordinates{(1,8435) (2,8027) (3,7648) (4,7865) (5,8123)
            };\label{Blocks C 2}
            \addplot[magenta,mark=square,mark size=2.9pt]coordinates{(1,3266) (2,2894) (3,3024) (4,2976) (5,3234)
            };\label{Blocks D 2}
            \addplot[orange,mark=square,mark size=2.9pt]coordinates{(1,6324) (2,6879) (3,5796) (4,6432) (5,6183)
            };\label{Blocks E 2}
            \addplot[violet,mark=square,mark size=2.9pt]coordinates{(1,2509) (2,2136) (3,2768) (4,2346) (5,2465)
            };\label{Blocks F 2}

        \end{axis}
    \end{tikzpicture}
\end{subGraph}

\end{Graph}

\end{document}

enter image description here