我认为最好先发布我的代码,然后再问我的问题
\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{lipsum}
\usepackage[T1]{fontenc} % optional
\usepackage{thmtools}
\declaretheoremstyle[%
spaceabove=\topsep,
spacebelow=\topsep,
headfont=\small\normalfont,
bodyfont=\itshape\small,
headpunct={.---},
postheadspace=1em,
headformat=\NAME\space\NUMBER,
headindent= 0pt,
]{remark}
\declaretheorem[style=remark,numberwithin=subsection]{remark}
\renewcommand{\theremark}{\arabic{remark}}
\newcommand\rmk[1]{\textit{Remark} \textup{\ref{#1}}}
\makeatletter
\renewcommand*{\p@section}{\S} %Add section symbol to section reference
\renewcommand*{\p@subsection}{\P} %Add section symbol to section reference
\makeatother
\begin{document}
\section{A}
\lipsum[1]
\subsection{A.1}
\label{a}
\begin{remark}
\label{remark}
\lipsum[2]
\end{remark}
\lipsum[2]
\subsection{A.2}
\begin{remark}
\lipsum[2]
\end{remark}
\lipsum[3]
\section{B}
\lipsum[1]
\subsection{B.1}
As we can see in \ref{a}~\rmk{remark}...
\end{document}
正如您在我的代码中看到的,注释枚举(和其他环境枚举)在每个子节处重新启动。我对此非常满意,但问题是,当我想交叉引用另一个子节中的注释时,我必须通过编写 明确指定子节\ref{sec:stuff}
。
是否可以修改我的命令\rmk
,使其自动包含子节引用?也许可以创建一个新命令来告诉您该环境的当前子节?
答案1
您可以定义\rmk
这样一种方式:仅当引用的备注位于另一个小节中时,才打印该小节的编号。
\documentclass[a4paper,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{xparse}
\usepackage{lipsum}
\declaretheoremstyle[
spaceabove=\topsep,
spacebelow=\topsep,
headfont=\normalfont\itshape\small,
bodyfont=\normalfont\small,
headpunct={.\,---\enspace},
postheadspace=0pt,
headformat=\NAME\space\NUMBER,
headindent= 0pt,
]{remark}
\declaretheorem[style=remark,numberwithin=subsection]{remark}
\renewcommand{\theremark}{\arabic{remark}}
\makeatletter
\renewcommand*{\p@section}{\S} %Add section symbol to section reference
\renewcommand*{\p@subsection}{\P} %Add section symbol to section reference
\renewcommand*{\p@remark}{\perhapssubsection{\thesubsection}}
\makeatother
\newcommand{\rmk}[1]{\textit{Remark}~\textup{\ref{#1}}}
\ExplSyntaxOn
\NewDocumentCommand{\perhapssubsection}{m}
{
\str_if_eq_x:nnF { #1 } { \thesubsection } { #1. }
}
\ExplSyntaxOff
\begin{document}
\section{A}
\lipsum[1]
\subsection{A.1}
\label{a}
\begin{remark}
\label{remark}
\lipsum[2]
\end{remark}
\lipsum[2]
\subsection{A.2}
\begin{remark}
\lipsum[2]
\end{remark}
\lipsum[3]
\section{B}
\lipsum[1]
\subsection{B.1}
\begin{remark}\label{remarkhere}
\lipsum[2]
\end{remark}
As we can see in \rmk{remark}
and in \rmk{remarkhere}
\end{document}
我稍微改变了一下注释的外观:我认为注释的头部应该用斜体,但注释主体应该竖直。这不仅是为了与参考文献保持一致,也是为了不让注释太突出:毕竟,你用的是较小的字体排版。欢迎随时恢复。
答案2
\renewcommand*{\p@remark}{\thesubsection.}
大多数情况下,您需要在序言中添加说明。
您可能还想研究如何加载cleveref
包(及其\cref
宏),以简化和简化一次创建多个交叉引用的过程。请参阅以下屏幕截图的最后一段,了解示例\cref
。
% !TEX TS-program = pdflatex
\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage[T1]{fontenc} % optional
\usepackage{thmtools}
\declaretheoremstyle[%
spaceabove=\topsep,
spacebelow=\topsep,
headfont=\small\normalfont,
bodyfont=\itshape\small,
headpunct={.---},
postheadspace=1em,
headformat=\NAME\space\NUMBER,
headindent= 0pt,
]{remark}
\declaretheorem[style=remark,numberwithin=subsection]
{remark}
\renewcommand{\theremark}{\arabic{remark}}
\newcommand\rmk[1]{\textit{Remark}~\textup{\ref{#1}}}
\newcommand\blurb{Nam dui ligula, fringilla a, euismod sodales,
sollicitudin vel, wisi. Morbi auctor lorem non justo. Nam
lacus libero, pretium at, lobortis vitae, ultricies et, tellus.}
\makeatletter
\renewcommand*{\p@section}{\S}
\renewcommand*{\p@subsection}{\P}
\renewcommand*{\p@remark}{\thesubsection.} % <--- new
\makeatother
\usepackage{cleveref}
\crefname{remark}{\textit{Remark}}{\textit{Remarks}}
\begin{document}
\section{Bla bla bla}
\subsection{Ble ble ble}
\begin{remark} \label{remark_e}
\blurb
\end{remark}
\subsection{Bli bli bli}
\begin{remark} \label{remark_i}
\blurb
\end{remark}
\section{Blo blo blo}
\subsection{Blu blu blu}
As we can see in \rmk{remark_e} as well as in \rmk{remark_i}, \dots
\bigskip\noindent
As we can see in \cref{remark_e,remark_i}, \dots
\end{document}