如何在下面的乳胶图中给出箭头符号?

如何在下面的乳胶图中给出箭头符号?
\documentclass[a4paper,12pt]{article}
\usepackage{amsfonts}
%\usepackage{amsbsy}
\usepackage{amssymb}
\usepackage{amsmath}
%\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{graphics}


\usepackage{tikz}


\usepackage{amsthm}
\usepackage{hyperref}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}

\begin{figure}[hbt!]
\begin{center}

  \begin{tikzpicture}[
       thick,
       acteur/.style={
         circle,
         fill=black,
         thick,
         inner sep=2pt,
         minimum size=0.2cm
       }
     ] 



           \node (a1) at (0,0) [acteur,label=below:6]{};
           \node (a2) at (1.5,0)[acteur,label=below:1]{}; 

           \node (a3) at (1.5,1.5) [acteur,label=above:4]{};
           \node (a4) at (0,1.5) [acteur,label=above:5]{}; 
           \node (a5) at (3,0) [acteur,label=below:2]{}; 
           \node (a6) at (4.5,0) [acteur,label=below:7]{};
            \node (a7) at (3,1.5) [acteur,label=above:3]{};
          \node (a8) at (4.5,1.5) [acteur,label=above:8]{};
           \draw[red] (a1) -- (a2); 
           \draw [red]  (a2) -- (a3); 
           \draw[red] (a3) -- (a4);
           \draw[green]  (a5) -- (a2);

           \draw [red](a6) -- (a5);
           \draw[red] (a5) -- (a7);
            \draw [red](a8) -- (a7);
             \draw [red](a3) -- (a7);

           \draw (2.3, -.7) node {$U$};


\end{tikzpicture} 

\end{center}


\end{figure}


\end{document}

这里我想要一个从 1 到 2 的定向箭头,箭头符号位于绿色边缘的中间。请给点建议。

答案1

使用tikz-euclide 包

\documentclass[a4paper,12pt]{article}
\usepackage{amsfonts}
%\usepackage{amsbsy}
\usepackage{amssymb}
\usepackage{amsmath}
%\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{graphics}


\usepackage{tikz}
\usepackage{tkz-euclide}% Newly added package


\usepackage{amsthm}
\usepackage{hyperref}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}

\begin{figure}[hbt!]
\begin{center}

  \begin{tikzpicture}[
       thick,
       acteur/.style={
         circle,
         fill=black,
         thick,
         inner sep=2pt,
         minimum size=0.2cm
       },
       decoration={markings,
       mark=at position 0.5 with {\arrow[scale=2]{>}};} % decoration setup
     ] 



           \node (a1) at (0,0) [acteur,label=below:6]{};
           \node (a2) at (1.5,0)[acteur,label=below:1]{}; 

           \node (a3) at (1.5,1.5) [acteur,label=above:4]{};
           \node (a4) at (0,1.5) [acteur,label=above:5]{}; 
           \node (a5) at (3,0) [acteur,label=below:2]{}; 
           \node (a6) at (4.5,0) [acteur,label=below:7]{};
            \node (a7) at (3,1.5) [acteur,label=above:3]{};
          \node (a8) at (4.5,1.5) [acteur,label=above:8]{};
           \draw[red] (a1) -- (a2); 
           \draw [red]  (a2) -- (a3); 
           \draw[red] (a3) -- (a4);
        \draw[postaction={decorate},green]  (a5) -- (a2); % I just added the decoration option here

           \draw [red](a6) -- (a5);
           \draw[red] (a5) -- (a7);
            \draw [red](a8) -- (a7);
             \draw [red](a3) -- (a7);

%          \tkzDrawSegment[postaction={decorate},green](a2,a5)
% This command gives the same result

           \draw (2.3, -.7) node {$U$};


\end{tikzpicture} 

\end{center}


\end{figure}


\end{document}

在此处输入图片描述

现在你可以玩它了。

答案2

您可以重复使用薛定谔猫的弯曲箭头风格。此样式即使在弯曲路径上也能产生良好的效果,并接受可选参数,默认为 0.5(=中间),以指示箭头应位于其所在路径的哪个位置。使用此样式,可以简单地绘制箭头:

\draw[attach arrow] (a2) -- (a5);

attach arrow=0.5如果您想明确说明从 a2 到 a5 的边缘上的箭头的位置,可以进行指定。

我还使用了scope环境来减少示例中的冗余,并且

\draw[green!80!black, attach arrow] (a2) -- (a5)
  node[pos=0.5, below, black] {$U$};

自动放置位于 a2 到 a5 边缘中间下方(此处没有坐标的硬编码)。如果要将其放置得稍微低一些,可以添加\usetikzlibrary{positioning}到前言中,并将上述两行替换为,例如:

\draw[green!80!black, attach arrow] (a2) -- (a5) coordinate[pos=0.5] (mid);
\node[below=0.3cm of mid] {$U$};

另外,pos=0.5可以用 代替midway,但这不是很有用。完整代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, bending, decorations.markings}

% https://tex.stackexchange.com/a/524935/73317 (Schrödinger's cat)
\tikzset{
    attach arrow/.style={
    decoration={
        markings,
         mark=at position 0 with {\pgfextra{%
         \pgfmathsetmacro{\tmpArrowTime}{\pgfkeysvalueof{/tikz/arc arrow/length}/(\pgfdecoratedpathlength)}%
         \xdef\tmpArrowTime{\tmpArrowTime}}},
        mark=at position {#1-3*\tmpArrowTime} with {\coordinate(@1);},
        mark=at position {#1-2*\tmpArrowTime} with {\coordinate(@2);},
        mark=at position {#1-1*\tmpArrowTime} with {\coordinate(@3);},
        mark=at position {#1+\tmpArrowTime/2} with {\coordinate(@4);
        \draw[-{Stealth[length=\pgfkeysvalueof{/tikz/arc arrow/length},bend]}]
          plot[smooth] coordinates {(@1) (@2) (@3) (@4)};},
        },
     postaction=decorate,
     },
     % Default arrow location: in the middle of the path
     attach arrow/.default=0.5,
     arc arrow/length/.initial=2mm,
}

\begin{document}

\begin{tikzpicture}[
  thick,
  acteur/.style={
    circle,
    thick,
    fill=black,
    inner sep=2pt,
    minimum size=0.2cm
  }]

  \begin{scope}[nodes={acteur}]
    \node (a1) at (0,0)     [label=below:6] {};
    \node (a2) at (1.5,0)   [label=below:1] {};

    \node (a3) at (1.5,1.5) [label=above:4] {};
    \node (a4) at (0,1.5)   [label=above:5] {};
    \node (a5) at (3,0)     [label=below:2] {};
    \node (a6) at (4.5,0)   [label=below:7] {};
    \node (a7) at (3,1.5)   [label=above:3] {};
    \node (a8) at (4.5,1.5) [label=above:8] {};
  \end{scope}

  \begin{scope}[color=red]
    \draw (a1) -- (a2);
    \draw (a2) -- (a3);
    \draw (a3) -- (a4);

    \draw (a6) -- (a5);
    \draw (a5) -- (a7);
    \draw (a8) -- (a7);
    \draw (a3) -- (a7);
  \end{scope}

  \draw[green!80!black, attach arrow] (a2) -- (a5)
    node[pos=0.5, below, black] {$U$};
\end{tikzpicture}

\end{document}

在此处输入图片描述

基于\usetikzlibrary{positioning}和的替代方案:

\draw[green!80!black, attach arrow] (a2) -- (a5) coordinate[pos=0.5] (mid);
\node[below=0.3cm of mid] {$U$};

你会得到:

在此处输入图片描述

注意:还有其他方法可以绘制图形(例如 TiZ 矩阵和\usetikzlibrary{graphs}),但目前的问题是关于箭头的,最好一次解决一个问题,特别是在开始时。:-)

相关内容