我试图将三个图表并排放置,但不起作用。如果我使用子图,第三个图会位于其他图下方,即使一行中有足够的空间容纳所有三个图。现在我尝试包含小页面,但我不知道如何将图表并排放置:
\documentclass{scrartcl}
\usepackage[margin=0.5in]{geometry}
\usepackage{textcomp}
\usepackage{pgfplots}
\usepackage{subfig}
\usepackage{graphicx}
\usepackage{subcaption}
\captionsetup{compatibility=false}
\pgfplotsset{width=5cm,compat=1.9}
\begin{document}
\begin{figure}[htbp]
%Start figure 1
\begin{minipage}{0.45\textwidth}{
\begin{tikzpicture}
\begin{axis}[
xlabel={Capacity},
ylabel={Service Level in \%},
xmin=0, xmax=8,
ymin=0, ymax=110,
xtick={0,1,2,3,4,5,6,7,8},
ytick={0,20,40,60,80,100},
legend pos=north west,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
color=blue,line width=0.5mm,
mark=square,
]
coordinates {
(2,90.92)(4,97.65)(6,99.94 )(8,100 )(10,100)
};
\end{axis};
\end{tikzpicture}}
\end{minipage}\hfill
%Start figure 2
\begin{minipage}{0.45\textwidth}
{\begin{tikzpicture}
\begin{axis}[
xlabel={Capacity},
ylabel={Costs in €},
xmin=0, xmax=8,
ymin=0, ymax=1000,
xtick={0,1,2,3,4,5,6,7,8},
ytick={0,100,200,300,400,500,600,700,800,900,1000},
legend pos=north west,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
color=blue,line width=0.5mm,
mark=square,
]
coordinates {
(2,909.83)(4,740.87)(6,740.87)(8,740.87)(10,740.87)
};
\end{axis}
\end{tikzpicture}}
\end{minipage}\hfill
%Start figure 3
\begin{minipage}{0.45\textwidth}{
\begin{tikzpicture}
\begin{axis}[
title={Sensitivity Analysis Service Level vs Costs},
xlabel={Service Level in \%},
ylabel={Costs in €},
xmin=0, xmax=100,
ymin=0, ymax=1000,
xtick={100,90,80,70,60,50,40,30,20,10,0},
ytick={100, 200, 300, 400, 500, 600, 700, 800, 900, 1000},
legend pos=north west,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
color=blue,line width=0.5mm,
mark=square,
]
coordinates {
(90.92,909.82)(90,850.60)(80, 712.71)(70, 712.71)(60,666.11)(50,645.72)(40,645.72)(30,645.72)(20,645.72)(10,646.72)(0,645.72)
};
\end{axis}
\end{tikzpicture}}
\end{minipage}\hfill
\end{figure}
\end{document}
有什么方法可以实现这个目标吗?
答案1
正如评论中提到的,空行是段落分隔符,因此您实际上是将图表放在三个单独的段落中,因此是三行。实际上,这与普通文本相同。此外,小页面的总宽度应小于\textwidth
,因此更改0.45
为0.32
。
我不同意使用 的建议scalebox
,我认为最好调整图表的设置。pgfplots
有几个预定义的样式可以使内容变小,它们是tiny
、footnotesize
和small
。如果应用footnotesize
样式并修改宽度,您可以获得以下内容:
其他修改主要是用 替换minipage
并subfigure
添加可选[t]
参数以修复对齐问题。错位主要是由于第三轴的标题太宽而跨过两行。标题以正常方式添加。(请注意,包subfigure
定义的环境subcaption
或多或少只是一个minipage
,但\caption
添加在其中的被视为子图的标题。)
如果您想要图 1、图 2、图 3 而不是图 1a、1b、1c,只需再次替换subfigure
即可minipage
。
\documentclass{scrartcl}
\usepackage[margin=0.5in]{geometry}
\usepackage{textcomp}
\usepackage{pgfplots}
\usepackage{subcaption}
\captionsetup{compatibility=false}
\pgfplotsset{width=5cm,compat=1.9}
\begin{document}
\begin{figure}[htbp]
\pgfplotsset{
footnotesize, % reduces font size and size of diagram
width=\linewidth, % modify size of axis
}
%Start figure 1
\begin{subfigure}[t]{0.32\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
xlabel={Capacity},
ylabel={Service Level in \%},
xmin=0, xmax=8,
ymin=0, ymax=110,
xtick={0,1,2,3,4,5,6,7,8},
ytick={0,20,40,60,80,100},
legend pos=north west,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
color=blue,line width=0.5mm,
mark=square,
]
coordinates {
(2,90.92)(4,97.65)(6,99.94 )(8,100 )(10,100)
};
\end{axis};
\end{tikzpicture}
\caption{foo}
\end{subfigure}\hfill
\begin{subfigure}[t]{0.32\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
xlabel={Capacity},
ylabel={Costs in €},
xmin=0, xmax=8,
ymin=0, ymax=1000,
xtick={0,1,2,3,4,5,6,7,8},
ytick={0,100,200,300,400,500,600,700,800,900,1000},
legend pos=north west,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
color=blue,line width=0.5mm,
mark=square,
]
coordinates {
(2,909.83)(4,740.87)(6,740.87)(8,740.87)(10,740.87)
};
\end{axis}
\end{tikzpicture}
\caption{bar}
\end{subfigure}\hfill
\begin{subfigure}[t]{0.32\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
title={Sensitivity Analysis\\Service Level vs Costs}, % <-- added \\
title style={align=center}, % <-- added
xlabel={Service Level in \%},
ylabel={Costs in €},
xmin=0, xmax=100,
ymin=0, ymax=1000,
xtick={100,90,80,70,60,50,40,30,20,10,0},
ytick={100, 200, 300, 400, 500, 600, 700, 800, 900, 1000},
legend pos=north west,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
color=blue,line width=0.5mm,
mark=square,
]
coordinates {
(90.92,909.82)(90,850.60)(80, 712.71)(70, 712.71)(60,666.11)(50,645.72)(40,645.72)(30,645.72)(20,645.72)(10,646.72)(0,645.72)
};
\end{axis}
\end{tikzpicture}
\caption{baz}
\end{subfigure}
\caption{foobarbaz}
\end{figure}
\end{document}