如何在每行的左侧添加额外的标题?

如何在每行的左侧添加额外的标题?

我正在尝试在第一行的顶部和每行的左侧添加额外的标题,但我不知道如何将它们添加到每行的左侧。这是我尝试过的代码:

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

\begin{document}

\begin{figure}
    \begin{subfigure}{0.18\linewidth}
        \centering
        \caption*{Caption for Figure 1}
        \label{fig:sub1}
        \includegraphics[width=\linewidth]{example-image}
    \end{subfigure}%
    \hspace{5pt}%
    \begin{subfigure}{0.18\linewidth}
        \centering
        \caption*{Caption for Figure 2}
        \label{fig:sub2}
        \includegraphics[width=\linewidth]{example-image}
    \end{subfigure}%
    \hspace{5pt}%
    \begin{subfigure}{0.18\linewidth}
        \centering
        \caption*{Caption for Figure 3}
        \label{fig:sub3}
        \includegraphics[width=\linewidth]{example-image}
    \end{subfigure}%
    \hspace{5pt}%
    \begin{subfigure}{0.18\linewidth}
        \centering
        \caption*{Caption for Figure 4}
        \label{fig:sub4}
        \includegraphics[width=\linewidth]{example-image}
    \end{subfigure}%
    \hspace{5pt}%
    \begin{subfigure}{0.18\linewidth}
        \centering
        \caption*{Caption for Figure 5}
        \label{fig:sub5}
        \includegraphics[width=\linewidth]{example-image}
    \end{subfigure}

    \vspace{10pt} % Add vertical space between the rows

    \begin{subfigure}{0.18\linewidth}
        \centering
        \includegraphics[width=\linewidth]{example-image}
    \end{subfigure}%
    \hspace{5pt}%
    \begin{subfigure}{0.18\linewidth}
        \centering
        \includegraphics[width=\linewidth]{example-image}
    \end{subfigure}%
    \hspace{5pt}%
    \begin{subfigure}{0.18\linewidth}
        \centering
        \includegraphics[width=\linewidth]{example-image}
    \end{subfigure}%
    \hspace{5pt}%
    \begin{subfigure}{0.18\linewidth}
        \centering
        \includegraphics[width=\linewidth]{example-image}
    \end{subfigure}%
    \hspace{5pt}%
    \begin{subfigure}{0.18\linewidth}
        \centering
        \includegraphics[width=\linewidth]{example-image}
    \end{subfigure}

    \caption{Caption}
    \label{fig:main}
\end{figure}

\end{document}

这是代码的输出: 在此处输入图片描述

这就是我要的: 在此处输入图片描述

答案1

我还做了一些不必要的格式更改。请注意,\label不适用于\caption*

\documentclass{article}
\usepackage{subcaption}
\usepackage[export]{adjustbox}% for valign
\usepackage{graphicx}
\usepackage{showframe}% alignment tool

\begin{document}

\begin{figure}
    \centering
    \captionsetup[subfigure]{justification=raggedright}
    \begin{subfigure}{0.15\linewidth}
      \caption*{Caption 1}
    \end{subfigure}\hfil
    \begin{subfigure}{0.15\linewidth}
        \caption*{Caption for Figure 1}
        \includegraphics[width=\linewidth, valign=c]{example-image}
    \end{subfigure}\hfil
    \begin{subfigure}{0.15\linewidth}
        \caption*{Caption for Figure 2}
        \includegraphics[width=\linewidth, valign=c]{example-image}
    \end{subfigure}\hfil
    \begin{subfigure}{0.15\linewidth}
        \caption*{Caption for Figure 3}
        \includegraphics[width=\linewidth, valign=c]{example-image}
    \end{subfigure}\hfil
    \begin{subfigure}{0.15\linewidth}
        \caption*{Caption for Figure 4}
        \includegraphics[width=\linewidth, valign=c]{example-image}
    \end{subfigure}\hfil
    \begin{subfigure}{0.15\linewidth}
        \caption*{Caption for Figure 5}
        \includegraphics[width=\linewidth, valign=c]{example-image}
    \end{subfigure}

    \vspace{\floatsep} % Add vertical space between the rows

    \begin{subfigure}{0.15\linewidth}
      \caption*{Caption 2}
    \end{subfigure}\hfil
    \begin{subfigure}{0.15\linewidth}
        \includegraphics[width=\linewidth, valign=c]{example-image}
    \end{subfigure}\hfil
    \begin{subfigure}{0.15\linewidth}
        \includegraphics[width=\linewidth, valign=c]{example-image}
    \end{subfigure}\hfil
    \begin{subfigure}{0.15\linewidth}
        \includegraphics[width=\linewidth, valign=c]{example-image}
    \end{subfigure}\hfil
    \begin{subfigure}{0.15\linewidth}
        \includegraphics[width=\linewidth, valign=c]{example-image}
    \end{subfigure}\hfil
    \begin{subfigure}{0.15\linewidth}
        \includegraphics[width=\linewidth, valign=c]{example-image}
    \end{subfigure}

    \caption{Caption}
    \label{fig:main}
\end{figure}

\end{document}

演示


此解决方案使用表格。虽然这需要计算\tabcolsep,但结果比表格*版本更简单。

\documentclass{article}
\usepackage{array}
\usepackage{graphicx}
\usepackage{showframe}% alignment tool

\begin{document}

\begin{figure}
    \centering
    \setlength{\tabcolsep}{\dimexpr 0.1\textwidth/12}% 6*0.15=0.9
    \begin{tabular}{*6{m{0.15\textwidth}}}
      & {\raggedright Caption for Figure 1}
      & {\raggedright Caption for Figure 2}
      & {\raggedright Caption for Figure 3}
      & {\raggedright Caption for Figure 4}
      & {\raggedright Caption for Figure 5}
    \\[\abovecaptionskip]
      {\hfil Caption 1} 
      & \includegraphics[width=\linewidth]{example-image}
      & \includegraphics[width=\linewidth]{example-image}
      & \includegraphics[width=\linewidth]{example-image}
      & \includegraphics[width=\linewidth]{example-image}
      & \includegraphics[width=\linewidth]{example-image}
    \\[\floatsep]
      {\hfil Caption 2}
      & \includegraphics[width=\linewidth]{example-image}
      & \includegraphics[width=\linewidth]{example-image}
      & \includegraphics[width=\linewidth]{example-image}
      & \includegraphics[width=\linewidth]{example-image}
      & \includegraphics[width=\linewidth]{example-image}
    \end{tabular}
    \caption{Caption}
    \label{fig:main}
\end{figure}

\end{document}

相关内容