附录中的练习编号

附录中的练习编号

我正在写一个教程,每个部分都有一些练习。我还有一个附录,其中包含每个部分的附加练习。

但我希望对每个部分的附加练习进行编号,以便他们继续对每个部分的练习进行编号。

Mico 建议一个办法,部分可行。但当我点击练习 2.3 时,系统却将我带到练习 1.3。

我在标题中包含了我使用的所有包,但可能并不是所有包都是需要的。

\documentclass[11pt]{article}
\newcounter{counterE} % for use in Appendix B
\usepackage{amsthm}

\usepackage[pagebackref=true, colorlinks=true, linkcolor=blue, citecolor=blue, linkcolor=blue, anchorcolor=red, urlcolor=blue]{hyperref}
\usepackage{url, amsmath,enumerate,fancyhdr,amssymb, amsthm, 
    pstricks, epsf, lscape, ifpdf, graphicx, float}
    
    \usepackage[capitalize]{cleveref}

\newtheorem{Exercise}{Exercise}[section]

\begin{document}


\section{First section} 
\label{first-section} 

\begin{Exercise}
    This is the first exercise in this section.   
\end{Exercise}

\begin{Exercise}
    This is the second exercise in this section. 
\end{Exercise}

Additional exercises for this section are in \cref{exer-app-first}. 

\section{Second section} \label{second-section} 

\begin{Exercise}
    This is the first exercise in this section.
\end{Exercise}

\begin{Exercise}
    This is the second exercise in this section. 
\end{Exercise}

Additional exercises for this section are in  \cref{exer-app-second}. 

        Referencing Exercise \ref{exer-13}.   
    
    Referencing Exercise \ref{exer-23}. 
    
    
    
    \newpage 
\appendix
\renewcommand\theExercise{\arabic{counterE}.\arabic{Exercise}} 
% change the prefix variable to "counterE"


\section{Supplemental materials} 

\section{Additional exercises}

\subsection{Additional exercises for \cref{first-section}}  
\label{exer-app-first}

\setcounter{counterE}{1} % number of first section
\setcounter{Exercise}{2} % number of last exercise in first section   

\begin{Exercise} \label{exer-13} 
    This exercise should be called ``Exercise 1.3.''
\end{Exercise}

\begin{Exercise}  \label{exer-14}  
    This exercise should be called ``Exercise 1.4.''
\end{Exercise}


    \newpage 
    
    
\subsection{ Additional exercises for \cref{second-section}}  
\label{exer-app-second}

\setcounter{counterE}{2} % number of second section
\setcounter{Exercise}{2} % number of last exercise in second section
  
\begin{Exercise}    \label{exer-23} 
    This exercise should be called ``Exercise 2.3.''
\end{Exercise}

\begin{Exercise}  \label{exer-24} 
    This exercise should be called ``Exercise 2.4.''
\end{Exercise}

\end{document}

答案1

像这样吗?

在此处输入图片描述

\documentclass[11pt]{article}
\newcounter{counterE} % for use in Appendix B
\usepackage{amsthm}
\theoremstyle{definition} % upright lettering
\usepackage[capitalize]{cleveref}

\newtheorem{Exercise}{Exercise}[section]

\begin{document}

\section{First section} 
\label{first-section} 

\begin{Exercise}
This is the first exercise in this section.   
\end{Exercise}
    
\begin{Exercise}
This is the second exercise in this section. 
\end{Exercise}
    
Additional exercises for this section are in \cref{exer-app-first}. 

\section{Second section} \label{second-section} 
    
\begin{Exercise}
This is the first exercise in this section.
\end{Exercise}

\begin{Exercise}
This is the second exercise in this section. 
\end{Exercise}
    
Additional exercises for this section are in  \cref{exer-app-second}. 


\appendix
\renewcommand\theExercise{\arabic{counterE}.\arabic{Exercise}} 
   % change the prefix variable to "counterE"


\section{Supplemental materials} 
    
\section{Additional exercises}

\subsection{Additional exercises for \cref{first-section}}  
\label{exer-app-first}
   
\setcounter{counterE}{1} % number of first section
\setcounter{Exercise}{2} % number of last exercise in first section   

\begin{Exercise}
This exercise should be called ``Exercise 1.3.''
\end{Exercise}
    
\begin{Exercise}
This exercise should be called ``Exercise 1.4.''
\end{Exercise}
    
\subsection{ Additional exercises for \cref{second-section}}  
\label{exer-app-second}

\setcounter{counterE}{2} % number of second section
\setcounter{Exercise}{2} % number of last exercise in second section
    
\begin{Exercise}
This exercise should be called ``Exercise 2.3.''
\end{Exercise}
    
\begin{Exercise}
This exercise should be called ``Exercise 2.4.''
\end{Exercise}
    
\end{document}

附录回答 OP 的后续查询。首先,我们要注意的是,OP 的后续查询中提出的问题主要取决于以下两个条件,两者都不是原始查询中已说明。首先,该hyperref包正在被使用。其次,正在创建对附录 B 中的练习环境的交叉引用。

那么,原始作者的问题与众所周知的hyperref包在创建超链接时偶尔无法涉及相关计数器变量有关。要解决这个问题,需要(重新)定义隐藏的计数器H,该计数器会自动与交叉引用核心的计数器相关联。以下代码块显示了如何针对手头的示例代码完成此操作。

在此处输入图片描述

\documentclass[11pt]{article}
\usepackage{amsthm}
\theoremstyle{definition} % upright lettering
\usepackage[colorlinks,allcolors=blue]{hyperref}
\usepackage[capitalize,nameinlink]{cleveref}

\newcounter{counterE} % for use in Appendix B

\newtheorem{Exercise}{Exercise}[section]
\crefname{Exercise}{Exercise}{Exercises}

\begin{document}

\noindent
Cross-references to Exercises \labelcref{ex_B_aa}, \labelcref{ex_B_ab}, \labelcref{ex_B_ba}, and \labelcref{ex_B_bb}.

\section{First section} 
\label{first-section} 

\begin{Exercise}
This is the first exercise in this section.   
\end{Exercise}
    
\begin{Exercise}
This is the second exercise in this section. 
\end{Exercise}
    
Additional exercises for this section are in \cref{exer-app-first}. 

\section{Second section} \label{second-section} 
    
\begin{Exercise}
This is the first exercise in this section.
\end{Exercise}

\begin{Exercise}
This is the second exercise in this section. 
\end{Exercise}
    
Additional exercises for this section are in  \cref{exer-app-second}. 


\appendix
\renewcommand\theExercise{\arabic{counterE}.\arabic{Exercise}} % change the prefix variable to "counterE"
\renewcommand\theHExercise{\arabic{subsection}.\arabic{Exercise}}
   


\section{Supplemental materials} 
    
\section{Additional exercises}

\subsection{Additional exercises for \cref{first-section}}  
\label{exer-app-first}
   
\setcounter{counterE}{1} % number of first section
\setcounter{Exercise}{2} % number of last exercise in first section   

\begin{Exercise} \label{ex_B_aa}
This exercise should be called ``Exercise 1.3.''
\end{Exercise}
    
\begin{Exercise} \label{ex_B_ab}
This exercise should be called ``Exercise 1.4.''
\end{Exercise}
    
\subsection{Additional exercises for \cref{second-section}}  
\label{exer-app-second}

\setcounter{counterE}{2} % number of second section
\setcounter{Exercise}{2} % number of last exercise in second section
    
\begin{Exercise} \label{ex_B_ba}
This exercise should be called ``Exercise 2.3.''
\end{Exercise}
    
\begin{Exercise} \label{ex_B_bb}
This exercise should be called ``Exercise 2.4.''
\end{Exercise}
    
\end{document}

相关内容