我有一个由多个小图组成的图形。我不想为了方便而将大图拆分开,再用 latex 将其拼凑在一起。相反,我想用 cleverref 引用大图的每个子部分。我将用 tikz 在每张图片中放置一个节点,将每个子图像命名为 (a)、(b)、... 我如何使用 cleverref 引用此子图像,以便引用看起来像这样:图 1.1a 整个引用应超链接到图像。
我已经在使用以下重要的包:
\usepackage{caption}
\usepackage{subcaption}
\captionsetup[subfigure]{subrefformat=simple,labelformat=simple}
\renewcommand\thesubfigure{\alph{subfigure}}
我的 cleverref 选项是:
%reference packages
\usepackage[colorlinks=false]{hyperref}
\usepackage[nameinlink]{cleveref}
\crefdefaultlabelformat{#2#1#3}
%options for equations
\creflabelformat{equation}{#2#1#3}
\crefformat{equation}{#2Eq.~#1#3}
\Crefformat{equation}{#2Equation~#1#3}
\crefmultiformat{equation}{#2Eqs.~#1#3}%
{ and~#2#1#3}{, #2#1#3}{ and~#2#1#3}
%options for enumerations
\creflabelformat{enumi}{#2(#1)#3}
\crefformat{enumi}{#2(#1)#3}
\Crefformat{enumi}{#2(#1)#3}
%options for figures
\creflabelformat{figure}{#2#1#3}
\crefformat{figure}{#2Fig.~#1#3}
\Crefformat{figure}{#2Figure~#1#3}
\crefmultiformat{figure}{#2Fiqs.~#1#3}%
{ and~#2#1#3}{, #2#1#3}{ and~#2#1#3}
答案1
我会选择剪辑图像并将其包含四次(这不会影响最终的 PDF 大小,因为资源只会加载一次)。使用\clipbox*
该trimclip
包,您甚至不需要知道图像大小。
\documentclass{article}
\usepackage{subcaption,graphicx,trimclip,hyperref,cleveref}
\begin{document}
\begin{figure}
\centering
\subcaptionbox{Top left\label{tl}}{%
\clipbox*{0 {.5\height} {.5\width} {1\height}}{%
\includegraphics[width=8cm]{duck}%
}%
}\qquad
\subcaptionbox{Top right\label{tr}}{%
\clipbox*{{.5\width} {.5\height} {1\width} {1\height}}{%
\includegraphics[width=8cm]{duck}%
}%
}
\medskip
\subcaptionbox{Bottom left\label{bl}}{%
\clipbox*{0 0 {.5\width} {.5\height}}{%
\includegraphics[width=8cm]{duck}%
}%
}\qquad
\subcaptionbox{Bottom right\label{br}}{%
\clipbox*{{.5\width} 0 {1\width} {.5\height}}{%
\includegraphics[width=8cm]{duck}%
}%
}
\caption{A split duck}
\end{figure}
\end{document}
一个更完整的示例,显示引用符合预期。
\documentclass{article}
\usepackage{subcaption,graphicx,trimclip}
\usepackage[colorlinks]{hyperref}
\usepackage[nameinlink]{cleveref}
\captionsetup[subfigure]{subrefformat=simple,labelformat=simple}
\renewcommand\thesubfigure{\alph{subfigure}}
\crefdefaultlabelformat{#2#1#3}
%options for equations
\creflabelformat{equation}{#2#1#3}
\crefformat{equation}{#2Eq.~#1#3}
\Crefformat{equation}{#2Equation~#1#3}
\crefmultiformat{equation}{#2Eqs.~#1#3}%
{ and~#2#1#3}{, #2#1#3}{ and~#2#1#3}
%options for enumerations
\creflabelformat{enumi}{#2(#1)#3}
\crefformat{enumi}{#2(#1)#3}
\Crefformat{enumi}{#2(#1)#3}
%options for figures
\creflabelformat{figure}{#2#1#3}
\crefformat{figure}{#2Fig.~#1#3}
\Crefformat{figure}{#2Figure~#1#3}
\crefmultiformat{figure}{#2Fiqs.~#1#3}%
{ and~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\begin{document}
A reference to \cref{global}, then to
\cref{tl}, \cref{tr}, \cref{bl} and \cref{br}.
\begin{figure}[htp]
\centering
\subcaptionbox{\label{tl}}{%
\clipbox*{0 {.5\height} {.5\width} {1\height}}{%
\includegraphics[width=8cm]{duck}%
}%
}\qquad
\subcaptionbox{\label{tr}}{%
\clipbox*{{.5\width} {.5\height} {1\width} {1\height}}{%
\includegraphics[width=8cm]{duck}%
}%
}
\medskip
\subcaptionbox{\label{bl}}{%
\clipbox*{0 0 {.5\width} {.5\height}}{%
\includegraphics[width=8cm]{duck}%
}%
}\qquad
\subcaptionbox{\label{br}}{%
\clipbox*{{.5\width} 0 {1\width} {.5\height}}{%
\includegraphics[width=8cm]{duck}%
}%
}
\caption{A split duck}\label{global}
\end{figure}
\end{document}
以下代码也将创建链接而不剪切图形;添加
\newcommand{\labelphantom}[1]{%
\parbox{0pt}{\phantomsubcaption\label{#1}}%
}
在你的序言中,然后输入
A reference to \cref{global2}, then to
\cref{tl2}, \cref{tr2}, \cref{bl2} and \cref{br2}.
\begin{figure}[htp]
\centering
\labelphantom{tl2}%
\labelphantom{tr2}%
\labelphantom{bl2}%
\labelphantom{br2}%
\includegraphics[width=8cm]{duck}%
\caption{A split duck}\label{global2}
\end{figure}