如何将不同高度的子图对齐在同一行(2)

如何将不同高度的子图对齐在同一行(2)

(这个问题与“如何将不同高度的子图对齐在同一行”)。

我用以下代码绘制了一个 2x2 矩阵数组:

\documentclass[journal,twocolumn,10pt]{IEEEtran}
    \usepackage[compress]{cite}
    \usepackage{times} % Font Times New Roman throughout the document
    \usepackage{subfigure}
    \usepackage{epsfig}
    \usepackage{amsmath}
    \usepackage{amssymb}
    \usepackage{array}
    \usepackage{algorithm}
    \usepackage{algorithmic}
    \usepackage{tikz,pgfplots}
    \usepackage{adjustbox}
    \pgfplotsset{compat=1.14}
    \usepgfplotslibrary{patchplots}
    \usepgfplotslibrary{fillbetween}
    \usepackage{caption}
    \usetikzlibrary{arrows.meta}
    \usepackage{graphicx}
    \usepackage{float}
    \usepackage{mathtools}

\begin{document}

\begin{figure}[t]
\centering
\captionsetup{justification=centering}
\resizebox {0.8 \columnwidth}{!}{
\subfigure[Line]{\centering
\begin{tikzpicture}
\draw (0,0) node {$S= \begin{bmatrix}
     0  &   0  &   0  &   0\\
     1  &   0  &   0  &   0\\
     0  &   1  &   0  &   0\\
     0  &   0  &   1  &   0\\
     1  &   0  &   1  &   0\\
     0  &   0  &   0  &   1\\
     1  &   0  &   0  &   1\\
     0  &   1  &   0  &   1\\
    \end{bmatrix}$};
\end{tikzpicture} }
\subfigure[Square]{\centering
\begin{tikzpicture}
\draw (0,0) node {$S= \begin{bmatrix}
     0  &   0  &   0  &   0\\
     1  &   0  &   0  &   0\\
     0  &   1  &   0  &   0\\
     0  &   0  &   1  &   0\\
     1  &   0  &   1  &   0\\
     0  &   0  &   0  &   1\\
     0  &   1  &   0  &   1\\
    \end{bmatrix}$};
\end{tikzpicture}}
}\\
\resizebox {0.8 \columnwidth}{!}{
\subfigure[Full]{\centering
\begin{tikzpicture}
\draw (0,0) node {$S= \begin{bmatrix}
     0  &   0  &   0  &   0\\
     1  &   0  &   0  &   0\\
     0  &   1  &   0  &   0\\
     0  &   0  &   1  &   0\\
     0  &   0  &   0  &   1\\
\end{bmatrix}$};
\end{tikzpicture}}
\subfigure[Star]{\centering
\begin{tikzpicture}
\draw (0,0) node {  $S= \begin{bmatrix}
     0  &   0  &   0  &   0\\
     1  &   0  &   0  &   0\\
     0  &   1  &   0  &   0\\
     0  &   0  &   1  &   0\\
     0  &   1  &   1  &   0\\
     0  &   0  &   0  &   1\\
     0  &   1  &   0  &   1\\
     0  &   0  &   1  &   1\\
     0  &   1  &   1  &   1\\
    \end{bmatrix}$};
\end{tikzpicture}}}
\caption{Action rule matrices for network graphs of figure \ref{NETEXAMPLE}}
\label{ACTIVATIONFIG}
\end{figure}

\end{document}                                        

得到如下图所示的结果

在此处输入图片描述

一行中的子图根据其标题对齐,(a) 与 (b) 对齐,(c) 与 (d) 对齐。我更愿意按符号对齐矩阵,S以便一行中的矩阵的符号位于同一高度。例如,像这四个矩阵一样,符号S对齐:

在此处输入图片描述

问候

笔记:提及的问题“如何将不同高度的子图对齐在同一行”使用该subcaption包,当将其添加到文档的整个前言中时会出现编译错误。

答案1

一个选项是为 tikz 中的每个绘图定义一个特定的大小,使用矩形,在示例中它用红线显示,然后用白线显示,如果不使用水印,就不会出现问题,最后另一个选项使用矩阵库和 tikz 定位绘制所有内容。

如果你决定在 tikz 中绘制所有内容,你可以在另一个文档中绘制任何内容,然后使用独立环境将其导入为 pdf,如下所示将 tikzpicture 的不同组件缩放在一起。

结果: 在此处输入图片描述

梅威瑟:

% arara: pdflatex: {synctex: yes, action: nonstopmode}

\documentclass[journal,twocolumn,10pt]{IEEEtran}
\usepackage[compress]{cite}
\usepackage{times} % Font Times New Roman throughout the document
\usepackage{subfigure}
\usepackage{epsfig}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{array}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{tikz,pgfplots}
\usepackage{adjustbox}
\pgfplotsset{compat=1.14}
\usepgfplotslibrary{patchplots}
\usepgfplotslibrary{fillbetween}
\usepackage{caption}
\usetikzlibrary{matrix,positioning}
\usepackage{graphicx}
\usepackage{float}
\usepackage{mathtools}

\usepackage{lipsum}

\begin{document}
An option just delimiting some common dimenssion for tikzpicture using a rectangle shape.\\

    \begin{figure}[h!]
        \centering
        \subfigure[Line]{\centering
                \begin{tikzpicture}
                \draw[red] (-1.5,-2) rectangle (1.5,2);
                \draw (0,0) node {$S= \begin{bmatrix}
                    0  &   0  &   0  &   0\\
                    1  &   0  &   0  &   0\\
                    0  &   1  &   0  &   0\\
                    0  &   0  &   1  &   0\\
                    1  &   0  &   1  &   0\\
                    0  &   0  &   0  &   1\\
                    1  &   0  &   0  &   1\\
                    0  &   1  &   0  &   1\\
                    \end{bmatrix}$};
                \end{tikzpicture}}
            \subfigure[Square]{\centering
                \begin{tikzpicture}
                \draw[red] (-1.5,-2) rectangle (1.5,2);
                \draw (0,0) node {$S= \begin{bmatrix}
                    0  &   0  &   0  &   0\\
                    1  &   0  &   0  &   0\\
                    0  &   1  &   0  &   0\\
                    0  &   0  &   1  &   0\\
                    1  &   0  &   1  &   0\\
                    0  &   0  &   0  &   1\\
                    0  &   1  &   0  &   1\\
                    \end{bmatrix}$};
                \end{tikzpicture}}\\
        \subfigure[Full]{\centering
                \begin{tikzpicture}
                \draw[red] (-1.5,-2) rectangle (1.5,2);
                \draw (0,0) node {$S= \begin{bmatrix}
                    0  &   0  &   0  &   0\\
                    1  &   0  &   0  &   0\\
                    0  &   1  &   0  &   0\\
                    0  &   0  &   1  &   0\\
                    0  &   0  &   0  &   1\\
                    \end{bmatrix}$};
                \end{tikzpicture}}
            \subfigure[Star]{\centering
                \begin{tikzpicture}
                \draw[red] (-1.5,-2) rectangle (1.5,2);
                \draw (0,0) node {  $S= \begin{bmatrix}
                    0  &   0  &   0  &   0\\
                    1  &   0  &   0  &   0\\
                    0  &   1  &   0  &   0\\
                    0  &   0  &   1  &   0\\
                    0  &   1  &   1  &   0\\
                    0  &   0  &   0  &   1\\
                    0  &   1  &   0  &   1\\
                    0  &   0  &   1  &   1\\
                    0  &   1  &   1  &   1\\
                    \end{bmatrix}$};
                \end{tikzpicture}}
        \caption{Matrix using an auxiliar red box \ref{NETEXAMPLE}}
        \label{ACTIVATIONFIG}
    \end{figure}
If you choose to draw write you could obtaind this result.\\

\begin{figure}[h!]
    \centering
    \subfigure[Line]{\centering
        \begin{tikzpicture}
        \draw[white] (-1.5,-2) rectangle (1.5,2);
        \draw (0,0) node {$S= \begin{bmatrix}
            0  &   0  &   0  &   0\\
            1  &   0  &   0  &   0\\
            0  &   1  &   0  &   0\\
            0  &   0  &   1  &   0\\
            1  &   0  &   1  &   0\\
            0  &   0  &   0  &   1\\
            1  &   0  &   0  &   1\\
            0  &   1  &   0  &   1\\
            \end{bmatrix}$};
        \end{tikzpicture}}
    \subfigure[Square]{\centering
        \begin{tikzpicture}
        \draw[white] (-1.5,-2) rectangle (1.5,2);
        \draw (0,0) node {$S= \begin{bmatrix}
            0  &   0  &   0  &   0\\
            1  &   0  &   0  &   0\\
            0  &   1  &   0  &   0\\
            0  &   0  &   1  &   0\\
            1  &   0  &   1  &   0\\
            0  &   0  &   0  &   1\\
            0  &   1  &   0  &   1\\
            \end{bmatrix}$};
        \end{tikzpicture}}\\
    \subfigure[Full]{\centering
        \begin{tikzpicture}
        \draw[white] (-1.5,-2) rectangle (1.5,2);
        \draw (0,0) node {$S= \begin{bmatrix}
            0  &   0  &   0  &   0\\
            1  &   0  &   0  &   0\\
            0  &   1  &   0  &   0\\
            0  &   0  &   1  &   0\\
            0  &   0  &   0  &   1\\
            \end{bmatrix}$};
        \end{tikzpicture}}
    \subfigure[Star]{\centering
        \begin{tikzpicture}
        \draw[white] (-1.5,-2) rectangle (1.5,2);
        \draw (0,0) node {  $S= \begin{bmatrix}
            0  &   0  &   0  &   0\\
            1  &   0  &   0  &   0\\
            0  &   1  &   0  &   0\\
            0  &   0  &   1  &   0\\
            0  &   1  &   1  &   0\\
            0  &   0  &   0  &   1\\
            0  &   1  &   0  &   1\\
            0  &   0  &   1  &   1\\
            0  &   1  &   1  &   1\\
            \end{bmatrix}$};
        \end{tikzpicture}}
    \caption{Matrix using an auxiliar white box.}
    \label{ACTIVATIONFIG}
\end{figure}
\vspace{2\baselineskip}
%Some text
Drawing unsing tikz matrix library and positioning, you can control all, the distance from matrix nodes, distance between matrix.
\vspace{\baselineskip}  
\begin{figure}[h!]
    \centering
    \begin{tikzpicture}[
    Matrix/.style={
        matrix of math nodes,
        align=center,
        left delimiter=[,
        right delimiter=],
        column sep=0pt,
        row sep=0pt,
        inner sep=2pt,
        %nodes in empty cells,
        on grid,
    }
    ]

    \matrix[Matrix](M1){ % Matrix contents  
        0  &   0  &   0  &   0\\
        1  &   0  &   0  &   0\\
        0  &   1  &   0  &   0\\
        0  &   0  &   1  &   0\\
        1  &   0  &   1  &   0\\
        0  &   0  &   0  &   1\\
        1  &   0  &   0  &   1\\
        0  &   1  &   0  &   1\\
    };

    \matrix[Matrix, right=4.5cm of M1](M2){ % Matrix contents  
        0  &   0  &   0  &   0\\
        1  &   0  &   0  &   0\\
        0  &   1  &   0  &   0\\
        0  &   0  &   1  &   0\\
        1  &   0  &   1  &   0\\
        0  &   0  &   0  &   1\\
        0  &   1  &   0  &   1\\
    };

    \matrix[Matrix, below=4.5cm of M1](M3){ % Matrix contents  
        0  &   0  &   0  &   0\\
        1  &   0  &   0  &   0\\
        0  &   1  &   0  &   0\\
        0  &   0  &   1  &   0\\
        0  &   0  &   0  &   1\\
    };

    \matrix[Matrix, right=4.5cm of M3](M4){ % Matrix contents  
        0  &   0  &   0  &   0\\
        1  &   0  &   0  &   0\\
        0  &   1  &   0  &   0\\
        0  &   0  &   1  &   0\\
        1  &   0  &   1  &   0\\
        0  &   0  &   0  &   1\\
        0  &   1  &   0  &   1\\
    };
    \foreach \i/\j [count=\k from 1]in {a/Line,b/Square,c/Full,d/Star}{
        \draw node[on grid, left=1.5cm of M\k]{$S =$};
        \draw node[on grid, below=2cm of M\k]{\small(\i) \j};
    }


    \end{tikzpicture}
    \caption{Matrix using tikz matrix and positioning library}
    \label{ACTIVATIONFIG}
\end{figure}

\end{document} 

答案2

您正在将矩阵放入 Ti已经有 Z 张图片了(我不知道为什么),这可以让你在这样的图片内进行对齐。

\documentclass[journal,twocolumn,10pt]{IEEEtran}
    \usepackage{times} % Font Times New Roman throughout the document
    \usepackage{amsmath}
    \usepackage{amssymb}
    \usepackage{array}
    \usepackage{tikz}
    \usepackage{adjustbox}
    \usepackage{subcaption}
    \usetikzlibrary{positioning}

\begin{document}

\begin{figure}[t]
\centering
\captionsetup{justification=centering}
\resizebox {0.8 \columnwidth}{!}{
\begin{tikzpicture}[every node/.append style={baseline}]
\draw (0,0) node (A) {$S= \begin{bmatrix}
     0  &   0  &   0  &   0\\
     1  &   0  &   0  &   0\\
     0  &   1  &   0  &   0\\
     0  &   0  &   1  &   0\\
     1  &   0  &   1  &   0\\
     0  &   0  &   0  &   1\\
     1  &   0  &   0  &   1\\
     0  &   1  &   0  &   1\\
    \end{bmatrix}$};
\node[below=0pt of A,text width=4cm] {\subcaption{Line}};
\node[right=1cm of A] (B) {$S= \begin{bmatrix}
     0  &   0  &   0  &   0\\
     1  &   0  &   0  &   0\\
     0  &   1  &   0  &   0\\
     0  &   0  &   1  &   0\\
     1  &   0  &   1  &   0\\
     0  &   0  &   0  &   1\\
     0  &   1  &   0  &   1\\
    \end{bmatrix}$};
\node[below=0pt of B,text width=4cm] {\subcaption{Square}};
\end{tikzpicture}%}
}\\
\resizebox {0.8 \columnwidth}{!}{
\begin{tikzpicture}[every node/.append style={baseline}]
\draw (0,0) node (C) {$S= \begin{bmatrix}
     0  &   0  &   0  &   0\\
     1  &   0  &   0  &   0\\
     0  &   1  &   0  &   0\\
     0  &   0  &   1  &   0\\
     0  &   0  &   0  &   1\\
\end{bmatrix}$};
\node[below=0pt of C,text width=4cm] {\subcaption{Full}};
\node[right=1cm of C] (D) {  $S= \begin{bmatrix}
     0  &   0  &   0  &   0\\
     1  &   0  &   0  &   0\\
     0  &   1  &   0  &   0\\
     0  &   0  &   1  &   0\\
     0  &   1  &   1  &   0\\
     0  &   0  &   0  &   1\\
     0  &   1  &   0  &   1\\
     0  &   0  &   1  &   1\\
     0  &   1  &   1  &   1\\
    \end{bmatrix}$};
\node[below=0pt of D,text width=4cm] {\subcaption{Star}};
\end{tikzpicture}}%}
\caption{Action rule matrices for network graphs of figure \ref{NETEXAMPLE}}
\label{ACTIVATIONFIG}
\end{figure}
\end{document}                      

在此处输入图片描述

将子标题对齐到相同高度也很容易。(而且你正在加载许多未使用的包。)

\documentclass[journal,twocolumn,10pt]{IEEEtran}
    \usepackage{times} % Font Times New Roman throughout the document
    \usepackage{amsmath}
    \usepackage{amssymb}
    \usepackage{array}
    \usepackage{tikz}
    \usepackage{adjustbox}
    \usepackage{subcaption}
    \usetikzlibrary{positioning}

\begin{document}

\begin{figure}[t]
\centering
\captionsetup{justification=centering}
\resizebox {0.8 \columnwidth}{!}{
\begin{tikzpicture}[every node/.append style={baseline}]
\draw (0,0) node (A) {$S= \begin{bmatrix}
     0  &   0  &   0  &   0\\
     1  &   0  &   0  &   0\\
     0  &   1  &   0  &   0\\
     0  &   0  &   1  &   0\\
     1  &   0  &   1  &   0\\
     0  &   0  &   0  &   1\\
     1  &   0  &   0  &   1\\
     0  &   1  &   0  &   1\\
    \end{bmatrix}$};
\node[below=0pt of A,text width=4cm] (Acap) {\subcaption{Line}};
\node[right=1cm of A] (B) {$S= \begin{bmatrix}
     0  &   0  &   0  &   0\\
     1  &   0  &   0  &   0\\
     0  &   1  &   0  &   0\\
     0  &   0  &   1  &   0\\
     1  &   0  &   1  &   0\\
     0  &   0  &   0  &   1\\
     0  &   1  &   0  &   1\\
    \end{bmatrix}$};
\node[text width=4cm] at (Acap -| B) {\subcaption{Square}};
\end{tikzpicture}%}
}\\
\resizebox {0.8 \columnwidth}{!}{
\begin{tikzpicture}[every node/.append style={baseline}]
\draw (0,0) node (C) {$S= \begin{bmatrix}
     0  &   0  &   0  &   0\\
     1  &   0  &   0  &   0\\
     0  &   1  &   0  &   0\\
     0  &   0  &   1  &   0\\
     0  &   0  &   0  &   1\\
\end{bmatrix}$};
\node[right=1cm of C] (D) {  $S= \begin{bmatrix}
     0  &   0  &   0  &   0\\
     1  &   0  &   0  &   0\\
     0  &   1  &   0  &   0\\
     0  &   0  &   1  &   0\\
     0  &   1  &   1  &   0\\
     0  &   0  &   0  &   1\\
     0  &   1  &   0  &   1\\
     0  &   0  &   1  &   1\\
     0  &   1  &   1  &   1\\
    \end{bmatrix}$};
\node[below=0pt of D,text width=4cm] (Dcap) {\subcaption{Star}};
\node[text width=4cm] at (Dcap -| C) {\subcaption{Full}};
\end{tikzpicture}}%}
\caption{Action rule matrices for network graphs of figure \ref{NETEXAMPLE}}
\label{ACTIVATIONFIG}
\end{figure}
\end{document} 

在此处输入图片描述

编辑:添加了第二个选项和baseline

相关内容