1

Hi there I was working on a subfigure and since it's part of a pipeline I wanted to have something in my main text saying: ... (Figure 4, top right) ... (Figure 4, middle) ... (Figure 4, bottom).

Now, the subfigure part it's pretty straightforward and it appears to be correct; however, when clicking on the in-text links I'm always prompted to the whole Figure 4... What I would actually like to happens is a close-in look at the top/middle/bottom of the figure according to where I click.

Below the packages I use and how I implemented the subfigure.

\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}

I didn't use \caption for subfigures as I didn't need it, I only require a global caption for the workflow. Also, I got rid of extra white spaces between the subfigures since I want the workflow to appear as a single item. See image below.

I'm not sure what I've done wrong, any help is greatly appreciated! enter image description here

Matteo
  • 121
  • 6
  • "I'm not sure what I'm dong wrong..." Since there are no \caption statements inside thesubfigure environments, the \label statements can't latch on to anything that's specific to those subfigures. Instead, all LaTeX can do is associate them with the overall \caption statement. A subfigure environment is nothing but a minipage environment that knows what to do when it encounters a \caption directive. Since you don't want to provide subfigure-specific captions, it's kind of pointless to even employ subfigure environments. Why not provide minipage environments directly? – Mico Feb 18 '24 at 13:13
  • @Mico Indeed, I see what you mean. I changed the \subfigure with \minipage but that doesn't seem to change the end result... is there anything else specific I need to do? Sorry but I'm quite new to LaTex, also apology I fixed the typos – Matteo Feb 18 '24 at 13:34
  • 1
    Since you've chosen not to provide subfigure-specific captions, the basic \label-\ref mechanism cannot work since the \label statement have no anchor to attach themselves to. Please consult the posting How to cross-reference an unnumbered theorem using hyperref and cleveref and its accepted answer [shameless self-citation alert!] for an alternative approach to creating cross-references. – Mico Feb 18 '24 at 13:53

1 Answers1

1

Since you've chosen not to provide \caption directives for the three subfigure environments, the associated \label statements cannot work correctly. That's what you've (re)discovered.

Fortunately, since you're employing the hyperref package, an alternative method for creating cross-references is available: the \hypertarget/\hyperlink pair of directives. Its application to the problem at hand is illustrated in the example below. (Note that I chose to simplify the OP's code considerably since most of it has no bearing on the problem at hand.) \hypertarget and \hyperlink each take two arguments. The first argument is akin to the (single) argument of the well-known \label and \ref statements, while the second argument should be the text string you want to see typeset. Observe that the second argument can be empty.

enter image description here

enter image description here

\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}

Mico
  • 506,678
  • 1
    It works like a charm!!! Thank you so much, I actually needed a bit of code to understand better. I tried to replicate from the post you linked me to but all I got were \hyperlinks pointing to my first page... I missed out the context and content dependent \hypertarget which I was misplacing in the in-text part of the figure. Thanks again! – Matteo Feb 18 '24 at 14:59