4

Code

Consider the follwing example:

\documentclass[danish]{article}

\usepackage{polyglossia} \setdefaultlanguage{danish} \usepackage[demo]{graphicx} \usepackage{booktabs} \usepackage{floatrow} \newfloatcommand{capbtabbox}{table}[][\FBwidth] \usepackage{caption,subcaption} \usepackage{siunitx} \usepackage{hyperref}

\begin{document}

\begin{figure} \begin{floatrow} \ffigbox{ \includegraphics[width = 0.2\textwidth]{image1}% }{ \caption{Figure caption.} \label{fig:1} } \capbtabbox{% \begin{tabular}{ l S[table-format = 2] } \toprule Næring~[\qty{1}{\g}] & {Energi~(\unit{\kJ})} \ \midrule Protein & 17 \[0.5ex] Fedtstof & 38 \[0.5ex] Kulhydrat & 17 \[0.5ex] Alkohol & 30 \ \bottomrule \end{tabular} }{ \caption{Table caption.} \label{tbl:1} } \end{floatrow} \end{figure}

\autoref{tbl:1}

\end{document}

output

Question

How to I make a reference to the table and not to the figure?

Mico
  • 506,678
  • Possibly helpful: https://tex.stackexchange.com/a/155223 – barbara beeton May 08 '22 at 21:02
  • @barbarabeeton Thank you Barbara. I'm not sure exactly what to look for in the other answer so can I maybe make you write an answer for my question? Thank you in advance. – Svend Tveskæg May 08 '22 at 21:22
  • @Svend -- I've never tried this myself, so what I was searching for was questions that cited ffigbox and needed references. Looking through the manual for floatrow, it looks like \ttabbox should give a recognizable "table", and \floatsetup[table]{capposition=bottom} to set a bottom caption. This is just a guess, based on the documentation. – barbara beeton May 08 '22 at 23:02

1 Answers1

6

First, \autoref does not use \@currentlabelname but rather uses \@currentHref to get the counter name. However, every caption in a figure uses the same \@currentHref, which is set at the top of the figure.

One can use \capstart from the hypcap package to add another \@currentHref with the desired \@captype (table).

I didn't use floatrow mostly to make sure it wasn't the source of the problem (which it often is).

\documentclass[danish]{article}

\usepackage{polyglossia} \setdefaultlanguage{danish} \usepackage[demo]{graphicx} \usepackage{booktabs} %\usepackage{floatrow} %\newfloatcommand{capbtabbox}{table}[][\FBwidth] \usepackage{caption,subcaption} \usepackage{siunitx} \usepackage{hyperref} \usepackage{hypcap}

\makeatletter \newcommand{\setcaptype}[1]% #1 = figure or table {\def@captype{#1}}

\newcommand{\setlabelname}[1]{\def@currentlabelname{#1}\ignorespaces} \makeatother

\begin{document}

\setcounter{table}{1}

\begin{figure} \begin{minipage}[b]{\dimexpr 0.5\textwidth-0.5\columnsep} \centering \includegraphics[width = 0.2\textwidth]{image1}% \caption{Figure caption.} \label{fig:1} \end{minipage}\hfill \begin{minipage}[b]{\dimexpr 0.5\textwidth-0.5\columnsep} \setcaptype{table}\capstart \centering \begin{tabular}[b]{ l S[table-format = 2] } \toprule Næring~[\qty{1}{\g}] & {Energi~(\unit{\kJ})} \ \midrule Protein & 17 \[0.5ex] Fedtstof & 38 \[0.5ex] Kulhydrat & 17 \[0.5ex] Alkohol & 30 \ \bottomrule \end{tabular} \caption{Table caption.} \setlabelname{notused} \label{tbl:1} \end{minipage} \end{figure}

\autoref{tbl:1}

\end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • Thank you! I'll look at it when I get home from work and then report back whether or not it fixed my problem. – Svend Tveskæg May 09 '22 at 10:13
  • I regard putting the counter name into @currentHref instead of @currentlabelname to be a bad decision. I would go the other way and fill every @currentHref with auto.1 auto.2 etc. All @currentHref needs to do is generate unique labels which are compatible with (but unlikely to be duplicated by) \hypertarget. – John Kormylo May 09 '22 at 14:23