交叉引用“假”子图片

交叉引用“假”子图片

我目前正在撰写一份作业报告Latex,在交叉引用“假”子图片时遇到了一些麻烦。

我说假是因为我正在进口单张图片在 Inkscape 中绘制,合并 4 个不同的子图,如下所示在此处输入图片描述

我希望当我通过时\cref{fig:model}可以参考(图 1A)或(图 1B)

这是我的 MWE:

\usepackage{graphicx}
\usepackage[round]{natbib}
\usepackage{hyperref} 
\usepackage{cleveref}
\crefformat{figure}{#2(\figurename~#1)#3}
 
\documentclass[notitlepage, 12pt]{report}


\begin{document}

\begin{figure}[h]
    \centering
    \includegraphics[height=10cm,width=16cm]{imagens/model.png}
    \caption{caption}
    \label{fig:model}
\end{figure}


\bibliography{ref}{}
\bibliographystyle{geo-apalike}

\end{document}

我使用了不同的格式,如下cref所述:将图的交叉引用放在括号中

关于如何做到这一点有什么建议吗?

答案1

这借鉴了Mico 的回答,而且还将锚点(大约)设置在正确的点:如果您单击链接,您将移动到正确的子图。

这个想法是生成四个subfigure占用与子图相同空间的空环境(“近似”是指图像之间的小间隙,但这不是什么大问题)。在这些空环境之后,打印图像,但不占用垂直空间,因此它将精确覆盖之前的空间。

\documentclass{article}
\usepackage{graphicx,subcaption}
\usepackage{hyperref} 
\usepackage{cleveref}

\crefformat{figure}{#2(\figurename~#1)#3}
\newsavebox{\fourfigurebox}

\begin{document}

\cref{four:a},
\cref{four:b},
\cref{four:c},
\cref{four:d},
\cref{four}.

\begin{figure}[htp]
\sbox\fourfigurebox{\includegraphics[width=\textwidth]{fourimages}}% change with your own image

\begin{subfigure}[t][0.5\ht\fourfigurebox]{0.5\textwidth}
\refstepcounter{subfigure}\label{four:a}
\end{subfigure}%<---- Don't forget
\begin{subfigure}[t][0.5\ht\fourfigurebox]{0.5\textwidth}
\refstepcounter{subfigure}\label{four:b}
\end{subfigure}\par\nointerlineskip
\begin{subfigure}[t][0.5\ht\fourfigurebox]{0.5\textwidth}
\refstepcounter{subfigure}\label{four:c}
\end{subfigure}%<---- Don't forget
\begin{subfigure}[t][0.5\ht\fourfigurebox]{0.5\textwidth}
\refstepcounter{subfigure}\label{four:d}
\end{subfigure}\par\nointerlineskip
\smash{\usebox{\fourfigurebox}}

\caption{These are four images}\label{four}

\end{figure}

\end{document}

在此处输入图片描述

答案2

我想您可以在环境中插入一个虚拟subfigure环境,该环境不包含图形,只包含四个\refstepcounter指令\labelfigure以创建四个隐式(但不可见)的子图。

话虽如此,我认为只写“如 \cref{fig:model} 的 A 和 B 面板所示,...”并没有什么错。

在此处输入图片描述

\documentclass[notitlepage, 12pt, demo]{report} % omit 'demo' option in real document
\usepackage{graphicx,subcaption}
\renewcommand\thesubfigure{\Alph{subfigure}} % OP wants uppercase letters

\usepackage[colorlinks,allcolors=blue]{hyperref} 
\usepackage[noabbrev,nameinlink]{cleveref}
\crefformat{figure}{#2(\figurename~#1)#3}
 
\begin{document}

\begin{figure}[h]
\begin{subfigure}{1\textwidth} % this 'subfigure' env. has no visible content
    \refstepcounter{subfigure}\label{fig:model:a}
    \refstepcounter{subfigure}\label{fig:model:b}
    \refstepcounter{subfigure}\label{fig:model:c}
    \refstepcounter{subfigure}\label{fig:model:d}
\end{subfigure}%
\includegraphics[width=\textwidth]{imagens/model.png}
\caption{A figure with four implicit subfigures}
\label{fig:model}
\end{figure}

As shown in \cref{fig:model:a} and \cref{fig:model:b}, \dots

As shown in Panels A and B of \cref{fig:model}, \dots
\end{document}

相关内容