带顶点的链式图

带顶点的链式图

我想通过 latex 绘制图形?

在此处输入图片描述

答案1

这是一个简短的代码,pstricks(更准确地说pst-eucl是模块):

 \documentclass[border=6pt]{standalone}
\usepackage{pst-eucl}%
\begin{document}

    \begin{pspicture}(-6,-2)(6,5)\sffamily
    \psset{unit =1.5cm, dotsize=4pt, PtNameMath=false}
    \pstGeonode[PosAngle={-90,90,90,60,-120,-90}](-4,2){a1}(-4,3){a2}(-3,3){a3}(-2,3){a4}(-2,2){a5}(-3,2){a6}
    \pstGeonode[PosAngle={0,0,40,-140,180}](-1,2){b1}(-1,1){b2}(-1,0){b3}(-2,0){b4}(-2,1){b5}
    \pstGeonode[PosAngle={90,140,-60,-90,-100}](0,0){c1}(1,0){c2}(1,-1){c3}(0,-1){c4}(-1,-1){c5}
    \pstGeonode[PosAngle={180,180,0,0,40}](1,1){d1}(1,2){d2}(2,2){d3}(2,1){d4}(2,0){d5}
    \pstGeonode[PosAngle={90,90,-90,-90,-90}](3,0){e1}(4,0){e2}(4,-1){e3}(3,-1){e4}(2,-1){e5}
    \foreach \i/\j in{a1/a4,b4/b1,c5/c2,c2/d3,e5/e2}{\psframe(\i)(\j)}
    \end{pspicture}

\end{document} 

一些解释:\pstGeonode 可以创建一个点列表,给出它们的坐标和名称。名称会自动放置在点附近,方向为 PosAngle(默认为 0,即右侧)。名称默认为节点的名称,以数学模式输入。

在此处输入图片描述

编辑:要打印每个节点的数字,似乎我们不能给出一个数字作为 Geonode 名称,所以我们需要使用键PointName={...,...}来打印这些数字。这是显式代码:

\begin{pspicture}(-6,-2)(6,5)\sffamily \psset{unit =1.5cm, dotsize=4pt,
PtNameMath=false} 
\pstGeonode[PosAngle={-90,90,90,60,-120,-90}, PointName={1,2,3,4,5,6}] %
(-4,2){a1}(-4,3){a2}(-3,3){a3}(-2,3){a4}(-2,2){a5}(-3,2){a6}%
\pstGeonode[PosAngle={0,0,40,-140,180}, PointName={7,8,9,10,11}] %
(-1,2){b1}(-1,1){b2}(-1,0){b3}(-2,0){b4}(-2,1){b5}%
\pstGeonode[PosAngle={90,140,-60,-90,-100}, PointName={12,13,14,15,16}]%
(0,0){c1}(1,0){c2}(1,-1){c3}(0,-1){c4}(-1,-1){c5}%
\pstGeonode[PosAngle={180,180,0,0,40}, PointName={17,18,19,20,21}]%
(1,1){d1}(1,2){d2}(2,2){d3}(2,1){d4}(2,0){d5}%
 \pstGeonode[PosAngle={90,90,-90,-90,-90}, PointName={22,23,24,25,26}]%
(3,0){e1}(4,0){e2}(4,-1){e3}(3,-1){e4}(2,-1){e5}
%\foreach \i/\j in{1/4,10/7,16/13,13/19,26/23}{\psframe(\i)(\j)} \end{pspicture}
\foreach \i/\j in{a1/a4,b4/b1,c5/c2,c2/d3,e5/e2}{\psframe(\i)(\j)}%
\end{pspicture}

在此处输入图片描述

相关内容