我想做一些類似中所做的事情這紙:
我特別感興趣的是:
- 每行影像數量相同
- 使用垂直標籤對每一行進行分類
- 新增標題
- 環繞圖像(以便一側可以有文字)
我讀過一些問題(這裡和這裡)但它們與我想要的有很大不同,你能幫助我嗎?
我已經嘗試過這個,但出現錯誤:
\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 應該可以簡單地進行測試。