LaTeX:创建新的节标题 [英] LaTeX: creating new section headings
问题描述
我想使用自定义全局计数器创建一个新的部分,例如标题. 预期的行为是使用\ rule命令定义一条规则,该规则可以在多个部分和小节中使用,但使用自定义全局计数器.
I want to create a new section like heading using a custom global counter. The intended behaviour is to have a \rule command which defines a rule, that can be used in several sections and subsection, but uses a custom global counter.
示例:
1. Section
1.1 SubSection
Rule 1: bla
Rule 2: foo
2. Section
Rule 3: foobar
2.1 subsection
Rule 4: yet another one
我尝试了两种不同的方法:
I tried two different things:
1.)从头开始创建自定义命令
1.) create a custom command from scratch
\newcounter{rule}
\addtocounter{rule}{0} % set them to some other numbers than 0
\renewcommand{\rule}[1]{{\noindent\normalfont\Large\bfseries{Rule \arabic{rule}:
#1 \addcontentsline{toc}{section}{Rule \arabic{rule}: #1}\newline\stepcounter{rule}}}}
这里的问题是我不知道如何格式化标题,以使其表现得像节.尤其是当行被包裹起来时.
The problem here is that I don't know how to format the heading so that it behaves like a section. Especially when the line gets wrapped.
应该是:
Rule 1: very long header line
correctly wrapped
但它看起来像这样:
Rule 1: very long header line
correctly wrapped
标题和以下文本之间的空格也应正确配置.
Also the space between heading and the following text is something that should be configured correctly.
2.)我尝试更改小节以供使用.
2.) I tried to change subsection for my use.
\renewcommand{\rule}[1]{\subsection{#1}}
\renewcommand{\thesubsection}{Rule \arabic{subsection}:}
这很容易并且可行,但是显然有一些缺点:
This is easy and works, but has obviously several drawbacks:
- 每个新部分的计数器都会重置,因此它不是全局计数器.
- 我不能再使用小节
我认为唯一的选择就是走的路,但是我不知道怎么走. 我希望任何人都可以在这里提供帮助.
I think only the first option is the way to go, but I don't know how. I hope anybody can help here.
谢谢.
推荐答案
首先,不要重新定义\rule
,因为它构成了其他核心(La)TeX功能的组成部分.宁可使用\Rule
之类的东西.
First of all, don't redefine \rule
, as it forms an integral part of other core (La)TeX functionality. Rather use something like \Rule
.
这是您要求的简单实现:
Here's a straight-forward implementation for your requirements:
\documentclass{article}
\makeatletter
\newcommand\Rule{\@startsection {Rule}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\normalfont\Large\bfseries}}
\newcommand{\Rulemark}[1]{}
\newcounter{Rule}
\let\l@Rule\l@section
\begin{document}
\tableofcontents
\section{Section}
\subsection{Subsection}
\Rule{bla}
\Rule{foo}
\section{Section}
\Rule{foobar}
\subsection{Subsection}
\Rule{yet another one}
\end{document}
上述\Rule
的设置是\section
的副本,具有所有必需的便利设施.
The above setup of \Rule
is a copy of \section
, with all the required amenities.
这篇关于LaTeX:创建新的节标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!