改变标签的大小?

改变标签的大小?

在下面的代码中,我想让所有顶点和边标签具有相同的大小。

    \documentclass
    \begin{figure}[H]
    \begin{center}\setlength\extrarowheight{7pt}
      \begin{minipage}[b]{0.4\textwidth}
    \begin{tikzpicture}[x=0.8cm, y=0.9cm]
      %\begin{tikzpicture}
            \tikzset{vnode/.style={draw,thick,circle,minimum width=0.6cm,inner sep=0pt}};
            \def\dist{2.8}
            
            % Nodes
            
            \begin{scope}[every node/.style={vnode}]
                \node (17) {$17$};
                \foreach \i [count=\ang from 2] in {0,11,7,10,13,1}
                    {
                    \path (17) --++ (60*\ang:\dist) node (\i) {$\large \i$};
                    }
                    
                \foreach \i [count=\ang] in {5,19}
                    {
                    \path (0) --++ (30+60*\ang:\dist) node (\i) {$\i$};
                    }
                    
                \foreach \i [count=\ang from 0] in {3,16}
                    {
                    \path (1) --++ (30+60*\ang:\dist) node (\i) {$\i$};
                    }
                    
                \foreach \i [count=\ang from 0] in {6,15}
                    {
                    \path (7) --++ (210+60*\ang:\dist) node (\i) {$\i$};
                    }
            \end{scope}
            
            % Paths
                    \path%[every node/.style={sloped}]
                (17)    edge [thick] node[left] {$17$} (0)
                        edge [thick] node[above] {$6$} (11)
                        edge [thick] node[left] {$10$} (7)
                        edge [thick] node[right] {$7$} (10)
                        edge [thick] node[above] {$4$} (13)
                        edge [thick] node[above left] {$16$} (1)
                (0)    edge [thick] node[right] {$5$} (5)
                        edge [thick] node[below left] {$19$} (19)
                (19)    edge [thick] node[above left] {$14$} (5)
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                            (1)    edge [thick] node[above left] {$15$} (16)
                (1)    edge [thick] node[above left] {$2$} (3)
                            (16)    edge [thick] node[above right] {$13$} (3)
                            (7)    edge [thick] node[above left] {$1$} (6)
                            (6)    edge [thick] node[below left] {$9$} (15)
                            (7)    edge [thick] node[above left] {$8$} (15)
                            
                            (1)    edge [thick] node[left] {$12$} (13)
                            (7)    edge [thick] node[above] {$3$} (10)
                            (0)    edge [thick] node[above left] {$11$} (11)
            ;
    
    
        \end{tikzpicture}
              \end{minipage}
    \quad
    \quad
            %\end{center}
        %   \end{figure}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %\begin{figure}[H]
    %\begin{center}\setlength\extrarowheight{7pt}
      \begin{minipage}[b]{0.4\textwidth}
        \begin{tikzpicture}[x=0.7cm, y=1cm]
        %First place the vertices. Note the names correspond to the labels.
        \node[shape=circle,draw=black, scale=0.7,thick] (v0) at (0,0) {$0$}; 
    \node[shape=circle,draw=black, scale=0.7,thick] (v7) at (0:3) {$7$}; 
        \node[shape=circle,draw=black, scale=0.7,thick] (v8) at (42:3) {$8$};
            \node[shape=circle,draw=black, scale=0.7,thick] (v9) at (105:2.8) {$9$} ;
        \node[shape=circle,draw=black, scale=0.7,thick] (v11) at (155:3) {$11$} ;
    \node[shape=circle,draw=black, scale=0.7,thick] (v6) at (205:3) {$6$} ;
    \node[shape=circle,draw=black, scale=0.7,thick] (v2) at (227:4) {$2$} ;
        \node[shape=circle,draw=black, scale=0.7,thick] (v5) at (262:2) {$5$} ;
        %Next do the edges and labels. Note the label positions; you can make them more precise by using angles instead of 8 directions right, above, etc.
        \foreach \x/\y/\lab in {0/8/left,0/7/below,0/9/right,0/11/below left,0/5/right,0/6/above left,5/2/below right,6/2/left,9/11/above left,7/8/above right}
        %   \draw[thick] (v\x)--node[above, \lab] {\pgfmathparse{int(abs(\x-\y))}{{\scriptsize \pgfmathresult}}} (v\y);
        \draw[thick] (v\x)--node[above, \lab] {\pgfmathparse{int(abs(\x-\y))}{{ \pgfmathresult}}} (v\y);
        %\draw[thick] (v\x)--node[above, \lab, text=blue] {\pgfmathparse{int(abs(\x-\y))}{\pgfmathresult}} (v\y);  
        \end{tikzpicture}
    %\caption{{Gracefully labelled dutch windmill.}\label{bb}
              \end{minipage}
            \caption{aaaa}\label{cc}
            \end{center}
            \end{figure}
\end{document}

答案1

看看以下解决方案是否适合您:

\documentclass{article}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{quotes}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\begin{figure}[ht]
    \tikzset{
vnode/.style = {circle, draw,thick,minimum width=6mm, 
                inner sep=0pt, outer sep=0pt},
every edge quotes/.style = {font=\footnotesize, auto=right},
every edge/.style = {draw, thick}
            }
    \def\dist{2.2}

\begin{minipage}[b]{0.45\textwidth}\raggedright
    \begin{tikzpicture}%[x=0.8cm, y=0.9cm]
% Nodes
    \begin{scope}[nodes={vnode}]
    \node (17) {$17$};
\foreach \i [count=\ang from 2] in {0,11,7,10,13,1}{
    \path (17) --++ (60*\ang:\dist) node (\i) {$\large \i$};}
\foreach \i [count=\ang] in {5,19}{
    \path (0) --++ (30+60*\ang:\dist) node (\i) {$\i$};}
\foreach \i [count=\ang from 0] in {3,16}{
    \path (1) --++ (30+60*\ang:\dist) node (\i) {$\i$};}
\foreach \i [count=\ang from 0] in {6,15}{
    \path (7) --++ (210+60*\ang:\dist) node (\i) {$\i$};}
    \end{scope}
% Paths
\path   (17)    edge    ["17"]      (0)
                edge    ["6" ']     (11)
                edge    ["10"]      (7)
                edge    ["7" ']     (10)
                edge    ["4"]     (13)
                edge    ["16" ']    (1)
        (0)     edge    ["5"]       (5)
                edge    ["19" ']    (19)
        (19)    edge    ["14" ']    (5)
 (1)     edge    ["15" ']    (16)
                edge    ["2"]       (3)
                edge    ["12" ']    (13)
        (16)    edge    ["13"']     (3)
        (7)     edge    ["1"]       (6)
        (6)     edge    ["9"]       (15)
        (7)     edge    ["8"']      (15)

        (7)     edge    ["3"]       (10)
        (0)     edge    ["11"]      (11)
            ;
    \end{tikzpicture}
          \end{minipage}
\hfill
\begin{minipage}[b]{0.45\textwidth}\raggedleft
    \begin{tikzpicture}
% nodes
   \begin{scope}[nodes={vnode}]
\node (v0)  at (0,0)        {$0$};
\node (v7)  at (0:3)        {$7$};
\node (v8)  at (42:3)       {$8$};
\node (v9)  at (105:2.8)    {$9$};
\node (v11) at (155:3)      {$11$};
\node (v6)  at (205:3)      {$6$};
\node (v2)  at (227:4)      {$2$};
\node (v5)  at (262:2)      {$5$};
    \end{scope}
% Paths
\foreach \x/\y in {8/0, 0/7, 0/9, 11/0, 5/0, 0/6, 2/5, 6/2, 9/11, 7/8}
{
\draw[thick] (v\x) edge ["\pgfmathparse{int(abs(\x-\y))}\pgfmathresult"]  (v\y);
}
    \end{tikzpicture}
\end{minipage}
    \caption{aaaa}\label{cc}
        \end{figure}
\end{document}

在此处输入图片描述

(红线表示文本边框)

相关内容