如何将图形放置在矩阵附近?

如何将图形放置在矩阵附近?

我正在寻找一种方法将图形放在矩阵旁边,矩阵编号为(1),并用与矩阵对应的图形命名图形(图 1:矩阵对应图形(1))。

我的尝试:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\usepackage{enumitem}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\usepackage{rotating}
\usepackage{kbordermatrix}
\begin{document}
\[ CM' ={%
   \begin{tabular}[b]{cc}
       {\(\kbordermatrix
            { &  1  &   \textcolor{red}{3} &  4 \\
            1 &  1  & \textcolor{red}{x_{13}} & x_{12}x_{24} \\
            \textcolor{red}{3}& \textcolor{red}{0} &  \textcolor{red}{1} & \textcolor{red}{x_{34}} \\   
            4 & 0 & \textcolor{red}{0} &  1  
            }
        \)%
       }

   \end{tabular}}
\]

    \begin{tikzpicture}[
      mycircle/.style={
         circle,
         draw=black,
         fill=black,
         fill opacity = 0.99,
         text opacity=1,
         inner sep=0pt,
         minimum size=12pt,
         font=\small},
      myarrow/.style={-Stealth},
      node distance=0.6cm and 1.2cm
      ]
      \node[mycircle] (c1) {\textcolor{white}{1}};
      \node[mycircle,above right=of c1] (c2) {\textcolor{white}{2}};
      \node[mycircle,below right=of c1] (c4) {\textcolor{white}{3}};
      \node[mycircle,below right=of c2] (c3) {\textcolor{white}{4}};

    \foreach \i/\j/\txt/\p in {% start node/end node/text/position
     c2/c3/$e_{24}$/above,
      c1/c2/$e_{12}$/above,
       c1/c3/$e_{14}$/below,
        c1/c4/$e_{13}$/below,
         c4/c3/$e_{34}$/below}
       \draw [myarrow] (\i) -- node[sloped,font=\small,\p] {\txt} (\j);


     % draw this outside loop to get proper orientation of 10
     
    \end{tikzpicture}
  
\end{document}

图1:矩阵对应图(1)结果不理想: 在此处输入图片描述

我正在寻找这样的输出:

在此处输入图片描述

答案1

将这两部分嵌套在小页面中。

我会使用nicematrix功能而不是\kbordermatrix

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\usepackage{nicematrix}

\begin{document}

\begin{figure}[htp]

\begin{minipage}[t]{0.48\textwidth}
\vspace{-0.8\baselineskip}
\begin{equation}\label{a-matrix}
CM'=
\begin{bNiceMatrix}[
  first-row,code-for-first-row=\scriptstyle,
  first-col,code-for-first-col=\scriptstyle,
]
                   & 1                  & \mathcolor{red}{3}      & 4 \\
1                  & 1                  & \mathcolor{red}{x_{13}} & x_{12}x_{24} \\
\mathcolor{red}{3} & \mathcolor{red}{0} & \mathcolor{red}{1}      & \mathcolor{red}{x_{34}} \\   
4                  & 0                  & \mathcolor{red}{0}      & 1  
\end{bNiceMatrix}
\end{equation}
\end{minipage}\hfill
\begin{minipage}[t]{0.48\textwidth}
\centering
\vspace{0pt}
\begin{tikzpicture}[
  mycircle/.style={
    circle,
    draw=black,
    fill=black,
    fill opacity = 0.99,
    text opacity=1,
    inner sep=0pt,
    minimum size=12pt,
    font=\small
  },
  myarrow/.style={-Stealth},
  node distance=0.6cm and 1.2cm
]
  \node[mycircle] (c1) {\textcolor{white}{1}};
  \node[mycircle,above right=of c1] (c2) {\textcolor{white}{2}};
  \node[mycircle,below right=of c1] (c4) {\textcolor{white}{3}};
  \node[mycircle,below right=of c2] (c3) {\textcolor{white}{4}};
  \foreach \i/\j/\txt/\p in {% start node/end node/text/position
    c2/c3/$e_{24}$/above,
    c1/c2/$e_{12}$/above,
    c1/c3/$e_{14}$/below,
    c1/c4/$e_{13}$/below,
    c4/c3/$e_{34}$/below%
  }
  {\draw [myarrow] (\i) -- node[sloped,font=\small,\p] {\txt} (\j);}
  % draw this outside loop to get proper orientation of 10
\end{tikzpicture}

\caption{Corresponding graph of the matrix~\eqref{a-matrix}}
\end{minipage}

\end{figure}

\end{document}

在此处输入图片描述

我更喜欢中间的标题。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\usepackage{nicematrix}

\begin{document}

\begin{figure}[htp]

\begin{minipage}[t]{0.48\textwidth}
\vspace{-0.8\baselineskip}
\begin{equation}\label{a-matrix}
CM'=
\begin{bNiceMatrix}[
  first-row,code-for-first-row=\scriptstyle,
  first-col,code-for-first-col=\scriptstyle,
]
                   & 1                  & \mathcolor{red}{3}      & 4 \\
1                  & 1                  & \mathcolor{red}{x_{13}} & x_{12}x_{24} \\
\mathcolor{red}{3} & \mathcolor{red}{0} & \mathcolor{red}{1}      & \mathcolor{red}{x_{34}} \\   
4                  & 0                  & \mathcolor{red}{0}      & 1  
\end{bNiceMatrix}
\end{equation}
\end{minipage}\hfill
\begin{minipage}[t]{0.48\textwidth}
\centering
\vspace{0pt}
\begin{tikzpicture}[
  mycircle/.style={
    circle,
    draw=black,
    fill=black,
    fill opacity = 0.99,
    text opacity=1,
    inner sep=0pt,
    minimum size=12pt,
    font=\small
  },
  myarrow/.style={-Stealth},
  node distance=0.6cm and 1.2cm
]
  \node[mycircle] (c1) {\textcolor{white}{1}};
  \node[mycircle,above right=of c1] (c2) {\textcolor{white}{2}};
  \node[mycircle,below right=of c1] (c4) {\textcolor{white}{3}};
  \node[mycircle,below right=of c2] (c3) {\textcolor{white}{4}};
  \foreach \i/\j/\txt/\p in {% start node/end node/text/position
    c2/c3/$e_{24}$/above,
    c1/c2/$e_{12}$/above,
    c1/c3/$e_{14}$/below,
    c1/c4/$e_{13}$/below,
    c4/c3/$e_{34}$/below%
  }
  {\draw [myarrow] (\i) -- node[sloped,font=\small,\p] {\txt} (\j);}
  % draw this outside loop to get proper orientation of 10
\end{tikzpicture}
\end{minipage}

\caption{Matrix and corresponding graph}

\end{figure}

\end{document}

在此处输入图片描述

相关内容