表格中的图片副标题

表格中的图片副标题

我想要用两种方式来描述表格中的图形:在每个图形下放置子标题(首选)或直接在图形中插入描述。

为了创建图表,我编写了以下代码:

\begin{sidewaystable}[!htbp]
\label{tab:gr}
\centering\small\setlength\tabcolsep{2pt}
\begin{tabularx}{\textwidth}{@{}>{\bfseries}c*{9}{X}@{}}

  \includegraphics[width=2.2in,height=1.8in]{A1}&
  \includegraphics[width=2.2in,height=1.8in]{A2} & 
  \includegraphics[width=2.2in,height=1.8in]{A3} & 
  \includegraphics[width=2.2in,height=1.8in]{A4} \\

  \includegraphics[width=2.2in,height=1.8in]{B1} &
  \includegraphics[width=2.2in,height=1.8in]{B2} &
  \includegraphics[width=2.2in,height=1.8in]{B3} &
  \includegraphics[width=2.2in,height=1.8in]{B4} \\

  \includegraphics[width=2.2in,height=1.8in]{fig/C1} &
  \includegraphics[width=2.2in,height=1.8in]{fig/C2} &
  \includegraphics[width=2.2in,height=1.8in]{fig/C3} &
  \includegraphics[width=2.2in,height=1.8in]{fig/C4} \\

  \includegraphics[width=2.2in,height=1.8in]{fig/D1} &
  \includegraphics[width=2.2in,height=1.8in]{fig/D2} &
  \includegraphics[width=2.2in,height=1.8in]{fig/D3} &
  \includegraphics[width=2.2in,height=1.8in]{fig/D4} \\
  \end{tabularx}
  \caption{The main caption of the table.}
\end{sidewaystable}

因为我得到了给定一行的数字的不同含义,所以我想在每个数字下方(在本例中为右边)添加单独的描述。

答案1

您可以使用\subcaption同名包中的命令为每个图形添加标题。

在 中使用子标题存在问题tabularx,请参阅SourceForge 上的此错误报告,因此最好使用带列tabular的正则p

代码注释:

  • 总是\label必须放置(或在)\caption
  • 我稍微缩小了图像的尺寸,由于子标题增加了额外的空间,它们需要更小才能适合页面。(即使经过我的调整,表格也可能比文本块更宽,这取决于您的设置。)
  • 图像和子标题之间的空间似乎会引入额外的垂直间距。即,而不是

    \includegraphics[width=1.8in,height=1.2in]{example-image} \subcaption{Text}
    

    \includegraphics[width=1.8in,height=1.2in]{example-image}\subcaption{Text}
    
  • 要进一步垂直压缩表格,您可以\renewcommand\arraystretch{0} 在 之前添加tabular。您还可以使用 将子标题移近图像\captionsetup[subtable]{aboveskip=2pt}。这些都在代码中,但已注释。


\documentclass{article}
\usepackage{graphicx}
\usepackage{rotating}    
\usepackage{subcaption}
\begin{document}
\begin{sidewaystable}
\centering\small\setlength\tabcolsep{2pt}%
%\renewcommand\arraystretch{0}
%\captionsetup[subtable]{aboveskip=2pt}
\begin{tabular}{@{}*{4}{p{1.8in}}@{}}
  \includegraphics[width=1.8in,height=1.2in]{example-image}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-a}\subcaption{Text} & 
  \includegraphics[width=1.8in,height=1.2in]{example-image-b}\subcaption{Text} & 
  \includegraphics[width=1.8in,height=1.2in]{example-image-c}\subcaption{Text} \\

  \includegraphics[width=1.8in,height=1.2in]{example-image}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-a}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-b}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-c}\subcaption{Text} \\

  \includegraphics[width=1.8in,height=1.2in]{example-image}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-a}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-b}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-c}\subcaption{Text} \\

  \includegraphics[width=1.8in,height=1.2in]{example-image}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-a}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-b}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-c}\subcaption{Text} \\
  \end{tabular}
  \caption{The main caption of the table.}
\label{tab:gr}
\end{sidewaystable}
\end{document}

相关内容