我正在尝试通过两个子图环境将两个 tikzpicture 放在一起。如您在第一张图片中看到的,它们不是水平对齐的。您可以在第二张图片中看到它应该是什么样子。
我注意到了一些事情:
- 标题太长,图片会不对齐。标题短一点就可以了。
- 当我给每个子图指定宽度时,
0.4\textwidth
图片是不对齐的。较小的宽度就可以了。 - 当我注释掉标题时,图片就对齐了。
提前致谢
第一张图片:
第二张图片:
我的代码如下:
\begin{figure}[]
\centering
\begin{subfigure}[b]{0.4\textwidth}
\centering
\input{figures/chapter_1/Wahrscheinlichkeitsfunktion.tex}
\caption{Wahrscheinlichkeitsfunktion der Haushaltsgröße.}
\label{fig:Wahrscheinlichkeitsfunktion}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.4\textwidth}
\centering
\input{figures/chapter_1/Verteilungsfunktion.tex}
\caption{Verteilungsfunktion der Haushaltsgröße.}
\label{fig:Verteilungsfunktion}
\end{subfigure}
\end{figure}
真理功能.tex
% This file was created by tikzplotlib v0.9.8.
\begin{tikzpicture}
\pgfplotsset{%
width=\textwidth
}
\definecolor{color0}{rgb}{0,0.56078431372549,0.835294117647059}
\begin{axis}[
axis line style={white!94.1176470588235!black},
tick align=outside,
tick pos=left,
title={short title},
x grid style={white!79.6078431372549!black},
xlabel={\(\displaystyle x \in \Omega\)},
xmajorgrids,
xmin=-0.75, xmax=4.75,
xtick style={color=black},
y grid style={white!79.6078431372549!black},
ylabel={Wahrscheinlichkeit},
ymajorgrids,
ymin=0, ymax=0.42,
ytick style={color=black}
]
\draw[draw=black,fill=color0,very thick] (axis cs:-0.5,0) rectangle (axis cs:0.5,0.1);
\draw[draw=black,fill=color0,very thick] (axis cs:0.5,0) rectangle (axis cs:1.5,0.2);
\draw[draw=black,fill=color0,very thick] (axis cs:1.5,0) rectangle (axis cs:2.5,0.4);
\draw[draw=black,fill=color0,very thick] (axis cs:2.5,0) rectangle (axis cs:3.5,0.2);
\draw[draw=black,fill=color0,very thick] (axis cs:3.5,0) rectangle (axis cs:4.5,0.1);
\end{axis}
\end{tikzpicture}
转让功能.tex
% This file was created by tikzplotlib v0.9.8.
\begin{tikzpicture}
\pgfplotsset{%
width=\textwidth
}
\definecolor{color0}{rgb}{0,0.56078431372549,0.835294117647059}
\begin{axis}[
axis line style={white!94.1176470588235!black},
tick align=outside,
tick pos=left,
title={Verteilungsfunktion \(\displaystyle F(x)\)},
x grid style={white!79.6078431372549!black},
xlabel={\(\displaystyle x \in \Omega\)},
xmajorgrids,
xmin=-0.75, xmax=4.75,
xtick style={color=black},
y grid style={white!79.6078431372549!black},
ylabel={Wahrscheinlichkeit},
ymajorgrids,
ymin=0, ymax=1.05,
ytick style={color=black}
]
\draw[draw=black,fill=color0,very thick] (axis cs:-0.5,0) rectangle (axis cs:0.5,0.1);
\draw[draw=black,fill=color0,very thick] (axis cs:0.5,0) rectangle (axis cs:1.5,0.3);
\draw[draw=black,fill=color0,very thick] (axis cs:1.5,0) rectangle (axis cs:2.5,0.7);
\draw[draw=black,fill=color0,very thick] (axis cs:2.5,0) rectangle (axis cs:3.5,0.9);
\draw[draw=black,fill=color0,very thick] (axis cs:3.5,0) rectangle (axis cs:4.5,1);
\end{axis}
\end{tikzpicture}
答案1
使用简单的 MWE 和您提供的精确代码,我没有发现图形之间有任何错位。
所以问题一定出在你的代码的其他地方。
要调试它,请在您的系统上运行我的示例,以验证它是否有效,然后开始逐个添加包和命令。
% !TeX TS-program = pdflatex
\documentclass[12pt,a4paper]{article}
\usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage[ngerman]{babel}
\usepackage{libertine}
\renewcommand*\familydefault{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage{subcaption}
\begin{document}
\begin{figure}[]
\centering
\begin{subfigure}[b]{0.4\textwidth}
\centering
\input{Wahrscheinlichkeitsfunktion}
\caption{Wahrscheinlichkeitsfunktion der Haushaltsgröße.}
\label{fig:Wahrscheinlichkeitsfunktion}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.4\textwidth}
\centering
\input{Verteilungsfunktion}
\caption{Verteilungsfunktion der Haushaltsgröße.}
\label{fig:Verteilungsfunktion}
\end{subfigure}
\end{figure}
\end{document}