可能重复:
如何制作以下精确的六边形?
我想创建一个六边形图,其中节点是行向量,边是带标签的箭头(我试图说明一个循环)。请参阅下面的尝试:
\documentclass{article}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{tikzpicture}[->,shorten >=0.2pt,auto,node distance=2.5cm,semithick]
\tikzstyle{every state}=[fill=none,draw=none,text=black]
\node[state] (A) {$(1,1,1)$};
\node[state] (B) [below right of=A] {$(1,1,1)$};
\node[state] (C) [below of=B] {$(1,1,1)$};
\node[state] (D) [below left of=C] {$(1,1,1)$};
\node[state] (E) [above left of=D] {$(1,1,1)$};
\node[state] (F) [above of = E] {$(1,1,1)$};
\path (A) edge node {$A$} (B)
(B) edge node {$A$} (C)
(C) edge node {$A$} (D)
(D) edge node {$A$} (E)
(E) edge node {$A$} (F)
(F) edge node {$A$} (A);
\end{tikzpicture}
\end{document}
我希望它是一个正六边形,但这不是。我还希望箭头的末端更靠近节点。我该如何对此进行排序?
谢谢
答案1
您还可以使用绝对坐标并使用 x 和 y 单位向量指向的方向:
\documentclass{article}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{tikzpicture}[->,shorten >=0.2pt,auto,node distance=2.5cm,semithick,x={(1,0)},y={({cos(60)},{sin(60)})}]
\tikzstyle{every state}=[fill=none,draw=none,text=black]
\node[state] (A) at (0,0) {$(1,1,1)$};
\node[state] (B) at (3,0) {$(1,1,1)$};
\node[state] (C) at (3,3) {$(1,1,1)$};
\node[state] (D) at (0,6) {$(1,1,1)$};
\node[state] (E) at (-3,6) {$(1,1,1)$};
\node[state] (F) at (-3,3) {$(1,1,1)$};
\path (A) edge node {$A$} (B)
(B) edge node {$A$} (C)
(C) edge node {$A$} (D)
(D) edge node {$A$} (E)
(E) edge node {$A$} (F)
(F) edge node {$A$} (A);
\end{tikzpicture}
\end{document}
编辑1:如果你想要六边形“站在一个角落”,你可以使用这个:
\begin{tikzpicture}[->,shorten >=0.2pt,auto,node distance=2.5cm,semithick,x={({cos(30)*1cm},{sin(30)*1cm})},y={({cos(150)*1cm},{sin(150)*1cm})}]
\tikzstyle{every state}=[fill=none,draw=none,text=black]
\node[state] (A) at (0,0) {$(1,1,1)$};
\node[state] (B) at (3,0) {$(1,1,1)$};
\node[state] (C) at (6,3) {$(1,1,1)$};
\node[state] (D) at (6,6) {$(1,1,1)$};
\node[state] (E) at (3,6) {$(1,1,1)$};
\node[state] (F) at (0,3) {$(1,1,1)$};
\path (A) edge node {$A$} (B)
(B) edge node {$A$} (C)
(C) edge node {$A$} (D)
(D) edge node {$A$} (E)
(E) edge node {$A$} (F)
(F) edge node {$A$} (A);
\end{tikzpicture}
请注意,我必须添加,*1cm
因为 tikz 显示了一些奇怪的行为:虽然给出的一些尺寸被解释为点,其他的则被解释为厘米。删除这四个,*1cm
你就能自己看到!
答案2
您可以独立地在两个方向上使用node distance
。我已经近似了正弦和余弦值的两倍。此外,额外的空间减少了inner sep
和outer sep
选项。如果需要,您可以为选项提供一些负数shorten
以获得更多扩展。
我稍微清理了一下代码,并添加了另一个 TikZ 库。请注意你的和我的positioning
之间的区别。above of=C
above = of C
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,positioning}
\begin{document}
\begin{tikzpicture}[->,shorten >=0.2pt,auto,%
node distance=1cm and 1.7cm,%
semithick,%
every state/.style={fill=none,draw=none,text=black, outer sep=1pt, inner sep=0}%
]
\node[state] (A) {$(1,1,1)$};
\node[state] (B) [below right = of A] {$(1,1,1)$};
\node[state] (C) [below = of B] {$(1,1,1)$};
\node[state] (D) [below left = of C] {$(1,1,1)$};
\node[state] (E) [above left = of D] {$(1,1,1)$};
\node[state] (F) [above = of E] {$(1,1,1)$};
\path (A) edge node {$A$} (B)
(B) edge node {$A$} (C)
(C) edge node {$A$} (D)
(D) edge node {$A$} (E)
(E) edge node {$A$} (F)
(F) edge node {$A$} (A);
\end{tikzpicture}
\end{document}
答案3
我还添加了这个解决方案,因为它更简洁。
\documentclass{article}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{tikzpicture}[->,shorten >=0.2pt,auto,node distance=2.5cm,semithick]
\tikzstyle{every state}=[fill=none,draw=none,text=black]
\draw
\foreach \angle/\label in {0/A,60/B,120/C,180/D,240/E,300/F}{
(\angle:3cm) node(\label)[state] {$(1,1,1)$}
}
\foreach \start/\destination in {A/B,B/C,C/D,D/E,E/F,F/A} {
(\start) edge node {$A$} (\destination)
};
\end{tikzpicture}
\end{document}