文本中对子图特定部分的引用

文本中对子图特定部分的引用

你好,我正在处理一个子图,因为它是管道的一部分,所以我想在主文中添加一些内容:...(图 4,右上)...(图 4,中间)...(图 4,底部)。

现在,子图部分非常简单,而且看起来是正确的;但是,当单击文内链接时,我总是被提示查看整个图 4...我真正想要的是,根据我单击的位置,近距离查看图的顶部/中部/底部。

下面是我使用的包以及我如何实现子图。

\documentclass[12pt]{report}

\usepackage{float}
\usepackage{graphicx} % for inserting images
\usepackage[inkscapearea=page]{svg} %for SVG import

\usepackage[letterpaper,margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\usepackage{textcomp}
\usepackage{setspace}
\usepackage{csquotes}
\usepackage{authblk}
\usepackage{xurl}

\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=blue,
    filecolor=.,
    linkcolor=maroon,
    urlcolor=teal,
    linktoc=all
}
\usepackage{cleveref}

\usepackage{caption}
\usepackage{orcidlink}
\usepackage{subcaption}

%\captionsetup[table]{font=small}
\captionsetup[figure]{font=small}
\renewcommand{\thefigure}{\arabic{figure}}

\definecolor{teal}{rgb}{0.0, 0.5, 0.5}
\definecolor{maroon}{rgb}{0.69, 0.19, 0.38}
\definecolor{coolblack}{rgb}{0.0, 0.18, 0.39}
\definecolor{MSBlue}{rgb}{0.204, 0.353, 0.541}
\definecolor{darkcerulean}{rgb}{0.03, 0.27, 0.49}

\usepackage{tocloft}
\usepackage{tocbasic}
\usepackage[nottoc]{tocbibind} % automatically adds LOF and LOT to TOC

\renewcommand{\cftdot}{}
\renewcommand{\baselinestretch}{1.5}
\renewcommand{\cftchapfont}{\Large\bfseries\color{MSBlue}}
\renewcommand{\cfttoctitlefont}{\Large\bfseries\color{black}}
\renewcommand{\cftloftitlefont}{\Large\bfseries\color{black}}
\renewcommand{\cftsecfont}{\large\bfseries\color{darkcerulean}}
\renewcommand{\cftsubsecfont}{\normalsize\bfseries\color{coolblack}}

\makeatletter
\renewcommand\@dotsep{10000}
\makeatother

\DeclareTOCStyleEntry[
  entrynumberformat=\entrynumberwithprefix{\figurename},
  dynnumwidth,
  numsep=1em
]{tocline}{figure}
\newcommand\entrynumberwithprefix[2]{#1\enspace#2:\hfill}

\title{\Huge\bfseries{Pangenome-based Demographic Inference}}
\author{\LARGE{Matteo Tommaso Ungaro}}
\date{}

\usepackage{microtype}
\usepackage[main=english]{babel}
\usepackage[sorting=ynt, backend=biber, giveninits]{biblatex}
\addbibresource{references.bib}
\DeclareNameAlias{author}{family-given}

\titleformat{\chapter}[hang]{\Large\bfseries\color{MSBlue}}{\thechapter}{1em}{}
\titleformat*{\section}{\large\bfseries\color{darkcerulean}}
\titleformat*{\subsection}{\normalsize\bfseries\color{coolblack}}

\begin{document}

...

%referring to part of the figure/specific subfigures
(\textbf{\hyperref[figure:construction]{Figure 4, top right}})
(\textbf{\hyperref[figure:mapping]{Figure 4, middle}})
(\textbf{\hyperref[figure:analyses]{Figure 4, bottom}})

%subfigure part
\begin{figure}[htbp]
    \centering
    \begin{subfigure}{\textwidth}
    \centering
        \includesvg[width=6.5in]{figure4_flowchart_pt1}
        \vspace{-1.1\baselineskip}
        \label{figure:construction}
    \end{subfigure}
    \begin{subfigure}{\textwidth}
    \centering
        \includesvg[width=6.5in]{figure4_flowchart_pt2}
        \vspace{-1.1\baselineskip}
        \label{figure:mapping}
    \end{subfigure}
    \begin{subfigure}{\textwidth}
    \centering
        \includesvg[width=6.5in]{figure4_flowchart_pt3}
        \label{figure:analyses}
    \end{subfigure}
\caption[\textbf{Workflow from pangenome construction to downstream analyses}]{\textbf{Workflow from pangenome construction to downstream analyses.} } 
\label{figure:workflow}
\end{figure}

\end{document}

我没有使用\caption子图,因为我不需要它,我只需要一个工作流程的全局标题。此外,我删除了子图之间的额外空白,因为我希望工作流程显示为单个项目。如下图所示。

我不确定我做错了什么,非常感谢任何帮助! 在此处输入图片描述

答案1

由于您选择不\caption为这三种subfigure环境提供指令,因此相关\label语句不能正常工作。这就是您(重新)发现的。

幸运的是,由于您正在使用该hyperref包,因此可以使用另一种方法来创建交叉引用:\hypertarget/\hyperlink指令对。下面的示例说明了它对手头问题的应用。(请注意,我选择大大简化 OP 的代码,因为其中大部分与手头的问题无关。)\hypertarget\hyperlink每个都接受两个参数。第一个参数类似于众所周知的\labeland\ref语句的(单个)参数,而第二个参数应该是您想要看到的排版文本字符串。请注意,第二个参数可以为空。

在此处输入图片描述

在此处输入图片描述

\documentclass[12pt]{report}

\usepackage[demo]{graphicx} % don't use 'demo' option in real document
\usepackage[letterpaper,margin=1in]{geometry}
%%%\usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage[T1]{fontenc}

\usepackage{caption}
\captionsetup{textfont=bf}
\usepackage{xcolor}

\usepackage{microtype}
\usepackage[english]{babel}

\usepackage{hyperref} % for '\hypertarget' and '\hyperlink' macros
\hypersetup{colorlinks,allcolors=blue,linktoc=all}
\usepackage[noabbrev,nameinlink]{cleveref}

\begin{document}
Cross-references to the \hyperlink{fig:upper}{upper}, 
\hyperlink{fig:middle}{middle}, and \hyperlink{fig:lower}{lower} 
parts of \cref{figure:workflow}.

\clearpage

\begin{figure}[htbp]
    \begin{minipage}{\textwidth} % no need for 'subfigure' overhead
    \color{red} % omit this instruction in the real document
    \hypertarget{fig:upper}{} % note: 2nd arg. is empty
    \includegraphics[width=\textwidth]{figure4_flowchart_pt1}
    \end{minipage}%
    \vspace*{-0.6mm}
    \begin{minipage}{\textwidth}
    \color{yellow} % omit this instruction in the real document
    \hypertarget{fig:middle}{} % note: 2nd arg. is empty
    \includegraphics[width=\textwidth]{figure4_flowchart_pt2}
    \end{minipage}%
    \vspace*{-0.6mm}
    \begin{minipage}{\textwidth}
    \color{blue} % omit this instruction in the real document
    \hypertarget{fig:lower}{} % note: 2nd arg. is empty
    \includegraphics[width=\textwidth]{figure4_flowchart_pt3}
    \end{minipage}
\caption{Workflow from pangenome construction to downstream analyses.} 
\label{figure:workflow}
\end{figure}

\end{document} 

相关内容