我有一个用 latex 制作的图表,每条边(图表的线)都有对应的值。我该如何将它们的值放在图表的每条线上,最好是靠近起源节点?
下面是我的代码。
% C(n,4) points of intersection
% Author: Hugues Vermeiren
\documentclass{article}
\usepackage{comment}
\usepackage{tikz}
\usepackage{ifthen}
\usepackage{amsmath}
\usetikzlibrary{arrows,calc,intersections}
% 1) Represent n points on a circle
% 2) Draw the complete graph on these points
% 3) Draw all the intersection points of any two of these segments
\begin{document}
\def\r{8} % Determina o tamanho geral do grafo
\def\n{9} \def\myangles{{36,72,108,144,180,216,252,288,324,360}}
%This vector contains the angles detere mining the position of the points.
%-----------------------------------------------------------
% Variables and counters used to generate the 4-combinations
\newcounter{np} \pgfmathsetcounter{np}{\n+1}
\newcounter{na} \newcounter{nb} \newcounter{nc}
\newcounter{ia}
\pgfmathsetcounter{na}{\n-1} % saves some computations later
\pgfmathsetcounter{nb}{\n-2} % ""
\pgfmathsetcounter{nc}{\n-3} % ""
\newcounter{q} \setcounter{q}{0} % if flag q=1 then exit the whiledo loop
\newcounter{e} \setcounter{e}{0} % e counts the combinations!
\newcounter{a} \setcounter{a}{0} % element of the 4-combination
\newcounter{b} \setcounter{b}{1} % ""
\newcounter{c} \setcounter{c}{2} % ""
\newcounter{d} \setcounter{d}{2} % ""
\begin{center}
\begin{tikzpicture}
\fill[fill=blue!10!green!10!,draw=blue,dotted,thick] (0,0) circle (\r);
\pgfmathparse{\n-1} \let\nn\pgfmathresult
% Determination of edges (lines connecting the nodes)
% Homo sapiens
% Edge Hs-Pt: 235
\pgfmathparse{0} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[0]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[1]} \let\u\pgfmathresult % Destination node
\draw[red,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Hs-Gg: 205
\pgfmathparse{0} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[0]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[2]} \let\u\pgfmathresult % Destination node
\draw[red,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Hs-Pa: 121
\pgfmathparse{0} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[0]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[3]} \let\u\pgfmathresult % Destination node
\draw[red,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Hs-Nl: 246
\pgfmathparse{0} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[0]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[4]} \let\u\pgfmathresult % Destination node
\draw[red,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Hs-Mm: 325
\pgfmathparse{0} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[0]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[5]} \let\u\pgfmathresult % Destination node
\draw[red,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Hs-Cj: 184
\pgfmathparse{0} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[0]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[6]} \let\u\pgfmathresult % Destination node
\draw[red,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Hs-Ts: 16
\pgfmathparse{0} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[0]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[7]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Hs-Og: 6
\pgfmathparse{0} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[0]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[8]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Hs-Mu: 1
\pgfmathparse{0} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[0]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[9]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Pan troglodytes
% Edge Pt-Gg: 69
\pgfmathparse{1} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[1]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[2]} \let\u\pgfmathresult % Destination node
\draw[green,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Pt-Pa: 53
\pgfmathparse{1} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[1]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[3]} \let\u\pgfmathresult % Destination node
\draw[green,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Pt-Nl: 83
\pgfmathparse{1} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[1]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[4]} \let\u\pgfmathresult % Destination node
\draw[green,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Pt-Mm: 64
\pgfmathparse{1} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[1]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[5]} \let\u\pgfmathresult % Destination node
\draw[green,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Pt-Cj: 58
\pgfmathparse{1} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[1]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[6]} \let\u\pgfmathresult % Destination node
\draw[green,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Pt-Ts: 3
\pgfmathparse{1} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[1]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[7]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Pt-Mu: 1
\pgfmathparse{1} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[1]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[9]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Gorilla gorilla
% Edge Gg-Pa: 66
\pgfmathparse{2} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[2]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[3]} \let\u\pgfmathresult % Destination node
\draw[green,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Gg-Nl: 66
\pgfmathparse{2} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[2]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[4]} \let\u\pgfmathresult % Destination node
\draw[green,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Gg-Mm: 81
\pgfmathparse{2} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[2]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[5]} \let\u\pgfmathresult % Destination node
\draw[green,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Gg-Cj: 72
\pgfmathparse{2} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[2]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[6]} \let\u\pgfmathresult % Destination node
\draw[green,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Gg-Ts: 3
\pgfmathparse{2} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[2]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[7]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Gg-Og: 1
\pgfmathparse{2} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[2]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[8]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Gg-Mu: 3
\pgfmathparse{2} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[2]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[9]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Pongo abelii
% Edge Pa-Nl: 66
\pgfmathparse{3} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[3]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[4]} \let\u\pgfmathresult % Destination node
\draw[green,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Pa-Mm: 150
\pgfmathparse{3} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[3]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[5]} \let\u\pgfmathresult % Destination node
\draw[red,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Pa-Cj: 50
\pgfmathparse{3} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[3]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[6]} \let\u\pgfmathresult % Destination node
\draw[green,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Pa-Ts: 2
\pgfmathparse{3} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[3]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[7]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Pa-Mu: 2
\pgfmathparse{3} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[3]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[9]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Nomascus leucogenys
% Edge Nl-Mm: 183
\pgfmathparse{4} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[4]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[5]} \let\u\pgfmathresult % Destination node
\draw[red,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Nl-Cj: 91
\pgfmathparse{4} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[4]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[6]} \let\u\pgfmathresult % Destination node
\draw[green,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Nl-Ts: 3
\pgfmathparse{4} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[4]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[7]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Nl-Og: 4
\pgfmathparse{4} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[4]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[8]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Macaca mulatta
% Edge Mm-Cj: 158
\pgfmathparse{5} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[5]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[6]} \let\u\pgfmathresult % Destination node
\draw[red,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Mm-Ts: 7
\pgfmathparse{5} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[5]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[7]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Mm-Og: 5
\pgfmathparse{5} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[5]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[8]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Mm-Mu: 1
\pgfmathparse{5} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[5]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[9]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Callithrix jacchus
% Edge Cj-Ts: 5
\pgfmathparse{6} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[6]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[7]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Cj-Og: 3
\pgfmathparse{6} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[6]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[8]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Edge Cj-Mu: 1
\pgfmathparse{6} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[6]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[9]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Tarsius syrichta
% Edge Ts-Mu: 1
\pgfmathparse{7} \let\ii\pgfmathresult % Start node
\pgfmathparse{\myangles[7]} \let\t\pgfmathresult % Start node
\pgfmathparse{\myangles[9]} \let\u\pgfmathresult % Destination node
\draw[blue,very thick] ({\r*cos(\t)},{\r*sin(\t)})--({\r*cos(\u)},{\r*sin(\u)});
% Determination of the nodes
% Node Homo sapiens
\pgfmathparse{\myangles[0]} \let\t\pgfmathresult
\pgfmathsetcounter{ia}{1}
\fill[draw=blue,fill=blue!20!,thick]
({\r*cos(\t)},{\r*sin(\t)})circle (4.5mm) node{$\mathbf{Hs}$};
% Node Pan troglodytes
\pgfmathparse{\myangles[1]} \let\t\pgfmathresult
\pgfmathsetcounter{ia}{2}
\fill[draw=blue,fill=blue!20!,thick]
({\r*cos(\t)},{\r*sin(\t)})circle (4.5mm) node{$\mathbf{Pt}$};
% Node Gorilla gorilla
\pgfmathparse{\myangles[2]} \let\t\pgfmathresult
\pgfmathsetcounter{ia}{3}
\fill[draw=blue,fill=blue!20!,thick]
({\r*cos(\t)},{\r*sin(\t)})circle (4.5mm) node{$\mathbf{Gg}$};
% Node Pongo abelii
\pgfmathparse{\myangles[3]} \let\t\pgfmathresult
\pgfmathsetcounter{ia}{4}
\fill[draw=blue,fill=blue!20!,thick]
({\r*cos(\t)},{\r*sin(\t)})circle (4.5mm) node{$\mathbf{Pa}$};
% Node Nomascus leucogenys
\pgfmathparse{\myangles[4]} \let\t\pgfmathresult
\pgfmathsetcounter{ia}{5}
\fill[draw=blue,fill=blue!20!,thick]
({\r*cos(\t)},{\r*sin(\t)})circle (4.5mm) node{$\mathbf{Nl}$};
% Node Macaca mulatta
\pgfmathparse{\myangles[5]} \let\t\pgfmathresult
\pgfmathsetcounter{ia}{6}
\fill[draw=blue,fill=blue!20!,thick]
({\r*cos(\t)},{\r*sin(\t)})circle (4.5mm) node{$\mathbf{Mm}$};
% Node Callithrix jacchus
\pgfmathparse{\myangles[6]} \let\t\pgfmathresult
\pgfmathsetcounter{ia}{7}
\fill[draw=blue,fill=blue!20!,thick]
({\r*cos(\t)},{\r*sin(\t)})circle (4.5mm) node{$\mathbf{Cj}$};
% Node Tarsius syrichta
\pgfmathparse{\myangles[7]} \let\t\pgfmathresult
\pgfmathsetcounter{ia}{8}
\fill[draw=blue,fill=blue!20!,thick]
({\r*cos(\t)},{\r*sin(\t)})circle (4.5mm) node{$\mathbf{Ts}$};
% Node Otolemur garnettii
\pgfmathparse{\myangles[8]} \let\t\pgfmathresult
\pgfmathsetcounter{ia}{9}
\fill[draw=blue,fill=blue!20!,thick]
({\r*cos(\t)},{\r*sin(\t)})circle (4.5mm) node{$\mathbf{Og}$};
% Node Microcebus murinus
\pgfmathparse{\myangles[9]} \let\t\pgfmathresult
\pgfmathsetcounter{ia}{10}
\fill[draw=blue,fill=blue!20!,thick]
({\r*cos(\t)},{\r*sin(\t)})circle (4.5mm) node{$\mathbf{Mu}$};
\end{tikzpicture}
\end{center}
\end{document}
答案1
您想要大致类似这样的东西吗?
我希望我已经更简洁地说明了构造:
\documentclass[tikz,border=10pt,multi]{standalone}
\begin{document}
% 1) Represent n points on a circle
% 2) Draw the complete graph on these points
% 3) Draw all the intersection points of any two of these segments
\def\r{8} % Determina o tamanho geral do grafo
\begin{tikzpicture}
\fill[fill=blue!10!green!10!,draw=blue,dotted,thick] (0,0) circle (\r);
\foreach \i/\m [count=\ino] in {36/Hs,72/Pi,108/Gg,144/Pa,180/Nl,216/Mm,252/Cj,288/Tc,324/Og,360/Mu}
{
\foreach \j [count=\jno] in {36,72,108,144,180,216,252,288,324,360}
{
\let\col\relax
\ifnum\ino<\jno
\ifnum\jno<8
\ifnum\ino=1\def\col{red}%
\else
\ifnum\ino<4\def\col{green}%
\else
\ifnum\ino<8
\ifnum\jno=6
\def\col{red}%
\else
\def\col{green}%
\ifnum\ino=6\ifnum\jno=7\def\col{red}\fi\fi
\fi
\fi
\fi
\fi
\else
\def\col{blue}%
\fi
\ifx\col\relax\else
\draw[\col,very thick] ({\r*cos(\i)},{\r*sin(\i)})--({\r*cos(\j)},{\r*sin(\j)}) node [pos=.2, fill=blue!10!green!10!, text=\col!75!black] {$\i$};
\fi
\fi
}
\fill[draw=blue,fill=blue!20!,thick] ({\r*cos(\i)},{\r*sin(\i)})circle (4.5mm) node{$\mathbf{\m}$};
}
\end{tikzpicture}
\end{document}