带标签的有向图

带标签的有向图

我试图绘制这张图表,但正如您所看到的,第三行和边缘上的两个标签(x_1和)相互干扰。我该如何修复它?另外,您有什么意见吗?我该如何在圆圈中用更大更粗的字体书写,并将图表插入页面的中心?x_301101010

\documentclass{article}

\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\usepackage{verbatim}

\begin{document}

\begin{tikzpicture}[-triangle 60,auto,node distance=3.7cm,ultra thick]
\tikzstyle{every state}=[circle,thick,draw=blue!75,fill=blue!20,minimum 
 size=20mm,text=black,minimum width=1cm]

\node[state] (A)    {$0000$};
\node[state] (B) [below of=A] {$0100$}; 
\node[state] (C) [left of=B]  {$0010$};  
\node[state] (D) [right of=B] {$1000$};

\node[state] (E) [below of=B] {$1100$}; 
\node[state] (F) [left of=E]  {$0101$};
\node[state] (G) [left of=F]  {$0011$};
\node[state] (H) [right of=E] {$0110$};
\node[state] (I) [right of=H] {$1010$};

\node[state] (J) [below of=F] {$0111$};

\node[state] (K) [below of=H] {$0111$};

\path (B) edge      node {$x_2$} (A)          
      (C) edge      node {$x_3$} (A)            
      (D) edge      node {$x_1$} (A)

      (E) edge      node {$x_1$} (B)
          edge      node {$x_2$} (D)                       
      (F) edge      node {$x_4$} (B)        
      (G) edge      node {$x_4$} (C)                
      (H) edge      node {$x_2$} (C)
          edge      node {$x_3$} (B)                  
      (I) edge      node {$x_1$} (C)
          edge      node {$x_3$} (D)

      (J) edge      node {$x_2$} (G)
          edge      node {$x_3$} (F)
          edge      node {$x_4$} (H)

      (K) edge      node {$x_1$} (G)
          edge      node {$x_4$} (I);
      \end{tikzpicture}

      \end{document}

答案1

您可以使用可选命令node

  • above,,, belowleft节点right位置
  • pos=xx 在 [0,1] 中:箭头上节点的相对位置
  • xshift=xyshift=x其中 x 是距离:在xy轴上平移

这是修改后的代码。我删除了一些未使用的导入,并将 documentclass 更改为standalone

\documentclass[margin=5mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}

\begin{document}

\begin{tikzpicture}[-triangle 60,auto,node distance=3.7cm,ultra thick]
    \tikzstyle{every state}=[circle,thick,draw=blue!75,fill=blue!20,minimum 
     size=20mm,text=black,minimum width=1cm]

    \node[state] (A)    {$0000$};
    \node[state] (B) [below of=A] {$0100$}; 
    \node[state] (C) [left of=B]  {$0010$};  
    \node[state] (D) [right of=B] {$1000$};

    \node[state] (E) [below of=B] {$1100$}; 
    \node[state] (F) [left of=E]  {$0101$};
    \node[state] (G) [left of=F]  {$0011$};
    \node[state] (H) [right of=E] {$0110$};
    \node[state] (I) [right of=H] {$1010$};

    \node[state] (J) [below of=F] {$0111$};

    \node[state] (K) [below of=H] {$0111$};

    \path (B) edge      node{$x_2$} (A)
          (C) edge      node{$x_3$} (A)
          (D) edge      node{$x_1$} (A)

          (E) edge      node[pos=0.3]{$x_1$} (B)
              edge      node[pos=0.7,above,xshift=-1mm]{$x_2$} (D)
          (F) edge      node{$x_4$} (B)
          (G) edge      node{$x_4$} (C)
          (H) edge      node[pos=0.1] {$x_2$} (C)
              edge      node[pos=0.7,above,xshift=1mm]{$x_3$} (B)
          (I) edge      node[pos=0.3,above]{$x_1$} (C)
              edge      node {$x_3$} (D)

          (J) edge      node{$x_2$} (G)
              edge      node{$x_3$} (F)
              edge      node{$x_4$} (H)

          (K) edge      node{$x_1$} (G)
              edge      node{$x_4$} (I);
\end{tikzpicture}

\end{document}

在此处输入图片描述

更改 tikz 自动机中的字体大小您可以使用:

\tikzset{every state/.append style={font=\Large}}

相关内容