【问题标题】:LaTeX: creating new section headingsLaTeX:创建新的章节标题
【发布时间】:2014-11-22 19:44:44
【问题描述】:

我想创建一个新部分,例如使用自定义全局计数器的标题。 预期的行为是有一个定义规则的 \rule 命令,可以在多个部分和小节中使用,但使用自定义全局计数器。

例子:

1. Section
1.1 SubSection
Rule 1: bla
Rule 2: foo
2. Section
Rule 3: foobar
2.1 subsection
Rule 4: yet another one

我尝试了两种不同的方法:

1.) 从头开始​​创建自定义命令

\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}}}}

这里的问题是我不知道如何格式化标题,使其表现得像一个节。尤其是在换行时。

应该是:

Rule 1: very long header line
        correctly wrapped

但它看起来像这样:

Rule 1: very long header line
correctly wrapped

标题和以下文本之间的空格也应该正确配置。

2.) 我尝试更改小节以供我使用。

\renewcommand{\rule}[1]{\subsection{#1}}
\renewcommand{\thesubsection}{Rule \arabic{subsection}:}

这既简单又有效,但显然有几个缺点:

  • 计数器会针对每个新部分进行重置,因此它不是全局计数器。
  • 我不能再使用小节了

我认为只有第一个选项是要走的路,但我不知道该怎么做。 我希望任何人都可以在这里提供帮助。

谢谢。

【问题讨论】:

    标签: latex


    【解决方案1】:

    首先,不要重新定义\rule,因为它是其他核心 (La)TeX 功能的组成部分。而是使用 \Rule 之类的东西。

    这是满足您要求的直接实施:

    \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 的副本,具有所有必需的便利设施。

    【讨论】:

      猜你喜欢
      • 2010-10-31
      • 2010-11-26
      • 2011-02-12
      • 1970-01-01
      • 2011-01-19
      • 1970-01-01
      • 2021-08-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多