我使用 TikZ 制作了两个图形,我想将它们并排放置。这是在 MWE 中完成的:
\documentclass{memoir}
\usepackage{graphicx}
\usepackage{tikz}
\newsubfloat{figure}
\begin{document}
\begin{figure}[htbp]
\centering
\subbottom[Convex set]{
\begin{tikzpicture}
\draw[rotate=-45,fill=gray!30] (0,0) ellipse (30pt and 45pt);
\end{tikzpicture}
}
\hspace{1cm}
\subbottom[Non-convex set]{
\begin{tikzpicture}
\draw[fill=gray!30] (0,0) to [out=140,in=90] (-1,-1)
to [out=-90,in=240] (0.8,-0.6)
to [out=60,in=-60] (1.2,1.2)
to [out=120,in=90] (0.3,0.7)
to [out=-90,in=20] (0.3,0)
to [out=200,in=-40] (0,0);
\draw (-0.5,-0.5) -- (0.7,0.7);
\fill (-0.5,-0.5) circle[radius=1.5pt];
\fill (0.7,0.7) circle[radius=1.5pt];
\end{tikzpicture}
}
\caption{Graphical interpretation of convex sets.}
\label{fig:convexSet}
\end{figure}
\end{document}
问题在于子图的顶部、中心和底部均未对齐。如何解决?是什么原因导致这种错位?TikZ 坐标系使用错误?
答案1
我认为to
路径使用了一些控制点来扩展第二个图形的边界框。您可以通过\draw (current bounding box.south east) rectangle (current bounding box.north west);
在每个末尾添加来看到这一点tikzpicture
,这将为您提供以下内容:
如您所见,第二个周围有一些额外的空白。我不知道如何自动修复此问题,但您可以使用以下命令手动设置边界框\useasboundingbox
:
\documentclass{memoir}
\usepackage{graphicx}
\usepackage{tikz}
\newsubfloat{figure}
\begin{document}
\begin{figure}[htbp]
\centering
\subbottom[Convex set]{
\begin{tikzpicture}
\draw[rotate=-45,fill=gray!30] (0,0) ellipse (30pt and 45pt);
%\draw (current bounding box.south east) rectangle (current bounding box.north west);
\end{tikzpicture}
}
\hspace{1cm}
\subbottom[Non-convex set]{
\begin{tikzpicture}
\useasboundingbox (-1,-1.35) rectangle (1.5,1.35); % values found by trial and error
\draw[fill=gray!30] (0,0) to [out=140,in=90] (-1,-1)
to [out=-90,in=240] (0.8,-0.6)
to [out=60,in=-60] (1.2,1.2)
to [out=120,in=90] (0.3,0.7)
to [out=-90,in=20] (0.3,0)
to [out=200,in=-40] (0,0);
\draw (-0.5,-0.5) -- (0.7,0.7);
\fill (-0.5,-0.5) circle[radius=1.5pt];
\fill (0.7,0.7) circle[radius=1.5pt];
%\draw (current bounding box.south east) rectangle (current bounding box.north west);
\end{tikzpicture}
}
\caption{Graphical interpretation of convex sets.}
\label{fig:convexSet}
\end{figure}
\end{document}