问题描述
这是我在这里提出的一个问题的延续:编号和标题 pgfplots/tikzpicture
我们解决了如何以特定方式命名图表并依次\listofgraphs
在文档开头生成图表。
当我按照该代码操作时,似乎无法让两个图表并排显示。我以为使用\subfigure
环境会起作用,但从我尝试的结果来看,我无法让它工作。@koleygr 的另一个建议是:尝试在彼此旁边使用\captionof{Graph}{Bla Bla}
内部minipages
。但这就是我迷失的地方。
平均能量损失
为了简单起见,我仅使用同一张图表两次:
\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}
其结果如下:
期望的输出/解决方案
而我想要的是这样的:
答案1
在单一Graph
环境中使用两个小页面。
\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}
答案2
您可以使用自动为您的自定义环境subcaption
创建环境的包。当然,您可能需要注意图表和标签的大小。subGraph
Graph
您可以使用几个命令来调整编号方式,我将其中一些命令放在下面的代码中。您应该参考软件包手册subcaption
以获取详细信息。
经过再三思考,在阅读了您链接的旧问题后,这可能并不是您想要的,因为两个subGraph
s 都属于同一个Graph
,因此共享同一个标签。我仍然将其留在这里以供参考。
\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}