tikzpicture 和子圖中並排的陣列不會對齊

tikzpicture 和子圖中並排的陣列不會對齊

我試圖並排對齊 a tikzpicture(網頁圖像)和數組(矩陣),但無論我做什麼,它們都無法正確對齊。兩個並排的數組和兩個tikzpicture並排的數組正確對齊(在同一行),但是當我將兩者混合時,我遇到了問題。我還沒有找到在子圖中處理這兩種環境的貼文。這是我的程式碼:

\documentclass[12ptm]{article}
\usepackage{amsmath, amsthm}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{arrows}
\usepackage{subcaption}

\begin{document}


\begin{figure}
\begin{subfigure}[t]{0.1\textwidth}
\centering
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=1.5cm,
        thick,main node/.style={circle,draw,font=\Large\bfseries}]

\tikzstyle{every node}=[draw,shape=circle];
\node[draw=none, shape=circle,scale=0.02cm, fill=none] (n1) {} ;
\node[draw,shape=circle,scale=0.02cm, main node](n2) [left of=n1] {$M$} ;
\node[draw,shape=circle,scale=0.02cm, main node] (n4) [above of=n1] {1} ;
\node[draw,shape=circle,scale=0.02cm, main node] (n3) [below of=n1] {3} ;
\node[draw,shape=circle,scale=0.02cm, main node] (n5) [right of=n1] {2} ;

\draw[<->] (n2) to[bend left=30] (n4);
\draw[<->] (n2) to[bend right=30] (n3);
\draw[->] (n4) to[bend left=30] (n5);
\draw[<->] (n3) to (n4);
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[t]{0.4\textwidth}
\centering
\[
\begin{array}{cccc}
\begin{array}{cccc} 
\\
&A &  &\;B\\
\end{array} 
\\
\begin{array}{cc}
 a \\
\\
  b\\

\end{array} 
\begin{array}{|cc|cc|}
\hline 
$6$&&$2$&\\
&$6$&&$7$\\ \hline
$7$&&$0$&\\
&$2$&&$0$\\ \hline

\end{array}
\end{array}
\]

\end{subfigure}
\end{figure}
\end{document}

正如您所看到的,您得到的是網絡圖,然後是網絡斜下方(右側)的另一條線上的數組。我希望他們肩並肩。

答案1

你有很多虛假內容$,而且subfigure標記沒有起到多大作用,所以我刪除了它。這裡我使用\raiseboxtikz 垂直居中。

在此輸入影像描述

\documentclass[12ptm]{article}
\usepackage{amsmath, amsthm}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{arrows}
\usepackage{subcaption}

\begin{document}


\begin{figure}

\raisebox{-.5\totalheight}{\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=1.5cm,
        thick,main node/.style={circle,draw,font=\Large\bfseries},
align=center]

\tikzstyle{every node}=[draw,shape=circle];
\node[draw=none, shape=circle,scale=0.02cm, fill=none] (n1) {} ;
\node[draw,shape=circle,scale=0.02cm, main node](n2) [left of=n1] {$M$} ;
\node[draw,shape=circle,scale=0.02cm, main node] (n4) [above of=n1] {1} ;
\node[draw,shape=circle,scale=0.02cm, main node] (n3) [below of=n1] {3} ;
\node[draw,shape=circle,scale=0.02cm, main node] (n5) [right of=n1] {2} ;

\draw[<->] (n2) to[bend left=30] (n4);
\draw[<->] (n2) to[bend right=30] (n3);
\draw[->] (n4) to[bend left=30] (n5);
\draw[<->] (n3) to (n4);
\end{tikzpicture}}
$\begin{array}{cccc}
\begin{array}{cccc} 
\\
&A &  &\;B\\
\end{array} 
\\
\begin{array}{cc}
 a \\
\\
  b\\
\end{array} 
\begin{array}{|cc|cc|}
\hline 
6&&2&\\
&6&&7\\ \hline
7&&0&\\
&2&&0\\ \hline

\end{array}
\end{array}
$
\end{figure}
\end{document}

答案2

您可以使用baselinestyle 來設定垂直對齊方式。在你的情況下

\begin{tikzpicture}[baseline={(n2)}, ...]

應該可以。

相關內容