4

Problem Description

I have a specific way I would like to caption my graphs created with \begin{tikzpicture}. More specifically I want to give them a numbering system, like that of figures and tables, but have the number and caption placed above the graph where the Title usually goes.

Additionally, I then want these graphs to have the Title of "Graph 2.9: ....." and then to be placed into a \listofgraphs section at the beginning of my document.

MWE:

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

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

\begin{document}

\begin{figure}
    \centering
    \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 D}
            \addplot[violet,mark=square,mark size=2.9pt]coordinates{(1,2509) (2,2136) (3,2768) (4,2346) (5,2465)
            };\label{Blocks E}

            \legend{Blocks A, Blocks B, Blocks C, Blocks D, Blocks E, Blocks F}
        \end{axis}
    \end{tikzpicture}
    \caption{}
    \label{graph: pull out results}
\end{figure}

\end{document}

This produces the following:

enter image description here

Desired Output/Solution

Whereas: I would want something that looks something like this:

enter image description here

And then for this to be placed in a \listofgraphs with the corresponding number and title.

Note: I already have figures and tables in my document, both in their own \listof...

I am using TexStudio and MikTex

itc
  • 657

1 Answers1

5

You could try defining a new floating environment like in this post: https://tex.stackexchange.com/a/95634/120578

\documentclass [a4paper,10pt]{report}

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

%koleygr: Added these from here: https://tex.stackexchange.com/a/95634/120578 \usepackage{newfloat} \usepackage{caption} \DeclareFloatingEnvironment[placement={!ht},name=Graph]{Graph}

\captionsetup[Graph]{labelfont=bf} \counterwithin{Graph}{chapter}

\usepackage{lipsum} \usepackage{multicol} \usepackage[colorlinks=true]{hyperref}

\begin{document} \section{} \begin{Graph}[!ht] \centering \caption{Pull-out glue strength for blocks with glued in cables} \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}

            \legend{Blocks A, Blocks B, Blocks C, Blocks D, Blocks E, Blocks F}
        \end{axis}
    \end{tikzpicture}
\end{Graph}

\end{document}

Output:

enter image description here

koleygr
  • 20,105
  • Cool! So this works for the graph title, any idea how to combine this with the \listofgraphs code. I have tried a few examples from: link and from link but I can't seem to get them to work. – Aaron Rhodes Aug 16 '22 at 14:23
  • @AaronRhodes ... It already works... but we used capital G for Graphs... So, just try \listofGraphs – koleygr Aug 16 '22 at 14:27
  • Actually, If I add \listofGraph to my code it prints out the correct thing. However TexStudio says it is an "unrecognized" command - But still prints the List correctly. Should I be bothered about fixing this? – Aaron Rhodes Aug 16 '22 at 14:29
  • just rename every Graph except of the name=Graph to graph ... I don't use TeXStudio ... But this will possibly help to get rid of this (and of TeXStudio later :P ) – koleygr Aug 16 '22 at 14:33
  • How you would go about having 2 graphs next to each other using this method? I had it working prior to this, but now it puts each new graph on a new line (There is no spaces between my \end{Graph} and\begin{Graph}). I am assuming it does this as it would with any figure...which leads me to think a\subfigure` solution would suffice, but unfortunately I can't get that to work. Any ideas? – Aaron Rhodes Aug 16 '22 at 19:35
  • Try using \captionof{Graph}{Bla Bla} inside minipages next to each other – koleygr Aug 16 '22 at 19:39
  • Would you be able to make another answer with a MWE of this? I am a little lost. – Aaron Rhodes Aug 16 '22 at 19:59
  • @AaronRhodes ... Please open o follow up question for this... It will not be helpful to other users in case it will solve multiple requests. Thanks – koleygr Aug 16 '22 at 21:01
  • Here is the follow up question for anyone interested link – Aaron Rhodes Aug 17 '22 at 13:08