答案1
以下是一段简短的代码pstricks
:
\documentclass[border=5pt, svgnames]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pst-node}
\usepackage{ auto-pst-pdf } %% to compile with pdflatex --enable-write18 (MiKTeX) or pdflatex --shell-escape (TeX Live, MacTeX))
\usepackage{makebox}
\begin{document}
$ \begin{psmatrix}[rowsep=1.1cm, colsep=1.2cm, mnode = circle]%
%%%% Nodes
[name = I1] \infty &[fillcolor = Gainsboro!60!Lavender, fillstyle= solid, name = Z]
\makebox*{$\infty$}{$ 0 $} & [name = I3] \infty & [name = I4] \infty \\
[name = J1] \infty & [name = J2]\infty & [name = J3]\infty & [name = J4]\infty
%%%%% Connecting nodes
\foreach \S/\T in {J1/I1,I1/Z, Z/J2, J2/I3, J2/J3, J3/I3, J3/I4, J3/J4, I3/I4,I4/J4}{\ncline{\S}{\T}}
%%%%% Labelling nodes
\psset{labelsep = 3pt}
\foreach \N/\label in {I1/r, Z/s, I3/t, I4/u}{\nput{90}{\N}{\label}}
\foreach \N/\label in {J1/v, J2/w, J3/x, J4/y}{\nput{-90}{\N}{\label}}
\end{psmatrix} $
\end{document}
要获得带有阴影连接的图表,必须使用 border=length
和bordercolor=
键,但由于阴影,策略略有不同:我们构建一个empty
节点矩阵,连接这些节点,然后将 \pscirclebox
添加到这些节点:
\documentclass[border=5pt, svgnames]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pst-node}
\usepackage{ auto-pst-pdf } %% to compile with pdflatex --enable-write18 (MiKTeX) or pdflatex --shell-escape (TeX Live, MacTeX))
\begin{document}
$ \begin{psmatrix}[rowsep=1.1cm, emnode = p]%
%%%% Nodes
[name = Oa] &[name = Z] & [name = I3] & [name = I4] \\
[name = J1] & [name =Ob] & [name = J3] & [name = J4] %
%%%%% Connections
\foreach \S/\T in { J3/I3, J3/I4, J3/J4, I3/I4,I4/J4}{\ncline{\S}{\T}}
\foreach \S/\T in {J1/Oa, Oa/Z, ,Z/Ob, Ob/I3,Ob/J3}{\ncline[border = 3.5pt, bordercolor = LightSlateGray, nodesep = -1pt]{\S}{\T}}
%%%%% Labels
\foreach \N/\label in {Oa/r, Z/s, I3/t, I4/u}{\nput[labelsep = 15pt]{90}{\N}{\label}}
\foreach \N/\label in {J1/v, Ob/w, J3/x, J4/y}{\nput[labelsep = 9pt]{-90}{\N}{\label}}
%%%% Coloured and non-coloured nodes
\psset{fillstyle = solid}
\foreach \node in {I3,I4, J1, J3, J4}{\rput(\node){\pscirclebox{\infty}}}
\psset{framesep = 4.4pt, fillcolor = DarkSlateGrey }
\rput(Oa){\pscirclebox[fillcolor = Gainsboro!60!Lavender]{1}}
\rput(Z){\pscirclebox{\color{white}0}}
\rput(Ob){\pscirclebox{\color{white}1}}
\end{psmatrix} $
\end{document}