2014-11-22 75 views
1

我想創建一個新的部分,如使用自定義全局計數器的標題。 預期的行爲是有一個定義規則的\ 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}:} 

這是很簡單的工作,但具有明顯的幾個缺點:

  • 櫃檯獲取每個新節復位,所以它不是一個全局計數器。
  • 我不能使用小節了

我認爲只有第一個選項是要走的路,但我不知道怎麼辦。 我希望有人能幫到這裏。

Thx。

回答

1

首先,不要重新定義\rule,因爲它構成了其他核心(La)TeX功能的組成部分。而是使用類似\Rule

下面是您要求的直觀的實現:

enter image description here

\documentclass{article} 

\makeatletter 
\newcommand\Rule{\@startsection {Rule}{1}{\[email protected]}% 
           {-3.5ex \@plus -1ex \@minus -.2ex}% 
           {2.3ex \@plus.2ex}% 
           {\normalfont\Large\bfseries}} 
\newcommand{\Rulemark}[1]{} 
\newcounter{Rule} 
\let\[email protected]\[email protected] 
\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一個副本,其中所有需要的設施。