我如何才能获得名称中使用的最后一个部分编号?

我如何才能获得名称中使用的最后一个部分编号?

我正在写一些包含许多章节的笔记。在此文件的每个章节末尾,我想插入一个练习列表,标题如下:

Problems - Section x.y (x = chapter, y = section)

\begin{exercise}
blah blah blah
\end{exercise}

我可以使用 \label 命令来执行此操作,例如

     \section{NameSection}\label{secx.y}

bla bla bla


     Problems - Section \ref{secx.y}
        
        \begin{exercise}
        blah blah blah
        \end{exercise}

有没有办法使用诸如 \lastchapter.section 或 \current.chapther.section 之类的命令来代替 \ref{secx.y} ?

我正在使用超链接。

\documentclass[a4paper, 12pt]{report}
\usepackage{mathpazo, amsmath,amsfonts,amscd,bezier, amssymb, ifthen,amsthm}
\usepackage[x11names, usenames,svgnames,dvipsnames, table]{xcolor}
\RequirePackage[babel=true]{microtype}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage{enumerate}
\usepackage[shortlabels]{enumitem}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{tasks}
\usepackage{graphicx}
\usepackage{float}
\usepackage[margin=1.5cm ]{geometry}
\usepackage[most]{tcolorbox}
\usepackage{indentfirst}
\usepackage{eqparbox, ulem}
\usepackage{lipsum}
\usepackage[colorlinks=true]{hyperref}
\hypersetup{allcolors=magenta}

\everymath{\displaystyle}

\newcounter{theeq} 
\counterwithin{theeq}{chapter}
\setcounter{theeq}{0}

\newcommand{\eq}{ 
    \
    
    \noindent 
    \refstepcounter{theeq}\textbf{\thechapter.\arabic{theeq}}. }
%%%%%%%%%%%%%%%%%
\begin{document}

\chapter{test1}
\lipsum[2]

\section{test1.1}\label{test1.1}
\lipsum[3]

\begin{center}
    \Large{Problems - Section \ref{test1.1}}
\end{center}

\eq Let \(x \in R\)

\eq xx

\section{test1.2}\label{test1.2}
\lipsum[3]

\begin{center}
    \Large{Problems - Section \ref{test1.2}}
\end{center}

\eq Let \(x \in R\)

\eq xx

\section{test1.3}\label{test1.3}
\lipsum[3]

\begin{center}
    \Large{Problems - Section \ref{test1.3}}
\end{center}

\eq Let \(x \in R\)

\eq xx


\chapter{test2}
\lipsum[3]

\section{test2.1}\label{test2.1}

\begin{center}
    \Large{Problems - Section \ref{test2.1}}
\end{center}

\eq Let \(x \in R\)

\eq \(\lim_{x\to 0} \frac{1}{x}\)

\chapter{test3}

\section{test3.1}\label{test3.1}

\begin{center}
    \Large{Problems - Section \ref{test3.1}}
\end{center}

\eq Let \(x \in R\)

\eq xx

\end{document}
                    

答案1

一次运行即可完成。您几乎可以将任何内容输入到文本输入中。

它可能并不总是适用于section.\thesection,这取决于\thesection的定义方式。如果您查看 下的辅助文件,\contentsline您将找到锚点名称section.1.1(例如)。这就是您需要为 重现的内容\hyperlink

\documentclass[a4paper, 12pt]{report}
\usepackage{mathpazo, amsmath,amsfonts,amscd,bezier, amssymb, ifthen,amsthm}
\usepackage[x11names, usenames,svgnames,dvipsnames, table]{xcolor}
\RequirePackage[babel=true]{microtype}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage{enumerate}
\usepackage[shortlabels]{enumitem}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{tasks}
\usepackage{graphicx}
\usepackage{float}
\usepackage[margin=1.5cm ]{geometry}
\usepackage[most]{tcolorbox}
\usepackage{indentfirst}
\usepackage{eqparbox, ulem}
\usepackage{lipsum}
\usepackage[colorlinks=true]{hyperref}
\hypersetup{allcolors=magenta}

\everymath{\displaystyle}

\newcounter{theeq} 
\counterwithin{theeq}{chapter}
\setcounter{theeq}{0}

\newcommand{\eq}{ 
    \
    
    \noindent 
    \refstepcounter{theeq}\textbf{\thechapter.\arabic{theeq}}. }
%%%%%%%%%%%%%%%%%
\begin{document}

\chapter{test1}
\lipsum[2]

\section{test1.1}\label{test1.1}
\lipsum[3]

\begin{center}
    \Large{Problems - \hyperlink{section.\thesection}{Section \thesection}}
\end{center}

\eq Let \(x \in R\)

\eq xx

\section{test1.2}
\lipsum[3]

\begin{center}
    \Large{Problems - \hyperlink{section.\thesection}{Section \thesection}}
\end{center}

\eq Let \(x \in R\)

\eq xx

\section{test1.3}
\lipsum[3]

\begin{center}
    \Large{Problems - \hyperlink{section.\thesection}{Section \thesection}}
\end{center}

\eq Let \(x \in R\)

\eq xx


\chapter{test2}
\lipsum[3]

\section{test2.1}

\begin{center}
    \Large{Problems - \hyperlink{section.\thesection}{Section \thesection}}
\end{center}

\eq Let \(x \in R\)

\eq \(\lim_{x\to 0} \frac{1}{x}\)

\chapter{test3}

\section{test3.1}

\begin{center}
    \Large{Problems - \hyperlink{section.\thesection}{Section \thesection}}
\end{center}

\eq Let \(x \in R\)

\eq xx

\end{document}

相关内容