如何绘制图中的自环和平行边(在投影仪中工作)

如何绘制图中的自环和平行边(在投影仪中工作)

我的问题是

我如何在图形中绘制自环和平行边?我正在使用 beamer 工作

在顶点 V_1 自环

V_2 和 V_3 之间的平行边

一个小问题如何将图形居中

平均能量损失

\documentclass[12pt,fleqn]{beamer}
\usetheme{AnnArbor}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\usetikzlibrary{decorations.markings}
\usecolortheme{beaver}
\usefonttheme{professionalfonts} % using non standard fonts for beamer
\usefonttheme{serif} % default family is serif
\addtobeamertemplate{frametitle}{}{\vspace{-0.4em}} % decrease
\begin{document}
\begin{frame}[t]
\begin{tikzpicture}
    \draw[line width=0.5pt] (0.0,3.0) -- (3.0,3.0);
    \draw[line width=0.5pt] (3.0,3.0) -- (3.0,0.0);
    \draw[line width=0.5pt] (3.0,0.0) -- (0.0,0.0);
    \draw[line width=0.5pt] (0.0,0.0) -- (0.0,3.0);
    \draw [fill=black] (0,3) circle (1.5pt);
    \draw[color=black,above] (0.0,3.10) node {$v_1$};
    \draw [fill=black] (3,3) circle (1.5pt);
    \draw[color=black,above] (3.0,3.10) node {$v_2$};
    \draw [fill=black] (3,0) circle (1.5pt);
    \draw[color=black,below] (3.0,-0.10) node {$v_3$};
    \draw [fill=black] (0,0) circle (1.5pt);
    \draw[color=black,below] (0.0,-0.10) node {$v_4$};
    \end{tikzpicture}
\end{frame}
\end{document}

答案1

在此处输入图片描述

通过使用automata库(类似于 @js bibra 在他的回答:+1),对于箭头,不是使用平行箭头而是使用弯曲的箭头,从序言中删除了由(, )arrows.meta加载的包,在演示中没有意义()或与最近的 LaTeX 默认功能()相关:beamerxcoloramsmathsetspace[utf]{inputenc}

\documentclass[12pt,fleqn]{beamer}
\usetheme{AnnArbor}
\usecolortheme{beaver}
\usefonttheme{professionalfonts} % using non standard fonts for beamer
\usefonttheme{serif} % default family is serif
\addtobeamertemplate{frametitle}{}{\vspace{-0.4em}} % decrease
%\usepackage{setspace}
%\usepackage{amsmath}
%\usepackage[utf8]{inputenc}
\usepackage{pgfplots}   % it load tikz and pgf too
\pgfplotsset{compat=1.17}

\usepackage{mathrsfs}
\usetikzlibrary{arrows.meta, automata,
                positioning,
                shadows}
\begin{document}
\begin{frame}
\begin{center}
    \begin{tikzpicture}[
      node distance = 22mm and 22mm,
state/.append style = {circle, draw=orange, fill=orange, 
                       minimum size=1.2em},
every edge/.style = {draw, -Stealth, semithick}
                        ] 
    \begin{scope}[nodes=state]
\node (n1)  {$v_1$};
\node (n2)  [right=of n1]   {$v_2$};
\node (n3)  [below=of n2]   {$v_3$};
\node (n4)  [left =of n3]   {$v_4$};
    \end{scope}
\path   (n3) edge  (n4)
        (n4) edge  (n1)
        (n1) edge [loop above,looseness=15]  (n1)
        (n1) edge  (n2)
        (n2) edge [bend left=15] (n3)
        (n3) edge [bend left=15] (n2)
        ;
    \end{tikzpicture}
\end{center}
\end{frame}
\end{document}

答案2

添加以下行

\path
(v1) edge [->,loop above] node {} (v1);

就在 \endtikzpicture 之前

在此处输入图片描述

编辑 - 可能感兴趣并且可以编辑/修改的替代解决方案

在此处输入图片描述

\documentclass[12pt,fleqn]{beamer} 
\usetheme{AnnArbor} 
\usepackage{setspace} 
\usepackage{amsmath} 
\usepackage[utf8]{inputenc} 
\usepackage{pgf,tikz,pgfplots} 
\pgfplotsset{compat=1.15} 
\usepackage{mathrsfs} 
%\usetikzlibrary{arrows} 
%\usetikzlibrary{decorations.markings, shapes,positioning,arrows.meta,bending,automata} 
\usetikzlibrary {arrows.meta,automata,positioning,shadows,calc}
\usecolortheme{beaver} 
\usefonttheme{professionalfonts} % using non standard fonts for beamer 
\usefonttheme{serif} % default family is serif 
\addtobeamertemplate{frametitle}{}{\vspace{-0.4em}} % decrease 
\newcommand\DoubleLine[7][4pt]{%
    \path(#2)--(#3)coordinate[at start](h1)coordinate[at end](h2);
    \draw[#4]($(h1)!#1!90:(h2)$)-- node [auto=left] {#5} ($(h2)!#1!-90:(h1)$); 
    \draw[#6]($(h1)!#1!-90:(h2)$)-- node [auto=right] {#7} ($(h2)!#1!90:(h1)$);
}
\begin{document} 
    \begin{frame}[t] 
        \begin{center}
        \begin{tikzpicture}[
            ->,
            >={Stealth[round]},
            shorten >=1pt,
            auto,
            node distance=2.8cm,
            on grid,
            semithick,
        every state/.style={
            fill=red,
            draw=none,
            circular drop shadow,
            text=white
        }
    ]
        \node[state] (A)              {$v_1$};
        \node[state] (B) [right=of A] {$v_2$};
        \node[state] (D) [below=of A] {$v_4$};
        \node[state] (C) [below=of B] {$v_3$};
        
        \path (A) edge  (B) 
        (C)edge(D)
        (D)edge(A)
        (A) edge [loop above]  (A)
        ;
        
        \DoubleLine{B}{C}{<-,very thick,black}{}{->,very thick,red}{}
        \end{tikzpicture}
    \end{center}
    \end{frame} 
\end{document}

双箭头定义取自此处——

标记图中的平行边

相关内容