![水平和垂直对齐 tikzpicture 图(子图)](https://linux22.com/image/467360/%E6%B0%B4%E5%B9%B3%E5%92%8C%E5%9E%82%E7%9B%B4%E5%AF%B9%E9%BD%90%20tikzpicture%20%E5%9B%BE%EF%BC%88%E5%AD%90%E5%9B%BE%EF%BC%89.png)
我有这四个 tikspicture 图作为子图。我希望轴和子标题 (a、b、c、d) 对齐。此外,我希望这些图具有相同的大小,并且子标题字母位于每个图下方的中心。另一个问题似乎是这些图太靠近右侧的边缘。
非常感谢您的帮助!
\documentclass[
12pt,
a4paper,
parskip=half,
toc=bibliography,
numbers=noendperiod
]{scrbook}
\usepackage[
left=3cm,
right=2.5cm,
top=2.5cm,
bottom=2.0cm,
includehead,
includefoot
]{geometry}
\usepackage[UKenglish]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{scrlayer-scrpage}
\usepackage{lmodern}
\usepackage{textcomp}
\usepackage{amsmath,amssymb}
\usepackage{mwe}
\usepackage{esvect}
\usepackage{mathfixs}
\usepackage[right]{eurosym}
\usepackage{gensymb}
\usepackage[dvipsnames,table,xcdraw]{xcolor}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{float}
\usepackage{caption}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\addtokomafont{caption}{\scriptsize}
\usepackage[font={normal}]{caption}
\setkomafont{captionlabel}{\bfseries\rmfamily}
\begin{document}
\begin{figure}[H]
\begin{subfigure}{0.4\linewidth}
\begin{tikzpicture}[baseline]
\begin{axis}[
xticklabels={one, two, three, four, five},
tick label style={font=\scriptsize},
x tick label style = {rotate=45, anchor=east},
ylabel={Flux},
ymin=-0.05,
ymax=20,
xtick={1,2,3,4,5},
]
\addplot[color=Blue, mark=*, dashed]
coordinates {(1,-0.03)(2,4.55)(3,2.55)(4,1.06)(5,16.91)};
\end{axis}
\end{tikzpicture}
\caption{ }
\end{subfigure}
\hfill
\begin{subfigure}{0.4\linewidth}
\begin{tikzpicture}
\begin{axis}[
xticklabels={one, four, five, twenty, thirty},
tick label style={font=\scriptsize},
x tick label style = {rotate=45, anchor=east},
ylabel={Flux},
ymin=0,
xtick={1,2,3,4,5},
legend pos=outer north east,
legend cell align={left}
]
\addplot[color=Blue, mark=*, dashed]
coordinates {(1,0.00)(2,47.77)(3,1.10)(4,14.68)(5,5.53)};
\end{axis}
\end{tikzpicture}
\caption{ }
\end{subfigure}
\vfill
\begin{subfigure}{0.4\linewidth}
\begin{tikzpicture}
\begin{axis}[
xticklabels={one, nine, seven, thirteen},
tick label style={font=\scriptsize},
x tick label style = {rotate=45, anchor=east},
ylabel={Flux},
ymin=0,
xtick={1,2,3,4},
legend pos=outer north east,
legend cell align={left}
]
\addplot[color=Blue, mark=*, dashed]
coordinates {(1,0.78)(2,6.72)(3,4.25)(4,7.97)};
\end{axis}
\end{tikzpicture}
\caption{ }
\end{subfigure}
\hfill
\begin{subfigure}{0.4\linewidth}
\begin{tikzpicture}
\begin{axis}[
xticklabels={one, two},
tick label style={font=\scriptsize},
x tick label style = {rotate=45, anchor=east},
ylabel={Flux},
ymin=-1,
ymax=1,
xtick={1,2},
legend pos=outer north east,
legend cell align={left}
]
\addplot[color=Blue, mark=*, dashed]
coordinates {(1,0.00)(2,-0.02)};
\end{axis}
\end{tikzpicture}
\caption{ }
\end{subfigure}
\caption{caption for all plots}
\label{all_plots}
\end{figure}
\end{document}
答案1
像这样:
在设计 MWE 时考虑了@MS-SPO 注释:
- 规定了图表的宽度和高度,所有图表都是相同的
- 规定的宽度刻度标签,在每个图中行都是相同的
- 规定的图表选项在图中合并
\pgfplotsset
(由此 MWE 代码更短,但更重要的是所有图表都相同)
\documentclass[12pt, a4paper,
parskip=half,
toc=bibliography,
numbers=noendperiod
]{scrbook}
\usepackage[hmargin={3.0cm, 2.5cm},
vmargin={2.5cm, 2.0cm},
includehead, includefoot
]{geometry}
\usepackage[UKenglish]{babel}
\usepackage[T1]{fontenc}
\usepackage{scrlayer-scrpage}
\usepackage{subcaption}
\usepackage{caption}
\addtokomafont{caption}{\scriptsize}
\setkomafont{captionlabel}{\bfseries\rmfamily}
\usepackage[dvipsnames,table,xcdraw]{xcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{figure}[ht]
\pgfplotsset{width=\linewidth, height=0.75\linewidth,
enlarge y limits=0.1,
tick label style={font=\scriptsize},
xticklabel style = {text width=1.4em, align=right, inner sep=2pt,
rotate=45, anchor=north east},
ylabel={Flux},
ylabel style = {text width=1em, inner sep=2pt},
yticklabel style = {text width=1.2em, align=right},
%
every axis plot post/.append style={color=Blue, dashed, mark=*},
}
\begin{subfigure}[t]{0.48\linewidth}
\begin{tikzpicture}
\begin{axis}[
xtick={1,...,5},
xticklabels={one, two, three, four, five},
ymax=20,
]
\addplot coordinates {(1,-0.03)(2,4.55)(3,2.55)(4,1.06)(5,5.93)};
\end{axis}
\end{tikzpicture}
\caption{}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.48\linewidth}
\begin{tikzpicture}
\begin{axis}[
xtick={1,...,5},
xticklabels={one, two, three, four, five},
ymax=50,
]
\addplot coordinates {(1,-0.03)(2,47.77)(3,1.10)(4,14.68)(5,16.91)};
\end{axis}
\end{tikzpicture}
\caption{}
\end{subfigure}
\medskip
\begin{subfigure}[t]{0.48\linewidth}
\begin{tikzpicture}
\begin{axis}[
xtick={1,...,4},
xticklabels={one, nine, seven, thirteen},
xticklabel style = {text width=2.4em},
]
\addplot coordinates {(1,0.78)(2,6.72)(3,4.25)(4,7.97)};
\end{axis}
\end{tikzpicture}
\caption{ }
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.48\linewidth}
\begin{tikzpicture}
\begin{axis}[
ymin=-1,
ymax=1,
xtick={1,2},
xticklabels={one, two},
xticklabel style = {text width=2.4em},
]
\addplot coordinates {(1,0.00)(2,-0.02)};
\end{axis}
\end{tikzpicture}
\caption{ }
\end{subfigure}
\caption{caption for all plots}
\label{all_plots}
\end{figure}
\end{document}