最近有一个很好的答案在如何用 TikZ 绘制 3D 六边形结构?
但我注意到一个小“错误”,我似乎无法修复。我删除了显示问题的代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
\begin{scope}[%
every node/.style={anchor=west,regular polygon, regular polygon sides=6,draw,inner sep=0.5cm},
transform shape]
\node (A) {A};
\node (B) at (A.corner 1) {B};
\node (C) at (B.corner 5) {C};
\node (D) at (A.corner 5) {D};
\node (E) at (D.corner 5) {E};
\foreach \hex in {A,...,E}
{
\foreach \corn in {1,...,6}
\draw[fill=white] (\hex.corner \corn) circle (2pt);
}
\end{scope}
\end{tikzpicture}
\end{document}
这段代码绘制了五个六边形的节点,但是六边形虽然有几个,但是“几个数”总是不一样,像素“不”,如下图所示:
- 哪一个价值观导致了这种情况?
- 为什么“转变”会以不同的强度发生?
- 如何修复?
答案1
您需要outer sep=0
并且还inner sep
依赖于节点内容,并且节点大小会相应变化。您可以改用minimum height/width
键。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
\begin{scope}[%
every node/.style={anchor=west,
regular polygon,
regular polygon sides=6,
draw,
minimum width=2cm,
outer sep=0,
},
transform shape]
\node (A) {A};
\node (B) at (A.corner 1) {B};
\node (C) at (B.corner 5) {C};
\node (D) at (A.corner 5) {DECF};
\node (E) at (D.corner 5) {E};
\foreach \hex in {A,...,E}
{
\foreach \corn in {1,...,6}
\draw[fill=white] (\hex.corner \corn) circle (2pt);
}
\end{scope}
\end{tikzpicture}
\end{document}