在 LaTeX 中绘制无向图

在 LaTeX 中绘制无向图

我在问题中看到了这张图在 LaTeX 中绘制图表

在此处输入图片描述没有箭?

是否可以在 LaTeX 中绘制像这样的图形,但没有箭头?

编辑:我找到了下面这部分,但我不知道如何用简单的边缘替换箭头。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
                    thick,main node/.style={circle,draw,font=\sffamily\Large\bfseries}]

  \node[main node] (1) {1};
  \node[main node] (2) [below left of=1] {2};
  \node[main node] (3) [below right of=2] {3};
  \node[main node] (4) [below right of=1] {4};

  \path[every node/.style={font=\sffamily\small}]
    (1) edge node [left] {0.6} (4)
        edge [bend right] node[left] {0.3} (2)
        edge [loop above] node {0.1} (1)
    (2) edge node [right] {0.4} (1)
        edge node {0.3} (4)
        edge [loop left] node {0.4} (2)
        edge [bend right] node[left] {0.1} (3)
    (3) edge node [right] {0.8} (2)
        edge [bend right] node[right] {0.2} (4)
    (4) edge node [left] {0.2} (3)
        edge [loop right] node {0.6} (4)
        edge [bend right] node[right] {0.2} (1);
\end{tikzpicture}
\end{document}

答案1

您只需要取出箭头命令->并将循环样式设置为空:

在此处输入图片描述

所有功劳都归功于@Stefan Kottwitz,因为他创造了原始图片

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[auto, node distance=3cm, every loop/.style={},
                    thick,main node/.style={circle,draw,font=\sffamily\Large\bfseries}]

  \node[main node] (1) {1};
  \node[main node] (2) [below left of=1] {2};
  \node[main node] (3) [below right of=2] {3};
  \node[main node] (4) [below right of=1] {4};

  \path[every node/.style={font=\sffamily\small}]
    (1) edge node [left] {0.6} (4)
        edge [bend right] node[left] {0.3} (2)
        edge [loop above] node {0.1} (1)
    (2) edge node [right] {0.4} (1)
        edge node {0.3} (4)
        edge [loop left] node {0.4} (2)
        edge [bend right] node[left] {0.1} (3)
    (3) edge node [right] {0.8} (2)
        edge [bend right] node[right] {0.2} (4)
    (4) edge node [left] {0.2} (3)
        edge [loop right] node {0.6} (4)
        edge [bend right] node[right] {0.2} (1);
\end{tikzpicture}
\end{document}

答案2

也许您更喜欢tikz-cd使用非常简单的语法来处理此类事情。该线every arrow/.append style={dash}将每个箭头设置为一条没有箭头头的线。

% arara: pdflatex

\documentclass{article}
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}[%
    ,cells={nodes={circle,draw,font=\sffamily\Large\bfseries}}
    ,every arrow/.append style={dash,thick}
    ]
& 
1\arrow{dl}{0.2}\arrow[bend left]{dr}{0.2}\arrow[loop above, near end, "0.1"] 
& \\
%%%%%%%%%%%
2\arrow[loop left, near end, "0.4"]\arrow[bend left]{ur}{0.3}\arrow{dr}{0.8}
& & 
4\arrow[loop right, near start, "0.6"]\arrow{ul}{0.6}\arrow[bend left]{dl}{0.2}\arrow{ll}{0.3} \\
%%%%%%%%%%%
& 
3\arrow{ur}{0.2}\arrow[bend left]{ul}{0.1} 
& 
\end{tikzcd}
\end{document}

在此处输入图片描述

答案3

这是完成的pstricks。环是螺旋状体的一部分,因为它是我所知道的最接近原始图形的曲线。

\documentclass[pdf, svgnames, x11names]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pst-node, pst-plot, pst-poly}
\usepackage{rotating}
\newcommand\myloop{\psplot[yunit = 1.6, plotpoints=200,plotstyle=curve, polarplot, algebraic, arrows = c-c]{-0.785}{0.785}{cos(2*x)/cos(x)}}

\begin{document}

\psset{unit=3cm, linecolor=LightSteelBlue}
\degrees
\begin{pspicture}%
    \sffamily\large
    \pnode(0,0){O}
    \pscircle(O){1}
    \multido{\I=90+90,\i=1 + 1}{4}{%
        \pnode(1.15; \I){L\i}{\psset{origin=L\i, unit = 0.4}\rotatebox{\numexpr\I}{\myloop}}
        \cnodeput[framesep=0.15, fillstyle=solid, fillcolor=white,linecolor=IndianRed!60!, linewidth=1pt](1;\I){A\i}{\bfseries\i}
    }
    \psset{labelsep=1.05}
    \nput{45}{O}{0.2}\nput{135}{O}{0.4}
    \nput{-45}{O}{0.2}\nput{-135}{O}{0.1}
    \nput[labelsep=2.7em]{50}{L1}{0.1}
    \nput[labelsep=2.4em]{135}{L2}{0.4}
    \nput[labelsep=2.4em]{45}{L4}{0.6}
    \ncline{A1}{A2}\naput{0.2}
    \ncline{A2}{A3}\naput{0.8}
    \ncline{A3}{A4}\naput{0.2}
    \ncline{A4}{A1}\naput{0.6}
\end{pspicture}

\end{document}

在此处输入图片描述

相关内容