改编自 Thorsten Donigs 的回答表格和图形并排显示,并带有独立标题
标题正确地对图形和表格进行了编号,但是在此示例中,如何正确设置文本中引用的图形和表格的标签?
\documentclass[11pt,a4paper,english]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[font=small,labelfont=bf]{caption}
\usepackage{hyperref}
\usepackage{graphicx}
\DeclareCaptionLabelFormat{andtable}{#1~#2 \& \tablename~\thetable}
\begin{document}
\begin{figure}[!ht]
\centering
\rule{3cm}{3cm}
\caption{pic1}
\end{figure}
\autoref{tab:table123} %will give Figure 2 instead of Table 1.
\begin{figure}[!ht]
\centering
\rule{3cm}{3cm}
\hfill
\begin{tabular}[b]{cc}\hline
Table head & Table head \\ \hline
Some values & Some values \\
Some values & Some values \\\hline
\end{tabular}
\captionlistentry[table]{entry for table}
\captionsetup{labelformat=andtable}
\caption{some caption for both.}
\label{tab:table123}
\label{fig:pic2}
\end{figure}
\end{document}
答案1
您需要标记相关计数器递增的点,并告诉 hyperref 您正在标记表格,即使它是一个图形环境。
\captionlistentry[figure]{entry for figure}
\label{fig:figure345}
\captionlistentry[table]{entry for table}
{\makeatletter\edef\@currentHref{table.caption.\the\c@table}\label{tab:table123}}