每行有多个图形,带有垂直标签

每行有多个图形,带有垂直标签

我想做一些类似于纸:

在此处输入图片描述

我特别感兴趣的是:

  1. 每行图像数量相同
  2. 使用垂直标签对每行进行分类
  3. 添加标题
  4. 包装图像(以便一侧可以有文字)

我读过一些问题(这里这里) 但它们与我想要的非常不同,你能帮帮我吗?

我已经尝试过这个,但是出现了错误:

\usepackage{subcaption} % for subfigures

\begin{table}[ht]
\begin{tabular}{ccc}
\begin{subfigure}{0.4\textwidth}\includegraphics[width=0.3\columnwidth]{Figures/all_souls_000021.jpg}&
\begin{subfigure}{0.4\textwidth}\includegraphics[width=0.3\columnwidth]{Figures/all_souls_000091.jpg}&
\begin{subfigure}{0.4\textwidth}\includegraphics[width=0.3\columnwidth]{Figures/oxford_000177.jpg}\\
\end{tabular}
\caption{A table with figures}
\label{tab:mytable}
\end{table}

错误:

! Missing } inserted.<inserted text>} ...olumnwidth]{Figures/all_souls_000021.jpg}&

答案1

具有方便的界面:

\documentclass{article}
\usepackage{graphicx,xparse,booktabs}

\ExplSyntaxOn
\NewDocumentEnvironment{places}{mm}
 {% #1 is the desired width, #2 is the number of photos per line
  \setlength{\tabcolsep}{0pt} % no space between rows
  \dim_set:Nn \l_places_width_dim
   {
    (#1-\ht\strutbox-\dp\strutbox-2pt)/(#2)
   }
  \begin{tabular}{r @{\hspace{2pt}} *{#2}{c}}
 }
 {
  \end{tabular}
 }

\NewDocumentCommand{\place}{mm}
 {% #1 is the name of the place, #2 is the comma separated list of images
  \seq_set_from_clist:Nn \l_places_images_in_seq { #2 }
  \seq_set_map:NNn \l_places_images_out_seq \l_places_images_in_seq { \places_set_image:n {##1} }
  \seq_put_left:Nn \l_places_images_out_seq
   {
    \begin{tabular}{c}\rotatebox[origin=c]{90}{\strut#1}\end{tabular}
   }
  \seq_use:Nn \l_places_images_out_seq { & } \\ \addlinespace
 }

\dim_new:N \l_places_width_dim
\seq_new:N \l_places_images_in_seq
\seq_new:N \l_places_images_out_seq

\cs_new_protected:Nn \places_set_image:n
 {
  \makebox[\l_places_width_dim]
   {
    \begin{tabular}{c}
    \includegraphics[
      width=\l_places_width_dim,
      height=\l_places_width_dim,
      keepaspectratio,
    ]{#1}
    \end{tabular}
   }
 }

\ExplSyntaxOff

\begin{document}

\begin{figure}[htp]
\centering

\begin{places}{\textwidth}{5}
\place{Hertford}{
  example-image,
  example-image-a,
  example-image-b,
  example-image-a,
  example-image-b
}
\place{Pitt Rivers}{
  example-image,
  example-image-9x16,
  example-image-b,
  example-image-a,
  example-image-b
}
\end{places}

\caption{Images}

\end{figure}

\begin{figure}[htp]
\centering

\begin{places}{.5\textwidth}{5}
\place{Hertford}{
  example-image,
  example-image-a,
  example-image-b,
  example-image-a,
  example-image-b
}
\place{Pitt Rivers}{
  example-image,
  example-image-9x16,
  example-image-b,
  example-image-a,
  example-image-b
}
\end{places}

\caption{Images}

\end{figure}

\end{document}

在此处输入图片描述

答案2

我猜你会喜欢这样的东西:

在此处输入图片描述

但我不确定。上图的代码片段是:

    \begin{figure}
\setlength\tabcolsep{1pt}
\settowidth\rotheadsize{Radcliffe Cam}
\begin{tabularx}{\linewidth}{l XXX }
\rothead{text 1}        &   \includegraphics[width=\hsize,valign=m]{image-1}
                        &   \includegraphics[width=\hsize,valign=m]{image-2}    
                        &   \includegraphics[width=\hsize,valign=m]{image-3}     \\  \addlinespace[2pt]
\rothead{Radcliffe Cam} &   \includegraphics[width=\hsize,valign=m]{image-4}
                        &   \includegraphics[width=\hsize,valign=m]{image-5}
                        &   \includegraphics[width=\hsize,valign=m]{image-6}
\end{tabularx}
    \caption{A table with figures}
\label{tab:mytable}
    \end{figure}

在您的文档前言中应该加载(除其他外)以下软件包:

\usepackage[demo]{graphicx}
\usepackage{booktabs, makecell, tabularx}
\usepackage{rotating}
\usepackage[export]{adjustbox}

附录: 当您希望“块”中的图像宽度比文本宽度窄时,您需要规定更窄的宽度tabularx(不是图形环境,您无法按照注释中显示的方式执行此操作):

\documentclass{article}
\usepackage[demo,   % in real document remove "demo" 
            export]{adjustbox}
\usepackage{rotating}
\usepackage{booktabs, makecell, tabularx}

\begin{document}
    \begin{figure}
\setlength\tabcolsep{1pt}
\settowidth\rotheadsize{Radcliffe Cam}
\setkeys{Gin}{width=\hsize}
\begin{tabularx}{0.8\linewidth}{l XXX }% <-- here is determined table width
\rothead{\centering
         text 1}        &   \includegraphics[valign=m]{image-1}
                        &   \includegraphics[valign=m]{image-2}    
                        &   \includegraphics[valign=m]{image-3}     \\  
    \addlinespace[2pt]
\rothead{Radcliffe Cam} &   \includegraphics[valign=m]{image-4}
                        &   \includegraphics[valign=m]{image-5}
                        &   \includegraphics[valign=m]{image-6}
\end{tabularx}
    \caption{A table with figures}
\label{tab:mytable}
    \end{figure}
\end{document}

编辑: 两年半后... :-) 附录中的代码片段已扩展为完整的 MWE。还进行了一些小改进。现在 MWE 应该可以简单测试了。

相关内容