如何在同一行中对齐不同高度的子图

如何在同一行中对齐不同高度的子图

以下代码:

\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}

产生以下图片: 在此处输入图片描述

水平对齐矩阵,将同一行中的标题设置为对齐。我想对齐同一行的矩阵,使其具有S=相同的高度(两行中对齐的 S)。

问候

答案1

  • 问题有了新内容,所以答案也变了……
  • 像这样(我仍然不知道,你喜欢获得什么,现在我猜你喜欢S在方程式中对齐子标题):

在此处输入图片描述

    \documentclass[journal,twocolumn,10pt]{IEEEtran}
    \usepackage{caption, subcaption}
    \usepackage{amsmath}
    \usepackage{array}

    \usepackage{lipsum}

    \begin{document}
    \lipsum[11]
    \begin{figure}[htb]
    \centering
    \captionsetup{justification=centering}
    \begin{tabular}{*{2}{m{\dimexpr0.45\linewidth-2\tabcolsep}}}
    \[
    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}
    \]
    &
    \[
    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}
    \]                      \\
    \subcaption{Line}
    &
    \subcaption{Square}     \\
    \[
    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}
    \]
    &
    \[
    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}
    \]                      \\
    \subcaption{Full}
    &
    \subcaption{Star}
    \end{tabular}
    \caption{Action rule matrices for network graphs of figure \ref{NETEXAMPLE}}
    \label{ACTIVATIONFIG}
    \end{figure}
    \end{document}

答案2

  • 软件包subfigure已被取代subfig
  • 但更好的用法是更糟糕subcaption

    \documentclass[journal,twocolumn,10pt]{IEEEtran}
    \usepackage{caption}
    \usepackage{tikz}
    \usetikzlibrary{arrows.meta}
    \usepackage{graphicx}
    \usepackage{subcaption}
    \usepackage{amsmath}
    
    \begin{document}
    
    \begin{figure}[htb]
    \centering
    \captionsetup{justification=centering}
    \begin{subfigure}[t]{0.45\linewidth} % with option "t" subfigure is aligned to its top
    \[
    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}
    \]
    \caption{Square}
    \end{subfigure}\hfil
    \begin{subfigure}[t]{0.45\linewidth}
    \[
    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}
    \]
    \caption{Square}
    \end{subfigure}
    
    \begin{subfigure}[t]{0.45\linewidth}
    \[
    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}
    \]
    \caption{Full}
    \end{subfigure}\hfil
    \begin{subfigure}[t]{0.45\linewidth}
    \[
    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}
    \]
    \caption{Star}
    \end{subfigure}
    \caption{Action rule matrices for network graphs of figure \ref{NETEXAMPLE}}
    \label{ACTIVATIONFIG}
    \end{figure}
    
    \end{document}
    

这使:

在此处输入图片描述

这就是你要找的吗?

注意:我不明白为什么将矩阵括在tikz节点中。我对它们使用简单的显示数学环境。

编辑(1): 如果您喜欢顶部对齐前两个矩阵,然后在第二对中删除选项[t]或添加选项[b]

\documentclass[journal,twocolumn,10pt]{IEEEtran}
\usepackage{caption}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{amsmath}

\begin{document}

\begin{figure}[htb]
\centering
\captionsetup{justification=centering}
\begin{subfigure}[t]{0.45\linewidth}% with option "t" subfigure is aligned t its top
\[
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}
\]
\caption{Square}
\end{subfigure}\hfil
\begin{subfigure}[t]{0.45\linewidth}
\[
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}
\]
\caption{Square}
\end{subfigure}

\begin{subfigure}{0.45\linewidth}% without option subfigure is alignet t its center
\[
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}
\]
\caption{Full}
\end{subfigure}\hfil
\begin{subfigure}{0.45\linewidth}
\[
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}
\]
\caption{Star}
\end{subfigure}

\begin{subfigure}[b]{0.45\linewidth}% with option "b" subfigure is aligned to its bottom
\[
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}
\]
\caption{Full}
\end{subfigure}\hfil
\begin{subfigure}[b]{0.45\linewidth}
\[
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}
\]
\caption{Star}
\end{subfigure}
\caption{Action rule matrices for network graphs of figure \ref{NETEXAMPLE}}
\label{ACTIVATIONFIG}
\end{figure}

\end{document}

在此处输入图片描述

编辑(2) 考虑土拨鼠下面的评论,前两个矩阵也可以按如下方式对齐:

在此处输入图片描述

\documentclass[journal,twocolumn,10pt]{IEEEtran}
\usepackage{caption}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{amsmath}

\begin{document}

\begin{figure}[t]
\centering
\captionsetup{justification=centering}
\begin{subfigure}[t]{0.45\linewidth}
\[
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}
\]
\caption{Square}
\end{subfigure}\hfil
\begin{subfigure}[t]{0.45\linewidth}
\begin{gather*}  % enable stacking phantom matrices below main
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}\\       
    \vphantom{\begin{bmatrix}
     0\\
    \end{bmatrix}}
\end{gather*}
\caption{Square}
\end{subfigure}

\end{figure}
\end{document}

相关内容