在 Tikz 中,如何在 foreach 箭头顶部写方程式?

在 Tikz 中,如何在 foreach 箭头顶部写方程式?

能否指点一下如何在以下两幅图的箭头上添加一些描述?例如,

在第一个图中,

  • 我们可以添加:Arrow $\vec{21}$在箭头顶部(最好是(1)平行线或 (2)水平的如果可能的话,但如果对你来说太难的话,那就没有必要)从第 2 项移到第 1 项?

  • 类似地,我们可以添加:在从项目到项目的Arrow $\vec{i j}$每个箭头顶部?这里,和。iji=2j=1,3,4,5,6

在第二张图中,

  • 我们可以尝试在每个箭头上添加一些希腊字母、、、$\alpha$等等$\beta$吗?$\gamma$

我们能否进行上述调整以获得(1)的选择平行线箭头方向或 (2)水平的文档中是否有该命令?如果是,您能否建议每种情况的命令行?

在此处输入图片描述

这是我的最低限度工作说明 MWE:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{matrix}


\usetikzlibrary{shapes,arrows,calc}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{amsmath, amsthm, amssymb,slashed,mathtools,tabu}


\begin{document}


\newline

\;\;\;\;
\begin{tikzpicture}\kern-5mm[>=stealth,->,shorten >=2pt,looseness=.5,auto]
      \matrix (M)[matrix of math nodes,row sep=1cm,column sep=8mm]{
1 & 2 & 3\\
   4    &  5 & 6 \\
   };
       \foreach \a/\b in {1-2/2-1,1-2/1-1,1-2/2-2,1-2/2-3, 1-2/1-3}
{\draw[thick,->](M-\a)--(M-\b);}
    \end{tikzpicture}



\newline

\begin{tikzpicture}[node distance=2cm, auto]

\def\mypoints{%
  (1, 0), (2, 0), (3, 0), (4, 0), (5, 0),
  (5, 1), (4, 1), (3, 1), (2, 1), (1, 1)%
};
\path
  \foreach \x [count=\xi] in \mypoints {
    \x node[circle, fill, inner sep=sqrt(2)*0.025cm] (node\xi) {}
  }
  \foreach \x [count=\xi, remember=\xi-1 as \xiprev] in \mypoints {
    \ifnum\xi>1 %
      (node\xiprev) edge[-latex', black!50!white] (node\xi)
    \fi
  }
;
\end{tikzpicture}



\end{document}

第二张图来自https://tex.stackexchange.com/a/385800/41144

答案1

TikZ 也许可以做到!

在等待 TikZ 答案时,我得到了如下的 Asymptote 答案:

仅用于比较目的!

usepackage("esvect");
picture pic1,pic2;

size(pic1,8cm);
pair[] A={(0,0),(-1,0),(1,0),sqrt(2)*dir(-135),(0,-1),sqrt(2)*dir(-45)};
int[] B={2,1,3,4,5,6};
margin m=Margin(2.5,2.5);
for (int i=0; i< A.length; ++i){  label(pic1,"$"+ (string) B[i] + "$",A[i],(0,0)); }
draw(pic1,Label("$\vv{21}$"),A[0]--A[1],Arrow,m);
draw(pic1,Label("$\vv{23}$",LeftSide),A[0]--A[2],Arrow,m);
draw(pic1,rotate(degrees(dir(A[0]-A[3])))*Label("$\vv{24}$"),A[0]--A[3],Arrow,m);
draw(pic1,rotate(degrees(dir(A[0]-A[4])))*Label("$\vv{25}$"),A[0]--A[4],Arrow,m);
draw(pic1,rotate(degrees(dir(A[5]-A[0])))*Label("$\vv{26}$",LeftSide),A[0]--A[5],Arrow,m);

size(pic2,10cm);
pair[] A={(0,0),(1,0),(2,0),(3,0),(4,0),(4,1),(3,1),(2,1),(1,1),(0,1)};
string[] alphabet={"$\alpha$", "$\beta$", "$\gamma$"};
alphabet.cyclic=true;
dot(pic2,A);
for (int i=0; i< A.length-1; ++i){
  draw(pic2,scale(0.8)*alphabet[i],A[i]--A[i+1],Arrow,Margin(1,1));
}
picture pic;
add(pic,pic1.fit(),(0,0),N);
add(pic,pic2.fit(),(0,0),S);
add(pic);
shipout(bbox(pic,2mm,invisible));

在此处输入图片描述

答案2

使用 TikZ:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                chains, 
                matrix,
                positioning,
                quotes}
\usepackage{esvect}

\begin{document}
    \begin{tikzpicture}[
       every edge/.style = {draw, thick, -Straight Barb},
every edge quotes/.style = {auto, inner sep=2pt, sloped}
                        ] 
\matrix (m) [matrix of math nodes,
             nodes={circle, minimum size=1.1em, inner sep=1pt, anchor=center},
             column sep=2cm,
             row sep=2cm]
{
1 & 2 & 3     \\
4 & 5 & 6     \\
};
\foreach \i/\j/\k in {1/1/1, 4/2/1, 5/2/2, 6/2/3, 3/1/3}
{
\draw   (m-1-2) edge ["$\vv{21}$"] (m-\j-\k);
}
    \end{tikzpicture}
       

    \begin{tikzpicture}[
           node distance = 2cm and 2 cm,
             start chain = going right,
              dot/.style = {circle, fill, inner sep=2pt},
       every edge/.style = {draw=gray, thick, -Straight Barb},
every edge quotes/.style = {auto, inner sep=2pt, sloped}
                        ]

  \foreach \i in {1,...,5}
{
    \node (n1\i) [dot, on chain] {};
    \node (n2\i) [dot, above=of n1\i] {};
}
  \foreach \x [count=\xi,count=\xj from 2] in {\alpha, \beta, \gamma, \alpha}
\ifnum\xj<6     \draw (n1\xi) edge["$\x$"] (n1\xj);   \fi
  \foreach \x [count=\xi,count=\xj from 2] in {\gamma, \beta, \alpha,  \gamma}
\ifnum\xj<6     \draw (n2\xj) edge["$\x$"] (n2\xi);   \fi
\draw (n15) edge["$\beta$"] (n25);
 
    \end{tikzpicture}
\end{document}

在此处输入图片描述 在此处输入图片描述

相关内容