
La documentación delflotación finalEl paquete explica cómo personalizar el texto en los marcadores desde el valor predeterminado "[Tabla 3 acerca de aquí]". Pero me gustaría personalizar los marcadores para incluir un hipervínculo a la figura al final del documento. ¿Cómo se puede lograr esto?
Aquí hay una subpregunta: al personalizar el marcador, \thepostfigure
se refiere al número de figura. ¿Existe un comando similar \thefigurereference
que se refiera a la referencia a la figura, de modo que el texto del marcador pueda ser algo así como Figure \ref{\thefigurereference}} about here.
?
Actualización 2:En los comentarios, también pregunté acerca de un vínculo de retroceso, de modo que el título de la figura al final del documento tuviera un hipervínculo al flotante "[Figura 1 acerca de aquí]" incrustado en el texto. La solución aceptada de @John Kormylo ofrece esto.
Actualización 1 [editado para que quede más claro, se refiere a la respuesta original de @John Kormylo, no a la revisada]:
La solución (original) de @John Kormylo funciona, pero, según he aprendido, es incompatible con el paquete de subtítulos. Entonces, mi pregunta revisada es: ¿Existe alguna forma de crear hipervínculos a figuras que aún funcionen con subtítulos?
Aquí hay un MWE que usa su solución donde los hipervínculos no van a las figuras al final. La Figura 2 solo está ahí para demostrar por qué necesito subtítulos: el enlace aún falla incluso sin él, siempre que se use el paquete subpcaption.
\documentclass{article}
\usepackage{endfloat}
\usepackage{mwe}
\usepackage{hyperref}
\usepackage{subcaption}
% John Kormylo's original solution, which works when the subcaption package isn't used:
\renewcommand{\floatplace}[1]{% #1 = float type (e.g. figure)
\begin{center}
\hyperlink{#1.\csname thepost#1\endcsname}%
{[\csname #1name\endcsname~\csname thepost#1\endcsname\ about here.]}
\end{center}}
\begin{document}
\begin{figure}
\includegraphics{example-image}
\caption{A figure without subfigures}
\end{figure}
\begin{figure}[htb]
\centering
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.9\textwidth]{example-image}
\caption{first part}
\end{subfigure}%
%
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.9\textwidth]{example-image}
\caption{(second part)}
\end{subfigure}%
\caption{A figure with subfigures}
\end{figure}
\lipsum[1-2]
\end{document}
El aux
archivo producido sugiere que la razón por la que la solución no funcionó es que el subtítulo cambia el nombre de los contadores de figure.1
, figure.2
etc. a figure.caption.2
, figure.caption.3
etc. Tiene estas líneas para la lista de tablas (que tiene hipervínculos funcionales a las figuras):
\@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces This is figure 1.\relax }}{3}{figure.caption.2}}
\@writefile{lof}{\contentsline {figure}{\numberline {2}{\ignorespaces This is figure 2.\relax }}{4}{figure.caption.3}}
Una opción sería reescribir \floatplace
el comando (original) de John Kormylo comenzando con la numeración en 2 y cambiando el nombre de la cabeza a figure.caption
o table.caption
. Pero en un documento diferente, la numeración figure.caption
del archivo auxiliar comienza en 18. (Aunque no he descubierto cómo reproducir esto en un MWE). Esto significa que esa solución no funciona.
Respuesta1
Las \caption
llamadas \refstepcounter{figure}
que crean un \hypertarget
nombre \@currentHref
. Lamentablemente, \floatplace
sólo tiene acceso a \thefigure
(en realidad \thepostfigure
). Entonces necesitamos crear un mapa desde \thefigure
hasta \@currentHref
y moverlo hasta el principio del documento a través del archivo auxiliar. Para combinar esto y el vínculo de retroceso, lo reemplacé \caption
con \figurecaption
.
De acuerdo con el original, \floatplace
lo hice independiente del tipo flotante. Sin embargo, solo agregué código para \figurecaption
y \newfigure
.
\documentclass{article}
\usepackage{endfloat}
\usepackage{mwe}
\usepackage{subcaption}
\usepackage{hyperref}
\makeatletter
\renewcommand{\floatplace}[1]{% #1 = float type (e.g. figure)
\begin{center}
\def\floatnumber{\csname thepost#1\endcsname}
\def\floatname{\csname #1name\endcsname}
\hypertarget{figureback\floatnumber}{}%
\@ifundefined{#1anchor\floatnumber}%
{[\floatname~\floatnumber\ about here.]}%
{\hyperlink{\csname #1anchor\floatnumber\endcsname}%
{[\floatname~\floatnumber\ about here.]}}
\end{center}}
\newcommand{\figurecaption}[2][\empty]% #1=short caption (optional), #2=caption
{\ifx\empty#1\relax \caption[#2]{\hyperlink{figureback\thefigure}{#2}}%
\else \caption[#1]{\hyperlink{figureback\thefigure}{#2}}%
\fi
\immediate\write\@auxout{\string\newfigure{\thefigure}{\@currentHref}}}
\makeatother
\newcommand{\newfigure}[2]% #1 = \thefigure, #2 = \@currentHref
{\expandafter\gdef\csname figureanchor#1\endcsname{#2}}
\begin{document}
\begin{figure}
\includegraphics{example-image}
\figurecaption{A figure without subfigures}
\end{figure}
\begin{figure}[htb]
\centering
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.9\textwidth]{example-image}
\caption{first part}
\end{subfigure}%
%
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.9\textwidth]{example-image}
\caption{(second part)}
\end{subfigure}%
\figurecaption{A figure with subfigures}
\end{figure}
\lipsum[1-2]
\end{document}
Esto debería funcionar sin importar qué convención de nomenclatura extraña imponga el subtítulo.
Respuesta2
Necesitaba hacer lo mismo con tablas y figuras y al mismo tiempo mantener bajo control un error con el paquete de glosarios. (Creo que podría tener una función propia "tablecaption" definida en alguna parte).
Aquí tienes:
\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage{xcolor} %Farben
\usepackage{hyperref} %Links
\usepackage[nolists]{endfloat} % figures mit platzhalter und dann im Anhang
\renewcommand{\efloatseparator}{\mbox{}}
\usepackage{glossaries}
\usepackage{ifthen}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{mwe}
\makeatletter
\renewcommand{\floatplace}[1]{% #1 = float type (e.g. figure)
\begin{center}
\def\floatnumber{\csname thepost#1\endcsname}
\def\floatname{\csname #1name\endcsname}
\ifthenelse{\equal{#1}{figure}}% define backlink based on figure or table
{\def\backlink{figureback\floatnumber}}%
{\def\backlink{tableback\floatnumber}}%
\colorbox{yellow}{\floatname}
\colorbox{red}{\backlink}
\colorbox{orange}{\floatnumber}
\colorbox{green}{\csname #1anchor\floatnumber\endcsname}
\hypertarget{\backlink}{}
\@ifundefined{#1anchor\floatnumber}%
{[ \floatname~\floatnumber\ about here. ]}%
{[ \hyperlink{\csname #1anchor\floatnumber\endcsname}%
{\floatname~\floatnumber} about here. ]}
\end{center}
}
%for figure
\newcommand{\figurecaption}[2][\empty]% #1=short caption (optional), #2=caption
{%
\ifx\empty#1\relax %
\caption[#2]{\hyperlink{figureback\thefigure}{#2}}%
\else %
\caption[#1]{\hyperlink{figureback\thefigure}{#2}}%
\fi
\immediate\write\@auxout{\string\newfigure{\thefigure}{\@currentHref}}%
}
\makeatother
\newcommand{\newfigure}[2]% #1 = \thefigure, #2 = \@currentHref
{\expandafter\gdef\csname figureanchor#1\endcsname{#2}}
\makeatletter
%for table
\newcommand{\tabcaption}[2][\empty]% #1=short caption (optional), #2=caption (tabcaption instead of tablecaption for glossaries)
{%
\ifx\empty#1\relax %
\caption[#2]{\hyperlink{tableback\thetable}{#2}}%
\else %
\caption[#1]{\hyperlink{tableback\thetable}{#2}}%
\fi
\immediate\write\@auxout{\string\newtable{\thetable}{\@currentHref}}%
}
\makeatother
\newcommand{\newtable}[2]% #1 = \thetable, #2 = \@currentHref
{\expandafter\gdef\csname tableanchor#1\endcsname{#2}}
\begin{document}
\begin{table}
\tabcaption{tab}
\begin{tabular}{lcr}
1 & 2 & 3 \\
\end{tabular}
\end{table}
\begin{figure}
\includegraphics{example-image}
\figurecaption{A figure without subfigures}
\end{figure}
\begin{figure}[htb]
\centering
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.9\textwidth]{example-image}
\caption{first part}
\end{subfigure}%
%
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.9\textwidth]{example-image}
\caption{(second part)}
\end{subfigure}%
\figurecaption{A figure with subfigures}
\end{figure}
\lipsum[1-2]
\end{document}