我在图中有两个 tikz 图片。以下是代码:
\begin{figure}[H]
\begin{tikzpicture}
\draw (0,0) node (a1) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=left:$a_1$] {}
-- ++(252:1.2cm) node (a2) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=left:$a_2$] {}
-- ++(324:1.2cm) node (a3) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt,label=left:$a_3$] {}
-- ++(36:1.2cm) node (a4) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=left:$a_4$] {}
-- ++(108:1.2cm) node (a5) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=above:$a_5$] {}
-- (a1);
\draw (0.75,-2.2) node (aux1)[minimum size=0pt, inner sep=0pt]{};
\draw (4,0) node (b3) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=right:$b_3$] {}
-- ++(216:1.2cm) node (b2) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=right:$b_2$] {}
-- ++(288:1.2cm) node (b1) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=below:$b_1$] {}
-- ++(0:1.2cm) node (b5) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=right:$b_5$] {}
-- ++(72:1.2cm) node (b4) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=right:$b_4$] {}
-- (b3);
\draw (4,0.4) node (aux2)[minimum size=0pt, inner sep=0pt]{};
\draw (a1) -- (a3);
\draw (a5) -- (a3);
\draw (b3) -- (b1);
\draw (b3) -- (b5);
\draw (a5) -- (b2);
\draw (a4) -- (b1);
\draw (a2) to [out=-80,in=180] (aux1);
\draw (aux1) to [out=0,in=-100] (a4);
\draw (a2) to [out=-90,in=-110] (b5);
\draw (b2) to [out=90,in=180] (aux2);
\draw (aux2) to [out=-10,in=110] (b4);
%\draw (b2) to [out=80,in=100] (b4);
\draw (a1) to [out=70,in=90] (b4);
\end{tikzpicture}
\hspace{0.3cm}
\begin{tikzpicture}
\tikzstyle{every node}=[draw,circle,fill=white,minimum size=4pt, inner sep=0pt]
\draw (0,0) node (3) [label=above:$3$] {}
-- ++(216:1.2cm) node (2) [label=left:$2$] {}
-- ++(288:1.2cm) node (1) [label=left:$1$] {}
-- ++(0:1.2cm) node (5) [label=right:$5$] {}
-- ++(72:1.2cm) node (4) [label=right:$4$] {}
-- (3);
\draw (1) -- (3);
\draw (1) -- (4);
\draw (2) -- (4);
\draw (2) -- (5);
\draw (3) -- (5);
\end{tikzpicture}
\caption{}
\end{figure}
如您所见,这些图并不并排,第二张图比第一张图略低。所以如果有人有时间回答,请给我一个可能的解决方案。我怎样才能让三个五边形并排?
答案1
只需将baseline
密钥添加到两个 tikz 图片中即可。
\documentclass[]{article}
\usepackage{tikz}
\begin{document}
\begin{figure}[h]
\begin{tikzpicture}[baseline]
\draw (0,0) node (a1) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=left:$a_1$] {}
-- ++(252:1.2cm) node (a2) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=left:$a_2$] {}
-- ++(324:1.2cm) node (a3) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt,label=left:$a_3$] {}
-- ++(36:1.2cm) node (a4) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=left:$a_4$] {}
-- ++(108:1.2cm) node (a5) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=above:$a_5$] {}
-- (a1);
\draw (0.75,-2.2) node (aux1)[minimum size=0pt, inner sep=0pt]{};
\draw (4,0) node (b3) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=right:$b_3$] {}
-- ++(216:1.2cm) node (b2) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=right:$b_2$] {}
-- ++(288:1.2cm) node (b1) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=below:$b_1$] {}
-- ++(0:1.2cm) node (b5) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=right:$b_5$] {}
-- ++(72:1.2cm) node (b4) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=right:$b_4$] {}
-- (b3);
\draw (4,0.4) node (aux2)[minimum size=0pt, inner sep=0pt]{};
\draw (a1) -- (a3);
\draw (a5) -- (a3);
\draw (b3) -- (b1);
\draw (b3) -- (b5);
\draw (a5) -- (b2);
\draw (a4) -- (b1);
\draw (a2) to [out=-80,in=180] (aux1);
\draw (aux1) to [out=0,in=-100] (a4);
\draw (a2) to [out=-90,in=-110] (b5);
\draw (b2) to [out=90,in=180] (aux2);
\draw (aux2) to [out=-10,in=110] (b4);
%\draw (b2) to [out=80,in=100] (b4);
\draw (a1) to [out=70,in=90] (b4);
\end{tikzpicture}
\hspace{0.3cm}
\begin{tikzpicture}[baseline]
\tikzstyle{every node}=[draw,circle,fill=white,minimum size=4pt, inner sep=0pt]
\draw (0,0) node (3) [label=above:$3$] {}
-- ++(216:1.2cm) node (2) [label=left:$2$] {}
-- ++(288:1.2cm) node (1) [label=left:$1$] {}
-- ++(0:1.2cm) node (5) [label=right:$5$] {}
-- ++(72:1.2cm) node (4) [label=right:$4$] {}
-- (3);
\draw (1) -- (3);
\draw (1) -- (4);
\draw (2) -- (4);
\draw (2) -- (5);
\draw (3) -- (5);
\end{tikzpicture}
\caption{}
\end{figure}
\end{document}
答案2
或者在同一个里面绘制两个图形tikzpicture
:
\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}[h]
\begin{tikzpicture}[baseline]
\draw (0,0) node (a1) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=left:$a_1$] {}
-- ++(252:1.2cm) node (a2) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=left:$a_2$] {}
-- ++(324:1.2cm) node (a3) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt,label=left:$a_3$] {}
-- ++(36:1.2cm) node (a4) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=left:$a_4$] {}
-- ++(108:1.2cm) node (a5) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=above:$a_5$] {}
-- (a1);
\draw (0.75,-2.2) node (aux1)[minimum size=0pt, inner sep=0pt]{};
\draw (4,0) node (b3) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=right:$b_3$] {}
-- ++(216:1.2cm) node (b2) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=right:$b_2$] {}
-- ++(288:1.2cm) node (b1) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=below:$b_1$] {}
-- ++(0:1.2cm) node (b5) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=right:$b_5$] {}
-- ++(72:1.2cm) node (b4) [draw,circle,fill=white,minimum size=4pt, inner sep=0pt, label=right:$b_4$] {}
-- (b3);
\draw (4,0.4) node (aux2)[minimum size=0pt, inner sep=0pt]{};
\draw (a1) -- (a3);
\draw (a5) -- (a3);
\draw (b3) -- (b1);
\draw (b3) -- (b5);
\draw (a5) -- (b2);
\draw (a4) -- (b1);
\draw (a2) to [out=-80,in=180] (aux1);
\draw (aux1) to [out=0,in=-100] (a4);
\draw (a2) to [out=-90,in=-110] (b5);
\draw (b2) to [out=90,in=180] (aux2);
\draw (aux2) to [out=-10,in=110] (b4);
%\draw (b2) to [out=80,in=100] (b4);
\draw (a1) to [out=70,in=90] (b4);
% \end{tikzpicture}
% \hspace{0.3cm}
% \begin{tikzpicture}[baseline]
\begin{scope}[every node/.style={draw,circle,fill=white,minimum size=4pt, inner sep=0pt}]
\draw node[right=3cm of b3] (3) [label=above:$3$] {} (3)
-- ++(216:1.2cm) node (2) [label=left:$2$] {}
-- ++(288:1.2cm) node (1) [label=left:$1$] {}
-- ++(0:1.2cm) node (5) [label=right:$5$] {}
-- ++(72:1.2cm) node (4) [label=right:$4$] {}
-- (3);
\draw (1) -- (3);
\draw (1) -- (4);
\draw (2) -- (4);
\draw (2) -- (5);
\draw (3) -- (5);
\end{scope}
\end{tikzpicture}
\caption{}
\end{figure}
\end{document}
更新:(与之前的答案无关)
只是为了好玩,在这里你可以找到上一个图形的另一种解决方案。
我使用了regular polygons
节点及其已定义的锚点。这样更容易对它们使用相对放置。两个直五边形节点用于transform shape, xscale=-1
将角顺序恢复为 CW。
顶点上的标签用三种结构来放置foreach
。
通过在构造中添加一些点,aux1
消除aux2
了和节点。希望对您有所帮助。control
to
\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.geometric}
\begin{document}
\begin{figure}[h]
\begin{tikzpicture}[vertex/.style={circle, fill=white, minimum size=4pt, inner sep=0pt, draw}]
\node[draw, regular polygon, shape border rotate=36, minimum size=2cm, anchor=corner 1] (a) {};
\draw (a.corner 3) edge (a.corner 1) edge (a.corner 5);
\node[draw, regular polygon, shape border rotate=216, minimum size=2cm, right=4cm of a.corner 1, anchor=corner 3, transform shape, xscale=-1] (b) {};
\draw (b.corner 3) edge (b.corner 1) edge (b.corner 5);
\node[draw, regular polygon, shape border rotate=216, minimum size=2cm, right=4cm of b.corner 3, anchor=corner 3, transform shape, xscale=-1] (c) {};
\foreach \i/\j in {1/3,2/4,3/5,4/1,5/2}
\draw (c.corner \i) edge (c.corner \j);
\foreach \i [count=\ni] in {left, left, left, left, above}
\node[vertex, label=\i:{$a_\ni$}] (a\ni) at (a.corner \ni) {};
\foreach \i [count=\ni] in {below, right, right, right, right}
\node[vertex, label=\i:{$b_\ni$}] (b\ni) at (b.corner \ni) {};
\foreach \i [count=\ni] in {left,left,above,right,right}
\node[vertex, label=\i:{$\ni$}] (c\ni) at (c.corner \ni) {};
\draw (a5) -- (b2);
\draw (a4) -- (b1);
\draw (a2) to [controls=+(-90:1.2) and +(-90:1.2), out=-80,in=-110] (a4);
\draw (a2) to [out=-90,in=-110] (b5);
\draw (b2) to [controls=+(90:1.2) and +(90:1.2), out=90,in=110] (b4);
\draw (a1) to [out=70,in=90] (b4);
\end{tikzpicture}
\caption{}
\end{figure}
\end{document}