如何将 Tikzpicture 与矩阵对齐?

如何将 Tikzpicture 与矩阵对齐?

下面的代码

\captionsetup[subfigure]
\usepackage{tkz-tab}

...

\begin{figure}[h!]
\centering
\subfigure[sub-title 1]
{\label{}
\begin{tikzpicture}[black,ultra thick, scale=0.5]
\draw (1,0) -- (5,0) -- (5,4) -- (1,4) -- (1,5) -- (0,5) -- (0,1) -- (1,1) -- cycle; 
\draw (3,1) -- (4,1) -- (4,3) -- (3,3) -- cycle;
\filldraw[fill=blue!20!white, draw=black] (1,0) -- (5,0) -- (5,4) -- (1,4) -- (1,5) -- (0,5) -- (0,1) -- (1,1) -- cycle; 
\filldraw[fill=white!100!white, draw=black] (3,1) -- (4,1) -- (4,3) -- (3,3) -- cycle;
\draw[step=1cm,gray,thin] (0,0) grid (5,5); 
\end{tikzpicture}
}
\qquad\qquad
$
\begin{matrix}
{\longrightarrow} \\
\quad \\
\quad \\
\quad \\
\quad \\
\end{matrix}
$
\qquad\qquad
\subfigure[sub-title 2]
{\label{}
$
\setlength\arraycolsep{4pt}
\begin{pmatrix}
1 & 0 & 0 & 0 & 0\\
1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 0 & 1\\
1 & 1 & 1 & 0 & 1\\
0 & 1 & 1 & 1 & 1
\end{pmatrix} 
$
}
\caption{Main title}
\end{figure}

得到图片 在此处输入图片描述

我怎样才能将两个子图对齐在同一水平线上?我不想切换到使用不同的包,因为我已经创建了许多图形。谢谢。

答案1

试试这个代码:

\documentclass[10pt,a4paper]{article}

\usepackage{amsmath}

\usepackage{tikz}

\begin{document}
    
    \begin{figure}[h!]
        \centering
        \begin{tabular}{p{0.3\textwidth}cp{0.3\textwidth}}
            \vspace*{-1.5cm}
            \begin{tikzpicture}[black,ultra thick, scale=0.5]
                \draw (1,0) -- (5,0) -- (5,4) -- (1,4) -- (1,5) -- (0,5) -- (0,1) -- (1,1) -- cycle; 
                \draw (3,1) -- (4,1) -- (4,3) -- (3,3) -- cycle;
                \filldraw[fill=blue!20!white, draw=black] (1,0) -- (5,0) -- (5,4) -- (1,4) -- (1,5) -- (0,5) -- (0,1) -- (1,1) -- cycle; 
                \filldraw[fill=white!100!white, draw=black] (3,1) -- (4,1) -- (4,3) -- (3,3) -- cycle;
                \draw[step=1cm,gray,thin] (0,0) grid (5,5); 
        \end{tikzpicture}
    & $\longrightarrow$&
    
            \setlength\arraycolsep{4pt}
        $   \begin{pmatrix}
                1 & 0 & 0 & 0 & 0\\
                1 & 1 & 1 & 1 & 1\\
                1 & 1 & 1 & 0 & 1\\
                1 & 1 & 1 & 0 & 1\\
                0 & 1 & 1 & 1 & 1
            \end{pmatrix} $
            \\
    \center{(a)}
    &&
    \center{(b)}
\end{tabular}
        \caption{Main title}
    \end{figure}
\end{document}

输出:

在此处输入图片描述

答案2

使用(如版本 1.3subfloat中所定义)和:subcaption\raisebox

\documentclass[10pt,a4paper]{article}
\usepackage{amsmath}
\usepackage[skip=1ex, 
            font=small, labelfont=bf,
            singlelinecheck=false
            ]{caption, subcaption}
\captionsetup[subfigure]{font=scriptsize,
                         singlelinecheck}

\usepackage{tikz}

\begin{document}
    \begin{figure}[!ht]
    \centering
\subfloat[sub-title 1]{
    \begin{tikzpicture}[scale=0.42]
    \filldraw[fill=blue!20!white, semithick] 
        (0,1) |- (1,5) |- (5,4) |- (1,0) |- cycle;
    \filldraw[fill=white!100!white, semithick] 
        (3,1) |- (4,3) |- cycle;
    \draw[step=1cm,gray,thin] (0,0) grid (5,5);
        \end{tikzpicture}
                    }
    \raisebox{10mm}{\quad$\longrightarrow$\quad}
    \subfloat[sub-title 1]{$\begin{pmatrix}
                    1 & 0 & 0 & 0 & 0\\
                    1 & 1 & 1 & 1 & 1\\
                    1 & 1 & 1 & 0 & 1\\
                    1 & 1 & 1 & 0 & 1\\
                    0 & 1 & 1 & 1 & 1
                            \end{pmatrix}$
                          }
\caption{Main title}
    \end{figure}
\end{document}

在此处输入图片描述

相关内容