图形与矩阵在同一高度

图形与矩阵在同一高度

我尝试将矩阵和图形并排放置,但我不知道该怎么做。我找到了一些方法,但没有用。(我是初学者。)谢谢。

\begin{tikzpicture}
\centering
[shorten >=1pt,->]
\tikzstyle{vertex}=[circle,fill=blue!25,minimum size=12pt,inner sep=2pt]
\node[vertex] (10) at (1,-1)  [shape=circle,draw=black] {1};
\node[vertex] (11) at (3,-1) [shape=circle,draw=black] {2};
\node[vertex] (12) at (2,-2) [shape=circle,draw=black] {3};
\node[vertex] (13) at (1,-3) [shape=circle,draw=black] {4};
\node[vertex] (14) at (3,-3) [shape=circle,draw=black] {5};
\draw (10) edge[-] (11);
\draw (10) edge[-] (12);
\draw (11) edge[-] (12);
\draw (13) edge[-] (14);
\draw (12) edge[-] (13);
\end{tikzpicture}
\vskip -2cm
\[
\begin{bmatrix}
\centering
0&1&1&0&0 \\
1&0&1&0&0 \\
1&1&0&1&0 \\
0&0&1&0&1 \\
0&0&0&1&0 \\
\end{bmatrix}
\]
%\end{minipage}
\begin{center} 
    Obr. 5
\end{center}
~\\

答案1

我当然会不是为此使用小页面。

\documentclass{article}
\usepackage{amsmath}%<-- added, 
\usepackage{tikz}
\begin{document}
\[\begin{tikzpicture}[shorten >=1pt,->,baseline=(12.base)]
\tikzset{vertex/.style={circle,fill=blue!25,minimum size=12pt,inner sep=2pt}}
\node[vertex] (10) at (1,-1)  [shape=circle,draw=black] {1};
\node[vertex] (11) at (3,-1) [shape=circle,draw=black] {2};
\node[vertex] (12) at (2,-2) [shape=circle,draw=black] {3};
\node[vertex] (13) at (1,-3) [shape=circle,draw=black] {4};
\node[vertex] (14) at (3,-3) [shape=circle,draw=black] {5};
\draw (10) edge[-] (11);
\draw (10) edge[-] (12);
\draw (11) edge[-] (12);
\draw (13) edge[-] (14);
\draw (12) edge[-] (13);
\end{tikzpicture}\quad
\begin{bmatrix}
0&1&1&0&0 \\
1&0&1&0&0 \\
1&1&0&1&0 \\
0&0&1&0&1 \\
0&0&0&1&0 \\
\end{bmatrix}
\]
\end{document}

如果Obr. 5表示类似的东西figure 5,则将该东西放在图形环境中。

在此处输入图片描述

答案2

一个简单的解决方案是使用minipage,在下面的例子中,我设置了两个,每个

of them using 30% of the width of the page

\usepackage{amsmath}

\begin{document}

\begin{minipage}{0.3\textwidth}

% graph
\begin{tikzpicture}
[shorten >=1pt,->]
\tikzstyle{vertex}=[circle,fill=blue!25,minimum size=12pt,inner sep=2pt]
\node[vertex] (10) at (1,-1)  [shape=circle,draw=black] {1};
\node[vertex] (11) at (3,-1) [shape=circle,draw=black] {2};
\node[vertex] (12) at (2,-2) [shape=circle,draw=black] {3};
\node[vertex] (13) at (1,-3) [shape=circle,draw=black] {4};
\node[vertex] (14) at (3,-3) [shape=circle,draw=black] {5};
\draw (10) edge[-] (11);
\draw (10) edge[-] (12);
\draw (11) edge[-] (12);
\draw (13) edge[-] (14);
\draw (12) edge[-] (13);
\end{tikzpicture}

\end{minipage}
\begin{minipage}{0.3\textwidth}

% matrix
\[
\begin{bmatrix}
  \centering
  0&1&1&0&0 \\
  1&0&1&0&0 \\
  1&1&0&1&0 \\
  0&0&1&0&1 \\
  0&0&0&1&0 \\
\end{bmatrix}
\]

\end{minipage}

\end{document}

在此处输入图片描述

答案3

另一种可能性是将矩阵tikzpicture放入 中,使其成为 的一部分\node

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage{tikz, amsmath}
\usetikzlibrary{positioning}
\begin{document}
\begin{center}
\begin{tikzpicture}[
  shorten >=1pt,
  vertex/.style={circle,draw=black,fill=blue!25,minimum size=12pt,inner sep=2pt}
]
\node[vertex] (10) at (1,-1)  {1};
\node[vertex] (11) at (3,-1)  {2};
\node[vertex] (12) at (2,-2)  {3};
\node[vertex] (13) at (1,-3)  {4};
\node[vertex] (14) at (3,-3)  {5};

% simpler way of drawing the connections
\draw (12) -- (10) -- (11) -- (12) -- (13) -- (14);


\node [
  label=below:Obr. 5, % adds Obr. 5 below the matrix
  right=of current bounding box.east, % position it relative to everything made so far in the diagram
] {
$\begin{bmatrix}
0&1&1&0&0 \\
1&0&1&0&0 \\
1&1&0&1&0 \\
0&0&1&0&1 \\
0&0&0&1&0 \\
\end{bmatrix}$};

\end{tikzpicture}
\end{center}
\end{document}

相关内容