クイズ付きの本をタイプセットしたいのですが、2 種類の図が必要です。
- テキスト図: これらは i、ii (ローマ字) で索引付けされています。
- クイズの数字: これらの数字はクイズに関連しており、適切な番号が付けられている必要があります: 1、2、3...n
クイズの図を上下に並べるのではなく、隣り合わせにしたいのですが、これを実現する唯一の方法はサブフロートを使用することです。原則的には、適切な参照を提供するカスタム カウンターを使用することで可能です。ただし、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}