[ ]
嗨,我正在尝试绘制下面的图像,但线条没有穿过节点,但我似乎无法弄清楚。以下是代码。
\documentclass[12pt,a4paper,top=1in,bottom=1in,left=1.5in,right=1.5in,margin=1.5in]{article}
\usepackage{tikz}
\usetikzlibrary{automata}
\begin{tikzpicture} [scale = 0.4]
\tikzstyle{vertex} = [circle, fill = black!10]
\tikzstyle{edge} = [thick]
\node[vertex](v1) at (0,0){1};
\node[vertex](v2) at (3,0){2};
\node[vertex] (v3) at (6,0) {3};
\node[vertex](v4) at (9,0){4};
\node[vertex](v5) at (12,0){5};
\node[vertex](v6) at (15,0){6};
\node[vertex](v7) at (18,0){7};
\node[vertex](v8) at (21,0){8};
\node[vertex](v9) at (24,0){9};
\node[vertex](v10) at (27,0){10};
\node[vertex](v11) at (30,0){11};
\node[vertex](v11) at (33,0){12};
\node[vertex](v13) at (36,0){13};
\draw [edge](v1) --(v13);
\path
(v1) edge [bend left] node {} (v13)
(v3) edge [bend left] node {} (v11)
(v5) edge [bend left] node {} (v8)
\end{tikzpicture}
\end{document}
答案1
看看以下解决方案是否适合您:
\documentclass[12pt,a4paper]{article}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{chains,
positioning
}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[
node distance = 5mm,
start chain = A going right, % <---
vertex/.style = {circle, fill=gray!30,
minimum size=1.3em, inner sep=0pt,
font=\small\bfseries,
on chain=A, join = by arr,
},
arr/.style = {-, semithick},
]
\foreach \i in {1,...,13}
\node[vertex] {\i};
%
\path[arr, bend left=45]
(A-1) edge (A-13)
(A-3) edge (A-11)
(A-5) edge (A-8);
\end{tikzpicture}
\end{figure}
\end{document}
笔记:
- 用于定位节点
chains
和positioning
包 - 节点名称由 定义
start chain = A going right
;因此第一个节点名称是A-1
,最后一个节点名称是A-13
- 节点之间的距离由 决定
node distance
;它定义节点边界之间的距离 chains
节点之间的线由包宏绘制join
。- 在您的文档类选项中,您遇到了麻烦,因为页面布局添加了“几何”包