一些评论

一些评论

我的尝试:

\begin{tikzpicture}
  \node (n1) at (0,0)  {};
  \node (n2) at (0,1)  {};
  \node (n3) at (1,0)  {};
  \node (n4) at (1,1)  {};
  \foreach \from/\to in {}
    \draw (\from) -- (\to);
  \foreach \from/\to in {n1/n3,n4/n2}
    \draw (\from) edge [->] (\to);
     \foreach \from/\to in {n2/n3,n4/n1}
    \draw (\from) edge [->>] (\to);
     \foreach \from/\to in {n1/n4}
    \draw (\from) edge [->>>] (\to);
  \foreach \from/\to in {}
    \draw (\from) edge [bend right] (\to);
\end{tikzpicture}

效果不太好——这是它的输出:

在此处输入图片描述

我怎样才能让箭头不位于尖端,而是位于边缘的中间?

答案1

两个选项:

  1. 使用 TikZ,使用带有装饰的样式:

    \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{decorations.markings}
    
    \def\Singlearrow{{\arrow[scale=1.5,xshift={0.5pt+2.25\pgflinewidth}]{>}}}
    \def\Doublearrow{{\arrow[scale=1.5,xshift=1.35pt +2.47\pgflinewidth]{>>}}}
    \def\Triplearrow{{\arrow[scale=1.5,xshift=1.75pt +2.47\pgflinewidth]{>>>}}}
    
    \begin{document}
    
    \begin{tikzpicture}[
    line cap=round,
    marr/.style={
      decoration={
        markings,
        mark=at position 0.5 with {#1}
        },
      postaction={decorate}
    }
    ] 
    \path
      coordinate (n1) at (0,0)
      coordinate (n2) at (0,2)
      coordinate (n3) at (2,0)
      coordinate (n4) at (2,2);
    \foreach \from/\to in {n1/n3,n4/n2}
        \draw[marr=\Singlearrow] (\from) -- (\to);
    \foreach \from/\to in {n1/n2,n3/n4}
        \draw[marr=\Doublearrow] (\from) -- (\to);
    \draw[marr=\Triplearrow] (n1) -- (n4);
    \draw[->]
      (0.35,1.3) arc (220:-40:8pt);
    \draw[->]
      (1.7,0.35) arc (-40:220:8pt);
    \end{tikzpicture}
    
    \end{document}
    

    在此处输入图片描述

    一些评论

    • 我使用了\coordinates 来代替原来的\nodes,这样线条就会相接。
    • 更改line cap为可round在顶点产生更好的结果。
    • 默认情况下,装饰会将箭头尖端(而不是箭头中心)放置在指定位置。这会产生丑陋的结果(对于组合箭头尤其明显)。针对此问题,有一些帖子,例如按中心定位箭头装饰,而不是按尖端定位箭头装饰,但不幸的是,那里的自动答案已经过时了。我改用了类似于answer by Kpym
  2. 使用tikz-cd

    \documentclass{article}
    \usepackage{tikz-cd}
    \usetikzlibrary{decorations.markings,arrows.meta}
    \usetikzlibrary{backgrounds}
    
    \begin{document}
    
    \begin{tikzpicture}
    \end{tikzpicture}
    
    \begin{tikzcd}[
    sep=2cm,
    cells={shape=coordinate},
    ]
      \ar[draw=none,r, "{\tikz\node[rotate=90,inner sep=0pt] {\tikz\draw[->](0,0) ;};  }" description]
      \ar[dash,r] 
    & 
    {} 
    \\
      \ar[draw=none,r, "{\tikz\node[rotate=270,inner sep=0pt] {\tikz\draw[->](0,0) ;};  }" description] 
      \ar[draw=none,u, "{\tikz\node[inner sep=0pt] {\tikz\draw[->>](0,0) ;};  }" description] 
      \ar[draw=none,ur, "{\tikz\node[rotate=-45,inner sep=0pt] {\tikz\draw[->>>](0,0) ;};  }" description] 
      \ar[dash,r] 
      \ar[dash,u] 
      \ar[dash,ur] 
    & 
    {}
      \ar[draw=none,u, "{\tikz\node[inner sep=0pt] {\tikz\draw[->>](0,0) ;};  }" description]
        \ar[dash,u]  
    \end{tikzcd}
    
    \end{document}
    

在此处输入图片描述

相关内容