596 private links
Could we cross-reference objects (tables, figures, etc.) that exist in the attached papers (whose code-base is foreign to the thesis) while also having these cross-references target the appropriate paper in the List of Papers, with the aid of the cleveref, caption and hyperref packages?
To clarify, for a compilation PhD thesis, where the thesis itself is created using LaTeX, but where the attached papers (hence the compilation part in the thesis) may or may not have been created using LaTeX (even if they were created using LaTeX, their codebase is not available to the thesis at runtime).
So we need to setup some sort of static list of manually created \label{}
s, that should occupy a counter and namespace separate from the thesis' own figures, tables, etc.
Preamble, literally
Uppsala university has a thesis template (my version, LuaLaTeX-based) that defines a listofpapers
environment (the details of which are not important right now) that allows us to create a List of Papers and easily assign a label for each paper, like this:
\begin{listofpapers}
\item\label{P1}
Li, C.; Ahmed, T.; Ma, M.; Edvinsson, T.; Zhu, J. %
Photocatalytic properties of ZnO/CdS nanoarrays\\%
\item \label{P2}
Ahmed, T.; Edvinsson, T. %
Photocatalytic activity of ultrasmall ZnO\\%
\end{listofpapers}
The above works in conjunction with the following definitions in the preamble:
\usepackage{cleveref}
\crefname{listofpapersc}{\textbf{\textsc{paper}}}{\textbf{\textsc{papers}}}
\Crefname{listofpapersc}{\textbf{\textsc{paper}}}{\textbf{\textsc{papers}}}
\creflabelformat{listofpapersc}{#2\textbf{\textsc{#1}}#3}
to give a nicely formatted Paper 1 (in small-caps in this case) in the text when we issue \cref{P1}
.
Solution: new floating environment and a custom cleveref format per paper
I have limited time to type this up, so here goes.
\usepackage{newfloat} % for the DeclareFloatingEnvironment cmd
\usepackage[nameinlink]{cleveref}
\crefname{listofpapersc}{\textbf{\textsc{paper}}}{\textbf{\textsc{papers}}}
\Crefname{listofpapersc}{\textbf{\textsc{paper}}}{\textbf{\textsc{papers}}}
\creflabelformat{listofpapersc}{#2\textbf{\textsc{#1}}#3}
\DeclareFloatingEnvironment[within=none]{tableP1}
\crefformat{tableP1}{\textsc{#2tab.~#1#3}~of\space\cref{P1}}
\Crefformat{tableP1}{\textsc{#2Tab.~#1#3}~of\space\cref{P1}}
\crefrangeformat{tableP1}{\textsc{tabs.~#3#1#4--#5#2#6}~of\space\cref{P1}}
\Crefrangeformat{tableP1}{\textsc{Tabs.~#3#1#4--#5#2#6}~of\space\cref{P1}}
\crefmultiformat{tableP1}{%
\scshape tabs.~#2#1#3}{%
\:\&\:#2#1#3~\textnormal{of\space}\cref{P1}}{%
, #2#1#3}{%
\:\&\:#2#1#3~\textnormal{of\space}\cref{P1}}
\Crefmultiformat{tableP1}{%
\scshape Tabs.~#2#1#3}{%
\:\&\:#2#1#3~\textnormal{of\space}\cref{P1}}{%
, #2#1#3}{%
\:\&\:#2#1#3~\textnormal{of\space}\cref{P1}}
\crefrangemultiformat{tableP1}{%
\scshape tabs.~#3#1#4--#5#2#6}{%
\:\&\:#3#1#4--#5#2#6~\textnormal{of\space}\cref{P1}}{%
, #3#1#4--#5#2#6}{%
\:\&\:#3#1#4--#5#2#6~\textnormal{of\space}\cref{P1}}
\Crefrangemultiformat{tableP1}{%
\scshape Tabs.~#3#1#4--#5#2#6}{%
\:\&\:#3#1#4--#5#2#6~\textnormal{of\space}\cref{P1}}{%
, #3#1#4--#5#2#6}{%
\:\&\:#3#1#4--#5#2#6~\textnormal{of\space}\cref{P1}}
and repeat the last block (everything down from DeclareFloatingEnvironment
) for figureP1
, and for tableP2
, figureP2
, etc.
And then, for the pièce de résistance, in one fell swoop we abuse both the listofpapers
environment and the phantomcaption
command to create the label
s that our cross-references will target:
\begin{listofpapers}
\item\label{P1}
Li, C.; Ahmed, T.; Ma, M.; Edvinsson, T.; Zhu, J. %
Photocatalytic properties of ZnO/CdS nanoarrays\\%
\bgroup
\captionsetup{type=figureP2}
\phantomcaption\label{fig:P1-schematic}
\phantomcaption\label{fig:P1-mechanism}
[... more figure labels as necessary ...]
\egroup
\bgroup
\captionsetup{type=tableP2}
\phantomcaption\label{tab:P1-parameters}
\phantomcaption\label{tab:P1-rates}
[... more table labels as necessary ...]
\egroup
\item \label{P2}
Ahmed, T.; Edvinsson, T. %
Photocatalytic activity of ultrasmall ZnO\\%
\end{listofpapers}
captionsetup
needs to be constrained by an environment (the manual suggests a minipage, which works fine but occupies a little bit of vertical space on the page), and it turns out group
works in this context and has the added benefit of occupying no space in the List of Papers.
With that, we can simply type \cref{fig:P1-schematic}
in the source to produce a nicely formatted cross-reference in the output document. The use of small-caps, abbreviated label names, and the trailing of paper X is my way to make these references contrast with the normal, in-thesis cross-references.
Here's an example of how the typeset cross-references look like:
Links and notes
- https://tex.stackexchange.com/questions/383587/plural-cref-with-custom-unnumbered-subsections
- https://tex.stackexchange.com/questions/597048/cleveref-fig-for-citing-multiple-subfigures-from-the-same-figure-but-figs
- https://gist.github.com/ummels/3428745
- https://reddit.com/r/LaTeX/comments/5gv6al/reference_multiple_list_items_in_single/
- the cleveref manual
- the caption and subcaption manuals