如何在乳膠中的 hyperref 中使用適當的超連結實現兩個數位計數器?

如何在乳膠中的 hyperref 中使用適當的超連結實現兩個數位計數器?

我想排版一本有測驗的書。我想要兩種類型的數字:

  • 文本數字:這些索引為 i、ii(羅馬)
  • 測驗數字:這些數字與測驗相關,並且應該有正確的編號:1,2,3...n

我希望測驗數字彼此相鄰,而不是彼此重疊,實現此目的的唯一方法是使用子浮點。原則上,使用自訂計數器是可能的,它提供了正確的參考。但是, hyperref 套件似乎不理解這些自訂計數器。

如何讓 hyperref 連結連結到正確的圖?

我的實現如下:

\documentclass{book}
\usepackage[english]{babel}
\usepackage[]{graphicx}
\usepackage{subfig}
\usepackage{hyperref}

%Counters
\newcounter{textcounter}
\setcounter{textcounter}{0}
\newcounter{quizcounter}
\setcounter{quizcounter}{0}

\begin{document}

\chapter*{Chaptername}

\section*{Introduction}
This is our normal text, where we want to refer to accompanying figures like figure \ref{textfigure1}.

\begin{figure}
\addtocounter{textcounter}{1}
\renewcommand{\thesubfigure}{\roman{textcounter}}
\renewcommand{\thefigure}{}
\subfloat[Example textfigure]{\includegraphics[width=0.5\columnwidth]{example_ti.jpg}\label{textfigure1}}
\end{figure}


\section*{Table}
\begin{enumerate}
\item Question one, asking questions about quizfigure \ref{quizfigure1}.
\item Question two, asking questions about quizfigure \ref{quizfigure2} , with more info in textfigure \ref{textfigure1}.
\end{enumerate}

\section*{quizfigures}
\begin{figure}
\renewcommand{\thesubfigure}{\arabic{quizcounter}}
\renewcommand{\thefigure}{}
\addtocounter{quizcounter}{1}
\subfloat[Example quizfigure 1]{\includegraphics[width=0.5\columnwidth]{example_q1.jpg}\label{quizfigure1}}
\end{figure}

\newpage

\begin{figure}
\renewcommand{\thesubfigure}{\arabic{quizcounter}}
\renewcommand{\thefigure}{}
\addtocounter{quizcounter}{1}
\subfloat[Example quizfigure 2]{\includegraphics[width=0.5\columnwidth]{example_q2.jpg}\label{quizfigure2}}
\addtocounter{quizcounter}{1}
\subfloat[Example quizfigure 3]{\includegraphics[width=0.5\columnwidth]{example_q3.jpg}\label{quizfigure3}}
\end{figure}


\end{document}

答案1

您不必使用自訂計數器,您可以使用subcaption套件的內建計數器。這是已棄用的軟體包的替代品subfig

您可以使用

\captionsetup{labelformat=empty,labelsep=none}
\renewcommand{\thefigure}{}

抑製圖形本身的標籤並將子圖形命名為就好像它們是圖形一樣。

要使用帶有羅馬數字的內建計數器,您可以使用

\renewcommand{\thesubfigure}{\roman{subfigure}}

為了在不同的圖形環境之間繼續子圖形的標籤計數,您應該只caption{}在最後一個圖形中使用。

\documentclass{book}
\usepackage[english]{babel}
\usepackage[]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{hyperref}


\captionsetup{labelformat=empty,labelsep=none}
\renewcommand{\thefigure}{}

\begin{document}

\chapter*{Chaptername}

\section*{Introduction}
This is our normal text, where we want to refer to accompanying figures like figure \ref{textfigure1}.

\begin{figure}
\renewcommand{\thesubfigure}{\roman{subfigure}}

\begin{subfigure}{6cm}
\caption{Example textfigure}
\label{textfigure1}
\end{subfigure}

\caption{}
\label{test}
\end{figure}


\section*{Table}
\begin{enumerate}
\item Question one, asking questions about quizfigure \ref{quizfigure1}.
\item Question two, asking questions about quizfigure \ref{quizfigure2} and \ref{quizfigure3} , with more info in textfigure \ref{textfigure1}.
\end{enumerate}

\section*{quizfigures}
\begin{figure}
\begin{subfigure}{3cm}
\caption{Example quizfigure 1}
\label{quizfigure1}
\end{subfigure}
\end{figure}

\newpage

\begin{figure}
\begin{subfigure}{3cm}
\caption{Example quizfigure 2}
\label{quizfigure2}
\end{subfigure}
\begin{subfigure}{3cm}
\caption{Example quizfigure 3}
\label{quizfigure3}
\end{subfigure}
\caption{}
\end{figure}

\end{document}

相關內容