如何将旋转的标题放在图像旁边?

如何将旋转的标题放在图像旁边?

我现在有的是:

前

\documentclass{article}
\usepackage{mwe}
\usepackage{subcaption}
\usepackage{calc}
\begin{document}
  \begin{figure}
    \begin{subfigure}{\linewidth}
      \begin{subfigure}{\linewidth/3 - 2em}
        \includegraphics[width=\linewidth]{example-image-1x1}
      \end{subfigure}\hfill
      \begin{subfigure}{\linewidth/3 - 2em}
        \includegraphics[width=\linewidth]{example-image-1x1}
      \end{subfigure}\hfill
      \begin{subfigure}{\linewidth/3 - 2em}
        \includegraphics[width=\linewidth]{example-image-1x1}
      \end{subfigure}
      \caption{Row 1}
    \end{subfigure}
    \par\bigskip
    \begin{subfigure}{\linewidth}
      \setcounter{subfigure}{0}%
      {
        \renewcommand\thesubfigure{\roman{subfigure}}
        \begin{subfigure}{\linewidth/3 - 2em}
          \includegraphics[width=\linewidth]{example-image-1x1}
          \caption{Column a}
        \end{subfigure}\hfill
        \begin{subfigure}{\linewidth/3 - 2em}
          \includegraphics[width=\linewidth]{example-image-1x1}
          \caption{Column b}
        \end{subfigure}\hfill
        \begin{subfigure}{\linewidth/3 - 2em}
          \includegraphics[width=\linewidth]{example-image-1x1}
          \caption{Column c}
        \end{subfigure}
      }%
      \setcounter{subfigure}{1}%
      \caption{Row 2}
    \end{subfigure}
  \end{figure}
\end{document}

我怎样才能移动行标题并旋转它以显示在页边距中?

后

我试过使用\rotatebox,但当它包含标题时似乎会出错

答案1

此解决方案使用表格(稍微向左移入边距)进行所有对齐。它依赖于图像的高度与宽度相同的事实(否则必须测量图像高度)。

引入了两个新计数器,以允许\labels。图像列计数器将在每一列中自动递增I。标签将存储您输入的任何内容\theimagecolumn

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

\newcounter{imagerow}[figure]
\newcounter{imagecolumn}[imagerow]
\renewcommand{\theimagecolumn}{Row \arabic{imagerow} Column \arabic{imagecolumn}}

\newcolumntype{I}{>{\refstepcounter{imagecolumn}}{c}<{}}

\newlength{\imagewidth}

\begin{document}
  \begin{figure}
    \def\arraystretch{0}% remove \arraystretch\dp\strutbox from row gap
    \setlength{\imagewidth}{\dimexpr \textwidth - 4\tabcolsep}% each gap takes 2\tabcolsep
    \divide \imagewidth by 3
    \hspace*{\dimexpr -\baselineskip - 2\tabcolsep}% move first column into margin
    \begin{tabular}{@{}cIII@{}}
      \stepcounter{imagerow}\raisebox{0.5\imagewidth}{\rotatebox[origin=c]{90}%
        {\strut Row \theimagerow}} &
      \includegraphics[width=\imagewidth]{example-image-1x1} &
      \includegraphics[width=\imagewidth]{example-image-1x1}\label{example} &
      \includegraphics[width=\imagewidth]{example-image-1x1} \\[2\tabcolsep]% adds gap between rows
      \stepcounter{imagerow}\raisebox{0.5\imagewidth}{\rotatebox[origin=c]{90}%
        {\strut Row \theimagerow}} &
      \includegraphics[width=\imagewidth]{example-image-1x1} &
      \includegraphics[width=\imagewidth]{example-image-1x1} &
      \includegraphics[width=\imagewidth]{example-image-1x1} \\[2\tabcolsep]
        \setcounter{imagecolumn}{0} &% \stepcounter{imagerow} will also work
        Column \arabic{imagecolumn} &
        Column \arabic{imagecolumn} &
        Column \arabic{imagecolumn}
    \end{tabular}
  \end{figure}
Example reference to image at \ref{example}.
\end{document}

演示

答案2

这对于行不起作用\caption,但至少看起来正确:

在此处输入图片描述

文本本身的定位是

\makebox[0pt]{\rotatebox[origin=c]{90}{
   (a) Row 1
}\hspace*{2em}}%

请注意,我必须为列标题添加一整行新行,否则它们会干扰行标题的垂直对齐。

完整代码如下

\documentclass{article}
\usepackage{mwe}% or load ’graphicx’ and ’blindtext’ manually
\usepackage{subcaption}
\usepackage{calc}
\begin{document}
  \blindtext
  \begin{figure}[h!]
    \begin{subfigure}{\linewidth}
      \makebox[0pt]{\rotatebox[origin=c]{90}{
        (a) Row 1
      }\hspace*{2em}}%
      \begin{subfigure}{\linewidth/3 - 2em}
        \includegraphics[width=\linewidth]{example-image-1x1}
      \end{subfigure}\hfill
      \begin{subfigure}{\linewidth/3 - 2em}
        \includegraphics[width=\linewidth]{example-image-1x1}
      \end{subfigure}\hfill
      \begin{subfigure}{\linewidth/3 - 2em}
        \includegraphics[width=\linewidth]{example-image-1x1}
      \end{subfigure}
    \end{subfigure}
    \par\bigskip
    \begin{subfigure}{\linewidth}
      \makebox[0pt]{\rotatebox[origin=c]{90}{
        (a) Row 1
      }\hspace*{2em}}%
      \begin{subfigure}{\linewidth/3 - 2em}
        \includegraphics[width=\linewidth]{example-image-1x1}
      \end{subfigure}\hfill
      \begin{subfigure}{\linewidth/3 - 2em}
        \includegraphics[width=\linewidth]{example-image-1x1}
      \end{subfigure}\hfill
      \begin{subfigure}{\linewidth/3 - 2em}
        \includegraphics[width=\linewidth]{example-image-1x1}
      \end{subfigure}
    \end{subfigure}
    \par\vskip \abovecaptionskip
    \begin{subfigure}{\linewidth}
      \setcounter{subfigure}{0}%
      \renewcommand\thesubfigure{\roman{subfigure}}
      \begin{subfigure}{\linewidth/3 - 2em}
        \caption{Column a}
      \end{subfigure}\hfill
      \begin{subfigure}{\linewidth/3 - 2em}
        \caption{Column b}
      \end{subfigure}\hfill
      \begin{subfigure}{\linewidth/3 - 2em}
        \caption{Column c}
      \end{subfigure}
    \end{subfigure}
  \end{figure}
\end{document}

相关内容