编号和标题 pgfplots/tikzpicture

编号和标题 pgfplots/tikzpicture

问题描述

我想用一种特定的方式来为用 创建的图表添加标题\begin{tikzpicture}。更具体地说,我想为它们提供一个编号系统,就像数字和表格的编号系统一样,但将编号和标题放在图表上方,也就是通常Title的位置。

此外,我希望这些图表的标题为“图表 2.9:.....”,然后将其放置在\listofgraphs文档开头的某个部分中。

梅威瑟:

\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}

这将产生以下内容:

在此处输入图片描述

期望的输出/解决方案

而我想要的是类似这样的东西:

在此处输入图片描述

然后将其放入\listofgraphs具有相应编号和标题的。

注意:我的文档中已经有图表和表格,它们都有自己的格式\listof...

我正在使用 TexStudio 和 MikTex

答案1

您可以尝试定义一个新的浮动环境,像这篇文章中一样: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}

输出:

在此处输入图片描述

相关内容