![文本中出现的子节标签](https://linux22.com/image/296750/%E6%96%87%E6%9C%AC%E4%B8%AD%E5%87%BA%E7%8E%B0%E7%9A%84%E5%AD%90%E8%8A%82%E6%A0%87%E7%AD%BE.png)
我有一份“书籍”格式的文档(严格地说,是在我使用的图书出版商定义的环境中,其细节远远超出了我的理解范围),我非常希望某些段落的标签与定理、引理等的标签具有相同的运行计数,但文本中的数字标签以粗体显示,并且不是踏上自己的路线。
例如,在第 2 章第 2.3 节中的定理 2.3.7 和定理 2.3.9 之间,我希望能够将我选择的中间段落以粗体(普通字体)的“2.3.8”或粗体(普通字体)的“2.3.8 Blah-blah”开头。对于此命令来说,允许使用\label
与该数字标签“2.3.8”关联的命令进行交叉引用也非常重要。
为了增加解决方案被图书出版商使用的机会(其排版人员无法向我提供解决方案),请尝试使答案尽可能简单。
虽然我无法在这里重现出版商的专有信息documentclass
(它太大了,我难以理解),但这里有一个测试.tex
文件,我根据下面的评论尝试使用命令 \paragraph:
\documentclass{book}
\begin{document}
\chapter{A class of groups}
Let $G$ be a group.
\section{A class of subgroups}
Let $H$ be a subgroup.
\paragraph{Refinements}\label{refined} This can be refined.
In \ref{refined} we saw something.
\end{document}
我得到的输出结果没有在“Refinements”前面出现任何数字标签,而末尾对它的交叉引用产生了该部分的数字标签,因此它失败了。我希望该带标签的段落以粗体“1.1.1. Refinements”开头,末尾的交叉引用应显示为“In 1.1.1 we saw something”。
我还应该指出,一个版本(很久以前从一个我不记得的来源给我的)做在环境中工作amsart
,其中层次结构移动一个:不是\chapter
,\section
,\subsection
而是\section
,\subsection
,\subsubsection
,并且以下内容完全给出了我所寻求的子小节(但出版商告诉我他们无法改编它;嗯,也许我应该特别要求他们尝试用下面的“小节”替换“小节”,以防他们没有尝试过?)。
\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
{\csname the#1\endcsname\quad}% default
{\csname #1@cntformat\endcsname}% individual control
}
\def\subsubsection@cntformat{{\rm{\textbf{\thesubsubsection.}}}}
\makeatother
答案1
定义一个新的定理环境。
\documentclass{book}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}[section]
\theoremstyle{definition}
\newtheorem{interthm}[thm]{\ignorespaces}% theorem label is empty
\begin{document}
\chapter{A class of groups}
Let $G$ be a finite group.
\section{A class of subgroups}
Let $H$ be a subgroup of $G$.
\begin{thm}\label{lagrange}
The order of $H$ divides the order of $G$.
\end{thm}
\begin{interthm}\label{lagrange-comment}
Theorem~\ref{lagrange} is credited to Lagrange and can be
inverted for abelian groups.
\end{interthm}
\begin{thm}\label{inverse-lagrange}
If $G$ is abelian and $k$ is a divisor of the order
of $G$, then $G$ has a subgroup of order $k$.
\end{thm}
In \ref{lagrange-comment} we saw something.
\end{document}
您可以使用技巧将其变成命令\everypar
;仅在外部层面使用它。
\documentclass{book}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}[section]
\newcommand{\interthm}{%
\par\refstepcounter{thm}%
\everypar{{\setbox0=\lastbox}\textbf{\thethm.} \everypar{}}%
}
\begin{document}
\chapter{A class of groups}
Let $G$ be a finite group.
\section{A class of subgroups}
Let $H$ be a subgroup of $G$.
\begin{thm}\label{lagrange}
The order of $H$ divides the order of $G$.
\end{thm}
\interthm\label{lagrange-comment}
Theorem~\ref{lagrange} is credited to Lagrange and can be
inverted for abelian groups.
\begin{thm}\label{inverse-lagrange}
If $G$ is abelian and $k$ is a divisor of the order
of $G$, then $G$ has a subgroup of order $k$.
\end{thm}
In \ref{lagrange-comment} we saw something.
\end{document}
请注意,在这种情况下,编号段落下方无法自动设置额外的垂直空间。
答案2
\intertheoremremark
这提供了一个名为“类似于”的 环境paragraph
(当然,它根本不是一个环境),只是带有一个subsection
类似的标签和一个粗体字体标题引导。\label
适用于此。
这使用了一个assoccnt
包,它提供了一个主计数器,当步进时,驱动其他计数器,在本例中是mytheorem
计数器。
然而,主计数器不能由主计数器驱动的另一个计数器驱动。
\documentclass{scrbook}
\usepackage{blindtext}
\usepackage{amsmath}
\usepackage{amsthm}%
\usepackage{assoccnt}%
\newcounter{intertheoremremark}
\renewcommand{\theintertheoremremark}{\thesection.\arabic{intertheoremremark}}
\newenvironment{intertheoremremark}[2][]{%
\setcounter{intertheoremremark}{\number\value{mytheorem}}%
\setlength{\parindent}{0pt}%
\refstepcounter{intertheoremremark}%
\large \textbf{\theintertheoremremark~#2}~
}{}%
\newtheorem{mytheorem}{Theorem}
\renewcommand{\themytheorem}{\thesection.\arabic{mytheorem}}
\DeclareAssociatedCounters{intertheoremremark}{mytheorem}%
\begin{document}
\chapter{Number one}
\section{First section}
\blindtext
\section{Second section}
\blindtext
\begin{mytheorem}{On Brontosaurs} \label{theorem::brontosaurs}
\blindtext
\end{mytheorem}
\begin{intertheoremremark}{Remarks to Theorem \ref{theorem::brontosaurs}} \label{firstremark}%
\blindtext
\end{intertheoremremark}%
\begin{mytheorem}{Other theory on Brontosaurs} \label{theorem::brontosaurs2}
\blindtext
\end{mytheorem}
\begin{intertheoremremark}{Remarks to Theorem \ref{theorem::brontosaurs2}}%
This is a follow up remark to \ref{firstremark}
\blindtext
\end{intertheoremremark}%
\end{document}
编辑
我应该补充一下,我是这个软件包的作者assoccnt
,这个软件包目前仍处于初级版本,可在 CTAN 和 TeXlive 2014 上使用
已更新版本并附\paragraph
加到mytheorem
等。
这不使用assoccnt
包,而是使用paragraph
环境intertheoremremark
。的行为stepcounter
略有变化,如assoccnt would do
。屏幕截图与上面的版本几乎相同。
\documentclass{book}
\usepackage{etoolbox}%
\usepackage{blindtext}
\usepackage{amsmath}
\usepackage{amsthm}%
\usepackage{remreset}%
\newtheorem{mytheorem}{Theorem}%
\makeatletter
\@removefromreset{paragraph}{subsubsection}
\@addtoreset{paragraph}{chapter}%
\@addtoreset{mytheorem}{chapter}%
\makeatother
\setcounter{secnumdepth}{4}%
\let\standardstepcounter\stepcounter
\renewcommand{\stepcounter}[1]{%
\ifstrequal{#1}{paragraph}{%
\standardstepcounter{mytheorem}%
}{ \ifstrequal{#1}{mytheorem}{%
\standardstepcounter{paragraph}%
}{}}%
\standardstepcounter{#1}%
}%
\renewcommand{\themytheorem}{\thesection.\arabic{mytheorem}}
\renewcommand{\theparagraph}{\thesection.\arabic{paragraph}.}%
\begin{document}
\chapter{Number one}
\section{First section}
\blindtext
\section{Second section}
\blindtext
\begin{mytheorem}{On Brontosaurs} \label{theorem::brontosaurs}
\blindtext
\end{mytheorem}
\paragraph{Remarks to Theorem \ref{theorem::brontosaurs}} \label{firstremark}%
\blindtext
\begin{mytheorem}{Other theory on Brontosaurs} \label{theorem::brontosaurs2}
\blindtext
\end{mytheorem}
\paragraph{Remarks to Theorem \ref{theorem::brontosaurs2_again}}%
This is a follow up remark to \ref{secondremark}%
\blindtext
\chapter{Number Two}
\section{First section}
\blindtext
\section{Second section}
\blindtext
\begin{mytheorem}{On Brontosaurs} \label{theorem::brontosaurs_again}
\blindtext
\end{mytheorem}
\paragraph{Remarks to Theorem \ref{theorem::brontosaurs_again}} \label{secondremark}%
\blindtext
\begin{mytheorem}{Other theory on Brontosaurs} \label{theorem::brontosaurs2_again}
\blindtext
\end{mytheorem}
\paragraph{Remarks to Theorem \ref{theorem::brontosaurs2}}%
This is a follow up remark to \ref{firstremark}
\blindtext
\end{document}