我怎样才能将一个方程式作为一个图形放在另一个图形的旁边?

我怎样才能将一个方程式作为一个图形放在另一个图形的旁边?

我想在一个图形旁边放一个等式,如下所示:

在此处输入图片描述

我当前的工作试验如下:

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{arrows.meta}

\begin{document}
\begin{figure}
    \centering
    \begin{tikzpicture}
    \centering
    \coordinate (a) at (0,0);
    \coordinate (b) at (4,0);
    \coordinate (c) at (2,2);
    \coordinate (d) at (2,-2);

    \draw (a) node[left]{$v_2$};
    \draw (b) node[right]{$v_4$};
    \draw (c) node[above]{$v_1$};
    \draw (d) node[below]{$v_3$};

    \draw [fill=black] (a) circle (2pt);
    \draw [fill=black] (b) circle (2pt);
    \draw [fill=black] (c) circle (2pt);
    \draw [fill=black] (d) circle (2pt);

    \draw [-{Latex[length=3mm]}] (a)--(b) ;
    \draw [-{Latex[length=3mm]}] (c)--(a) ;
    \draw [-{Latex[length=3mm]}] (b)--(c) ;
    \draw [-{Latex[length=3mm]}] (c)--(d) ;
    \end{tikzpicture} 
    $A=\left[\begin{array}{cccc}
    1 & 0 & 0 & 1   \\
    1 & 0 & 0 & 0   \\
    1 & 0 & 0 & 0   \\
    0 & 1 & 0 & 0
    \end{array}\right]$
    \caption{A directed graph with its adjacency matrix.}
\end{figure}

得出的结果为:

在此处输入图片描述

答案1

你可以使用subcaption包。为了全面控制对齐,你可以将所有内容放在一个包中tikzpicture

\documentclass{article}
\usepackage{subcaption}
\usepackage{tikz}

\usetikzlibrary{arrows.meta,positioning}

\begin{document}
\begin{figure}
    \centering
    \begin{tikzpicture}
    \centering
    \coordinate (a) at (0,0);
    \coordinate (b) at (4,0);
    \coordinate (c) at (2,2);
    \coordinate (d) at (2,-2);

    \draw (a) node[left]{$v_2$};
    \draw (b) node[right]{$v_4$};
    \draw (c) node[above]{$v_1$};
    \draw (d) node[below]{$v_3$};

    \draw [fill=black] (a) circle[radius=2pt];
    \draw [fill=black] (b) circle[radius=2pt];
    \draw [fill=black] (c) circle[radius=2pt];
    \draw [fill=black] (d) circle[radius=2pt];

    \draw [-{Latex[length=3mm]}] (a)--(b) ;
    \draw [-{Latex[length=3mm]}] (c)--(a) ;
    \draw [-{Latex[length=3mm]}] (b)--(c) ;
    \draw [-{Latex[length=3mm]}] (c)--(d) ;
    \path ([yshift=-1ex]current bounding box.south) node[text width=5em] (sca){\subcaption{ }};
    \path node[text width=5em,right=8em of sca] (scb){\subcaption{ }};
    \node at (scb|-a) {$\displaystyle A=\left[\begin{array}{cccc}
    1 & 0 & 0 & 1   \\
    1 & 0 & 0 & 0   \\
    1 & 0 & 0 & 0   \\
    0 & 1 & 0 & 0
    \end{array}\right]$};
    \end{tikzpicture} 
    \caption{A directed graph with its adjacency matrix.}
\end{figure}
\end{document}

在此处输入图片描述

您可以改变8emright=8em of sca达到您喜欢的任何距离。

或者只使用经典subfigure环境。

\documentclass{article}
\usepackage{subcaption}
\usepackage{tikz}

\usetikzlibrary{arrows.meta}

\begin{document}
\begin{figure}
    \centering
  \begin{subfigure}{0.45\linewidth}
    \centering
    \begin{tikzpicture}
    \centering
    \coordinate (a) at (0,0);
    \coordinate (b) at (4,0);
    \coordinate (c) at (2,2);
    \coordinate (d) at (2,-2);

    \draw (a) node[left]{$v_2$};
    \draw (b) node[right]{$v_4$};
    \draw (c) node[above]{$v_1$};
    \draw (d) node[below]{$v_3$};

    \draw [fill=black] (a) circle[radius=2pt];
    \draw [fill=black] (b) circle[radius=2pt];
    \draw [fill=black] (c) circle[radius=2pt];
    \draw [fill=black] (d) circle[radius=2pt];

    \draw [-{Latex[length=3mm]}] (a)--(b) ;
    \draw [-{Latex[length=3mm]}] (c)--(a) ;
    \draw [-{Latex[length=3mm]}] (b)--(c) ;
    \draw [-{Latex[length=3mm]}] (c)--(d) ;
    \end{tikzpicture} 
    \caption{}
    \end{subfigure}\quad
  \begin{subfigure}{0.45\linewidth}
    \centering
    $\displaystyle A=\left[\begin{array}{cccc}
    1 & 0 & 0 & 1   \\
    1 & 0 & 0 & 0   \\
    1 & 0 & 0 & 0   \\
    0 & 1 & 0 & 0
    \end{array}\right]$
    \caption{}
    \end{subfigure} 
    \caption{A directed graph with its adjacency matrix.}
\end{figure}
\end{document}

在此处输入图片描述

这里有一些题外的建议,可以使您的代码更短一些。

\documentclass{article}
\usepackage{subcaption}
\usepackage{tikz}

\usetikzlibrary{arrows.meta,positioning}

\begin{document}
\begin{figure}
    \centering
    \begin{tikzpicture}
    \centering
    \path foreach \X [count=\Y] in {a,b,c,d}
     {(90*\Y:2) node[circle,fill,inner sep=2pt,label={[]90*\Y:$v_\Y$}] (\X){}};

    \draw [-{Latex[length=3mm]}] (a)edge (b) (b) edge (d) 
    (d) edge (a)  (a) edge (c) ;
    \path ([yshift=-1ex]current bounding box.south) node[text width=5em] (sca){\subcaption{ }};
    \path node[text width=5em,base right=10em of sca] (scb){\subcaption{ }};
    \node at (scb|-b) {$\displaystyle A=\left[\begin{array}{cccc}
    1 & 0 & 0 & 1   \\
    1 & 0 & 0 & 0   \\
    1 & 0 & 0 & 0   \\
    0 & 1 & 0 & 0
    \end{array}\right]$};
    \end{tikzpicture} 
    \caption{A directed graph with its adjacency matrix.}
\end{figure}
\end{document}

在此处输入图片描述

相关内容