代码:

代码:

我更喜欢在外部设计我的图形,这样我只需要在 latex 中包含一个图像,即使它包含多个子图。比如说,我想有两个并排的图形 (a) 和 (b)。我不会创建两个图像(对应于 (a) 和 (b))并将两者包含在图形环境中,而是创建一个并排的两个图形的图像,并只在图形环境中包含这一图像。

然而,有时我确实会反过来进行,并开始欣赏这个subfig包的便利性,它与一起cleveref允许直接和自动地引用子图。

不过,我还是想坚持创建一张图像而不是两张图像的习惯,因为我可以更轻松地调整子图的位置。有没有办法引用乳胶中未明确定义的子图(因为它是在外部定义的)?

我知道我可以手动使用\ref并在后面加上“a”或“b”来完成此操作。但是,我还不知道是否要将引用放在括号中,这可以通过cleveref最后的包轻松调整。因此,我希望尽可能保持其同质性。

如果已经有这样的问题,我很抱歉,但我完全不知道如何搜索。在字段中使用我的标题search确实会提供任何线索。

答案1

我同意这种工作流程并不理想,但您可以使用现有方法的一种方法是使用subcaption包中的空子图环境。我创建了一个名为的新命令\phantomsubfigure,它接受子图的标签作为唯一参数。

代码:

\documentclass[]{article}

\usepackage[demo]{graphicx} %the demo option is set only for this example
\usepackage[]{hyperref}
\usepackage[]{cleveref} %http://www.ctan.org/pkg/cleveref
\usepackage[labelformat=empty,skip=0pt]{subcaption} %http://www.ctan.org/pkg/subcaption

\newcommand*\phantomsubfigure[1]{\begin{subfigure}[]{0pt}\caption{}\label{#1}\end{subfigure}} %<---- this is the command

\begin{document}

Take look at the cow in \cref{1a}, the space ship in \cref{1b}, and finally at the dress in \cref{1c}.

\begin{figure}[ht]
\centering
\includegraphics[width=\columnwidth]{test.jpg}%
\phantomsubfigure{1a}%
\phantomsubfigure{1b}%
\phantomsubfigure{1c}%
\caption{this is a test}
\end{figure}

\end{document}

示例输出:

示例输出

相关内容