숫자에서 행렬 위와 아래의 다른 숫자로 곡선 화살표를 만드는 방법은 무엇입니까?

숫자에서 행렬 위와 아래의 다른 숫자로 곡선 화살표를 만드는 방법은 무엇입니까?

내 코드:

\documentclass[12pt]{article}
\usepackage{amsmath}

\begin{document}

\begin{align}
   \pi=\begin{pmatrix}
        1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
        1 & 7 & 5 & 2 & 4 & 6 & 3 & 8
    \end{pmatrix}
\end{align}

\end{document}

여기에 이미지 설명을 입력하세요

이런 화살표를 어떻게 만들 수 있나요? 위/아래에 텍스트가 있고 색상이 지정된 숫자에서 다른 숫자로.

답변1

을 사용하는 것이 좋습니다 tikzmark. 두 번 컴파일해야 한다는 점을 기억하세요.

관련 없음: 을(를) 사용하지 않는 것 같아서 align으로 변경했습니다 equation.

여기에 이미지 설명을 입력하세요

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

\begin{equation}
   \pi=\begin{pmatrix}
        1 & \tikzmarknode[blue!70!black]{a}{2} & 3 & \tikzmarknode[green!50!black]{b}{4} & 5 & 6 & 7 & 8\\
        1 & \tikzmarknode[blue]{c}{7} & 5 & \tikzmarknode[green]{d}{2} & 4 & 6 & 3 & 8
    \end{pmatrix}
\end{equation}

\begin{tikzpicture}[remember picture,overlay]
\draw[-latex]([yshift=.5ex]a.north) to[bend left]node[above]{\scriptsize$\textcolor{blue!70!black}{i}<\textcolor{green!50!black}{j}$} ([yshift=.5ex]b.north);
\draw[-latex]([yshift=-.5ex]d.south) to[bend left]node[below]{\scriptsize$\textcolor{blue}{\pi(i)}>\textcolor{green}{\pi(j)}$} ([yshift=-.5ex]c.south);
\end{tikzpicture}

\end{document}

답변2

나는 pstricks해결책을 제안합니다:

    \documentclass[12pt]{article}
    \usepackage{amsmath}
    \usepackage[svgnames]{xcolor}
    \usepackage{pst-node}

    \begin{document}

    \begin{equation}
       \pi=\begin{pmatrix}
            1 & \rnode[t]{a}{\color{SteelBlue}2} & 3 & \rnode[t]{b}{\color{DarkSeaGreen}4} & 5 & 6 & 7 & 8\\
            1 & \rnode[b]{c}{\color{DeepSkyBlue}7} & 5 & \rnode[b]{d}{\color{SpringGreen}2} & 4 & 6 & 3 & 8
        \end{pmatrix}
    \psset{arrowinset=0.1, arrows=->, nodesep=1pt, arcangle=30}
    \ncarc{a}{b}\naput[labelsep=1pt]{{\color{SteelBlue}i }< {\color{DarkSeaGreen}j}}
    \ncarc{d}{c}\naput[labelsep=1pt]{{\color{DeepSkyBlue}\pi(i )} > {\color{SpringGreen}\pi( j)}}
    \end{equation}

    \end{document} 

여기에 이미지 설명을 입력하세요

답변3

{pNiceMatrix}이를 통해 nicematrix매트릭스에 PGF/Tikz 노드가 생성되고 Tikz는 해당 노드를 사용하여 화살표를 그립니다.

\documentclass[12pt]{article}
\usepackage{nicematrix,tikz}

\begin{document}

\begin{equation}
\pi =
\begin{pNiceMatrix}
     1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
     1 & 7 & 5 & 2 & 4 & 6 & 3 & 8
\CodeAfter
     \begin{tikzpicture}
     \draw [->] (1-|2.5) to [bend left] node [above] {\scriptsize $i<j$} (1-|4.5);
     \draw [->] (3-|4.5) to [bend left] node[below] {\scriptsize$\pi(i)>\pi(j)$} (3-|2.5);
     \end{tikzpicture}
\end{pNiceMatrix}
\end{equation}

\end{document}

(PGF/Tikz 노드로 인해) 여러 컴파일이 필요합니다.

위 코드의 출력

관련 정보