使用\includegraphics
和 PNG 图像,我能够并排对齐图形。但是,当我用 替换 时\includegraphics
,tikzpicture
图形并不并排。相反,它们一个在另一个之上。有没有办法让 tikz 图形并排?
\begin{figure}
\begin{subfigure}{0.15\textwidth}
\begin{tikzpicture}[->,>=stealth',node distance=1cm,
thick,main node/.style={circle,fill,inner sep=1.5pt}]
\node[main node] (1) [label=above:{$Z$}]{};
\node[main node] (2) [below left =0.5cm of 1,label=left:$X$]{};
\node[main node] (3) [below right =0.5cm of 1,label=right:$Y$] {};
\path[every node/.style={font=\sffamily\small}]
(1) edge node {} (2)
(1) edge node {} (3)
(2) edge node {} (3);
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}{0.15\textwidth}
\begin{tikzpicture}[->,>=stealth',node distance=1cm,
thick,main node/.style={circle,fill,inner sep=1.5pt}]
\node[main node] (1) [label=above:{$Z$}]{};
\node[main node] (2) [below left =0.5cm of 1,label=left:$X$]{};
\node[main node] (3) [below right =0.5cm of 1,label=right:$Y$] {};
\path[every node/.style={font=\sffamily\small}]
(1) edge node {} (3)
(2) edge node {} (3);
\end{tikzpicture}
\end{subfigure}
\end{figure}
答案1
每个subfigure
环境都变成一个框(a minipage
)。框之间的空行开始一个新段落,因此它们将排版在彼此下方。
要将subfigure
s 并排放置,请将空行替换为水平空格,如\quad
、\qquad
、\hspace{...}
、\hfill
,或者什么都不写。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\usepackage{subcaption}
\begin{document}
\quad
\begin{figure}
\centering
\begin{subfigure}{0.2\textwidth}
\begin{tikzpicture}[->,>=stealth',node distance=1cm,
thick,main node/.style={circle,fill,inner sep=1.5pt}]
\node[main node] (1) [label=above:{$Z$}]{};
\node[main node] (2) [below left =0.5cm of 1,label=left:$X$]{};
\node[main node] (3) [below right =0.5cm of 1,label=right:$Y$] {};
\path[every node/.style={font=\sffamily\small}]
(1) edge node {} (2)
(1) edge node {} (3)
(2) edge node {} (3);
\end{tikzpicture}
\end{subfigure}
\quad
\begin{subfigure}{0.2\textwidth}
\begin{tikzpicture}[->,>=stealth',node distance=1cm,
thick,main node/.style={circle,fill,inner sep=1.5pt}]
\node[main node] (1) [label=above:{$Z$}]{};
\node[main node] (2) [below left =0.5cm of 1,label=left:$X$]{};
\node[main node] (3) [below right =0.5cm of 1,label=right:$Y$] {};
\path[every node/.style={font=\sffamily\small}]
(1) edge node {} (3)
(2) edge node {} (3);
\end{tikzpicture}
\end{subfigure}
\end{figure}
\end{document}