自定义多个子图的放置

自定义多个子图的放置

说我有7子图,我想放置1左边的图形,把它放大到足以占据两行。然后其他的6数字放在右边,3每行的数字。示例如下,

在此处输入图片描述

在乳胶中应该怎样编码?

答案1

您可以使用包中的命令tabular环境。subcaptionboxsubcaption

\documentclass{article}

\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{multirow}
\usepackage{tabularx}

\newcolumntype{s}{>{\hsize=.2\hsize\linewidth=\hsize}X}
\newcolumntype{D}{>{\hsize=.4\hsize\linewidth=\hsize}X} %Double width column

\newcommand{\wdImg}{\dimexpr \linewidth-2\tabcolsep} %width of the image

\begin{document}
    \begin{figure}
        \begin{tabularx}{\textwidth}{D *{3}{s}}
            \multirow{-2.9}{*}{\subcaptionbox{a\label{fig:1}}{\includegraphics[width=\wdImg]{example-image}}}
            & \subcaptionbox{a\label{fig:2}}{\includegraphics[width=\wdImg]{example-image}}
            & \subcaptionbox{a\label{fig:3}}{\includegraphics[width=\wdImg]{example-image}}
            & \subcaptionbox{a\label{fig:4}}{\includegraphics[width=\wdImg]{example-image}}
            \\
            & \subcaptionbox{a\label{fig:5}}{\includegraphics[width=\wdImg]{example-image}}
            & \subcaptionbox{a\label{fig:6}}{\includegraphics[width=\wdImg]{example-image}}
            & \subcaptionbox{a\label{fig:7}}{\includegraphics[width=\wdImg]{example-image}}
            \\
        \end{tabularx}
        \caption{A figure}
        \label{fig:fig1}
    \end{figure}
\end{document}

在此处输入图片描述

答案2

如果您的图片是正方形的,这是一种实现完美对齐的方法。

\documentclass{article}
\usepackage{subcaption}
\usepackage{graphicx}

\newsavebox{\houlubox}
\newlength{\houlumodule}
\newlength{\houlusep}

\begin{document}

\begin{figure}[htp]

% we decide that the big figure is 2/5 of the column width
\sbox{\houlubox}{%
  \begin{subfigure}{0.4\dimexpr\columnwidth}
  \includegraphics[width=\textwidth]{example-image-1x1}
  \caption{}
  \end{subfigure}%
}
% the width of the other images should be half the difference
% between twice the width and the height, minus a short gap
\setlength{\houlumodule}{\dimexpr(2\wd\houlubox-\ht\houlubox-\dp\houlubox)/2-0.5ex}
% let's compute the separation
\setlength{\houlusep}{\dimexpr(\columnwidth-\wd\houlubox-3\houlumodule)/3}

\parbox[b]{\wd\houlubox}{\usebox{\houlubox}\par\vspace{0pt}}\hfill
\parbox[b][\dimexpr\ht\houlubox+\dp\houlubox][s]{\dimexpr3\houlumodule+2\houlusep}{%
  \begin{subfigure}{\houlumodule}
  \includegraphics[width=\textwidth]{example-image-1x1}
  \caption{}
  \end{subfigure}\hfill
  \begin{subfigure}{\houlumodule}
  \includegraphics[width=\textwidth]{example-image-1x1}
  \caption{}
  \end{subfigure}\hfill
  \begin{subfigure}{\houlumodule}
  \includegraphics[width=\textwidth]{example-image-1x1}
  \caption{}
  \end{subfigure}

  \vfill

  \begin{subfigure}{\houlumodule}
  \includegraphics[width=\textwidth]{example-image-1x1}
  \caption{}
  \end{subfigure}\hfill
  \begin{subfigure}{\houlumodule}
  \includegraphics[width=\textwidth]{example-image-1x1}
  \caption{}
  \end{subfigure}\hfill
  \begin{subfigure}{\houlumodule}
  \includegraphics[width=\textwidth]{example-image-1x1}
  \caption{}
  \end{subfigure}

  \vspace{0pt}
}
\caption{Full caption}

\end{figure}

\end{document}

在此处输入图片描述

答案3

对齐顶部和底部比较棘手。下面通过反复试验只找到大图像的高度。请注意,它越大,其他子图就越小。

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{tabularx}

\begin{document}
    \begin{figure}
        \captionsetup[subfigure]{skip=0pt}% reduce caption size
        \setlength{\tabcolsep}{2pt}% reduce horizontal gaps
        \sbox1{\includegraphics[height=4.175cm]{example-image}}% measure width
        \sbox2{\parbox[t]{\wd1}{\subcaption{a}\label{fig:1}}}% first subcaption
        \begin{tabularx}{\textwidth}{@{}lXXX@{}}
            & \raisebox{-\height}{\includegraphics[width=\hsize]{example-image}}
            & \raisebox{-\height}{\includegraphics[width=\hsize]{example-image}}
            & \raisebox{-\height}{\includegraphics[width=\hsize]{example-image}}
            \\
            & \subcaption{a}\label{fig:2}
            & \subcaption{a}\label{fig:3}
            & \subcaption{a}\label{fig:4}
            \\
            \smash{\usebox1}% overlap preceding rows
            & \includegraphics[width=\hsize]{example-image}
            & \includegraphics[width=\hsize]{example-image}
            & \includegraphics[width=\hsize]{example-image}
            \\
            \usebox2
            & \subcaption{a}\label{fig:5}
            & \subcaption{a}\label{fig:6}
            & \subcaption{a}\label{fig:7}
        \end{tabularx}
        \caption{A figure}\label{fig:fig1}
    \end{figure}
\end{document}

相关内容