这个问题与通过几个定义在 TikZ 中创建一组图表。
在以下第一个菱形中的 MBWE 线中,原本应该垂直,但却出现了意外的角度。我应该知道什么才能纠正此行为?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
[inner sep=0.7mm,
koc/.style={circle,draw=black,fill=black,thick,minimum size=3mm},
kob/.style={circle,draw=black,fill=white,thick,minimum size=3mm},
kwc/.style={rectangle,draw=black,fill=black,thick,minimum size=3mm},
kwb/.style={rectangle,draw=black,fill=white,thick,minimum size=3mm},
trc/.style={regular polygon, regular polygon sides=3,draw=black,fill=black,thick, minimum size=1mm},
empty/.style={},
trb/.style={regular polygon, regular polygon sides=3,draw=black,fill=white,thick,minimum size=1mm}]
\node[trc] (A)[label=above:$a$] {};
\node[kob] (D) [above right=of A] {};
\node[empty](empty)[right=of A]{};
\node[kwb] (F) [below right=of A] {};
\begin{scope}[on grid,node distance=9mm]
\node[kwc] (B) [below=of D,label=above left:$b$] {};
\node[kob] (E) [above=of F] {};
%\node[trc] (F) [below right=of A] {f};
\end{scope}
\node[trc](C)[right=of empty,label= above:$c$]{};
\foreach \k in {D,B,E,F} \draw(A)--(\k);
\foreach \k in {D,B,E,F}\draw (\k)--(C);
\draw (D)--(B);
\draw (B)--(E);
\draw (E)--(F);
\end{tikzpicture}
\hspace{1cm}
\begin{tikzpicture}
[inner sep=0.7mm,
koc/.style={circle,draw=black,fill=black,thick,minimum size=3mm},
kob/.style={circle,draw=black,fill=white,thick,minimum size=3mm},
kwc/.style={rectangle,draw=black,fill=black,thick,minimum size=3mm},
kwb/.style={rectangle,draw=black,fill=white,thick,minimum size=3mm},
trc/.style={regular polygon, regular polygon sides=3,draw=black,fill=black,thick, minimum size=1mm},
empty/.style={},
trb/.style={regular polygon, regular polygon sides=3,draw=black,fill=white,thick,minimum size=1mm}]
\node[kwb] (A) {};
\node[kob] (D) [above right=of A] {};
\node[empty](empty)[right=of A]{};
\node[kob] (F) [below right=of A] {};
\begin{scope}[on grid,node distance=8mm]
\node[trc] (B) [right=of A,label=above right:$a$] {};
\node[kwc] (E) [left=of C,label=above right:$b$] {};
\end{scope}
\node[trc](C)[right=of empty,label=above right:$c$]{};
\foreach \k in {A,B,E,C} \draw(D)--(\k);
\foreach \k in {A,B,E,C}\draw (\k)--(F);
\draw (A)--(B);
\draw (B)--(E);
\draw (E)--(C);
\end{tikzpicture}
\caption{Case $(\beta,2)$ of Lemma 2.2}
\end{figure}
\end{document}
答案1
以下是不同的做法,使用diamond
形状表示四个外部节点,使用路径表示两个内部节点。最好使用以下任一方法
outer sep=+0pt
对于每个节点,line cap=rect
对于线条,和/或- 钻石
draw
这样线条就不会尴尬地结束于节点的边界(这仅在高缩放级别下可见)。
我擅自重新组织了样式。
代码
\documentclass[tikz,convert]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[
every whateverthisis/.style={thick, draw=black, inner sep=+0.7mm},
circle style/.style= {shape=circle, minimum size=+3mm},
rect style/.style= {shape=rectangle, minimum size=+3mm},
triangle style/.style={shape=regular polygon, regular polygon sides=3, minimum size=+1mm},
black style/.style={fill=black},
white style/.style={ },
koc/.style={every whateverthisis, circle style, black style},
kob/.style={every whateverthisis, circle style, white style},
kwc/.style={every whateverthisis, rect style, black style},
kwb/.style={every whateverthisis, rect style, white style},
trc/.style={every whateverthisis, triangle style, black style},
trb/.style={every whateverthisis, triangle style, white style},
]
\node[shape=diamond, minimum size=2.5cm, outer sep=+0pt] (d) {};
\node[trc, label=above:$a$] at (d.west) (A) {};
\node[trc, label=above:$c$] at (d.east) (C) {};
\node[kob] at (d.north) (D) {};
\node[kwb] at (d.south) (F) {};
\path (d.north) -- (d.south) node [pos=.4, kwc, label=above left:$b$] (B) {}
node [pos=.6, kob] (E) {};
\draw (A) -- (D) -- (C) -- (F) -- (A);
\path (B) edge (A) edge (C) edge (D) edge (E)
(E) edge (A) edge (C) edge (F);
\end{tikzpicture}
\end{document}
输出
答案2
防止该问题的一个简单方法是使用以下on grid
选项:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
[inner sep=0.7mm,
koc/.style={circle,draw=black,fill=black,thick,minimum size=3mm},
kob/.style={koc,fill=white},
kwc/.style={rectangle,draw=black,fill=black,thick,minimum size=3mm},
kwb/.style={kwc,fill=white},
trc/.style={regular polygon, regular polygon sides=3,draw=black,fill=black,thick, minimum size=1mm},
empty/.style={},
trb/.style={trc,fill=white},on grid,node distance=12mm and 12mm]
\node[trc] (A)[label=above:$a$] {};
\node[kob] (D) [above right=of A] {};
\node[empty](empty)[right=of A]{};
\node[kwb] (F) [below right=of A] {};
\begin{scope}[on grid,node distance=9mm]
\node[kwc] (B) [below=26pt of D,label=above left:$b$] {};
\node[kob] (E) [above=26pt of F] {};
%\node[trc] (F) [below right=of A] {f};
\end{scope}
\node[trc](C)[right=of empty,label= above:$c$]{};
\foreach \k in {D,B,E,F} \draw(A)--(\k);
\foreach \k in {D,B,E,F}\draw (\k)--(C);
\draw (D)--(B);
\draw (B)--(E);
\draw (E)--(F);
\end{tikzpicture}
\caption{Case $(\beta,2)$ of Lemma 2.2}
\end{figure}
\end{document}