我是 LaTeX 新手,有一个问题。
有人能告诉我如果想要在 LaTeX 中添加更多标题该怎么办吗?比如 5 个、10 个甚至 15 个。有相应的软件包吗?
答案1
不必太过认真,因为不建议深度编号。不过,这里介绍了如何拥有 100 个分区级别(所有分区级别均以\subsubsection
该级别为蓝本)。
\documentclass[a4paper]{report}
\makeatletter
\newcommand\level[1]{%
\ifcase#1\relax\expandafter\chapter\or
\expandafter\section\or
\expandafter\subsection\or
\expandafter\subsubsection\else
\def\next{\@level{#1}}\expandafter\next
\fi}
\newcommand{\@level}[1]{%
\@startsection{level#1}
{#1}
{\z@}%
{-3.25ex\@plus -1ex \@minus -.2ex}%
{1.5ex \@plus .2ex}%
{\normalfont\normalsize\bfseries}}
\newcounter{level4}[subsubsection]
\@namedef{thelevel4}{\thesubsubsection.\arabic{level4}}
\@namedef{level4mark}#1{}
\count@=4
\loop\ifnum\count@<100
\begingroup\edef\x{\endgroup
\noexpand\newcounter{level\number\numexpr\count@+1\relax}[level\number\count@]
\noexpand\@namedef{thelevel\number\numexpr\count@+1\relax}{%
\noexpand\@nameuse{thelevel\number\count@}.\noexpand\arabic{level\number\numexpr\count@+1\relax}}
\noexpand\@namedef{level\number\numexpr\count@+1\relax mark}####1{}}
\x
\advance\count@\@ne
\repeat
\makeatother
\setcounter{secnumdepth}{100}
\begin{document}
\level{0}{abc}
\level{1}{abc}
\level{2}{abc}
\level{3}{abc}
\level{4}{abc}
\level{5}{abc}
\level{6}{abc}
\level{7}{abc}
\level{8}{abc}
\level{9}{abc}
\level{10}{abc}
\level{11}{abc}
\level{12}{abc}
\end{document}
命令\level{0}
、\level{1}
、\level{2}
和与、、和\level{3}
含义相同。\chapter
\section
\subsection
\subsubsection
添加
如果您还想安排目录,这里有一种方法。
\documentclass[a4paper]{report}
\makeatletter
\newcommand\level[1]{%
\ifcase#1\relax\expandafter\chapter\or
\expandafter\section\or
\expandafter\subsection\or
\expandafter\subsubsection\else
\def\next{\@level{#1}}\expandafter\next
\fi}
\newcommand{\@level}[1]{%
\@startsection{level#1}
{#1}
{\z@}%
{-3.25ex\@plus -1ex \@minus -.2ex}%
{1.5ex \@plus .2ex}%
{\normalfont\normalsize\bfseries}}
\newdimen\@leveldim
\newdimen\@dotsdim
{\normalfont\normalsize
\sbox\z@{0}\global\@leveldim=\wd\z@
\sbox\z@{.}\global\@dotsdim=\wd\z@
}
\newcounter{level4}[subsubsection]
\@namedef{thelevel4}{\thesubsubsection.\arabic{level4}}
\@namedef{level4mark}#1{}
\def\l@section{\@dottedtocline{1}{0pt}{\dimexpr\@leveldim*4+\@dotsdim*1+6pt\relax}}
\def\l@subsection{\@dottedtocline{2}{0pt}{\dimexpr\@leveldim*5+\@dotsdim*2+6pt\relax}}
\def\l@subsubsection{\@dottedtocline{3}{0pt}{\dimexpr\@leveldim*6+\@dotsdim*3+6pt\relax}}
\@namedef{l@level4}{\@dottedtocline{4}{0pt}{\dimexpr\@leveldim*7+\@dotsdim*4+6pt\relax}}
\count@=4
\def\@ncp#1{\number\numexpr\count@+#1\relax}
\loop\ifnum\count@<100
\begingroup\edef\x{\endgroup
\noexpand\newcounter{level\@ncp{1}}[level\number\count@]
\noexpand\@namedef{thelevel\@ncp{1}}{%
\noexpand\@nameuse{thelevel\@ncp{0}}.\noexpand\arabic{level\@ncp{1}}}
\noexpand\@namedef{level\@ncp{1}mark}####1{}%
\noexpand\@namedef{l@level\@ncp{1}}%
{\noexpand\@dottedtocline{\@ncp{1}}{0pt}{\the\dimexpr\@leveldim*\@ncp{5}+\@dotsdim*\@ncp{0}\relax}}}%
\x
\advance\count@\@ne
\repeat
\makeatother
\setcounter{secnumdepth}{100}
\setcounter{tocdepth}{100}
\begin{document}
\tableofcontents
\level{0}{abc}\thispagestyle{empty}
\level{1}{abc}
\level{2}{abc}
\level{3}{abc}
\level{4}{abc}
\level{5}{abc}
\level{6}{abc}
\level{7}{abc}
\level{8}{abc}
\level{9}{abc}
\level{10}{abc}
\level{11}{abc}
\level{12}{abc}
\end{document}
然而我无法忍受看到这个结果。
答案2
如果您是 LaTeX 新手,并且需要进行复杂的分段,您可能需要查看 ConTeXt。除非您使用的是 MikTeX 或旧的 TeX Live,否则它应该可以立即使用,只需运行context yourfile.tex
或texexec yourfile.tex
在下面的示例上运行:
\setupcolors[state=start]
\usemodule[subsub]
\setuphead[section][color=red,style=\bfc]
\setuphead[subsection][color=blue,style=\bfb]
\setuphead[subsubsection][style=\bfa]
\setuphead[subsubsubsection][style=bold]
\starttext
\section{first section}
\subsection{a}
\subsubsection{b}
\subsubsubsection{c}
\subsubsubsubsection{d}
\subsubsubsubsubsection{e}
\subsubsubsubsubsubsection{f}
\subsubsubsubsubsubsubsection{g}
\subsubsubsubsubsubsubsubsection{h}
\subsubsubsubsubsubsubsubsubsection{i}
\stoptext
定义\usemodule[subsub]
了一些额外的级别,但您也可以轻松定义和配置自己的级别(就分段而言,pdfTeX 和基于 LuaTeX 的 ConTeXt 之间略有不同,因此我没有提供任何更具体的示例,但如果需要,我可以提供更多详细信息)。如果您想提供不同于的标题\section
,您可以使用
\definehead[myniceheading][section]
\setuphead[myniceheading][color=darkgreen,style=\bib,alternative=middle,number=no]
\myniceheading{Some heading}
答案3
我找到了一个可能的解决方案 - 对于任何遇到与我同样问题的人:
http://www-mobile.ecs.soton.ac.uk/scripts/viewvc.cgi/yja02r/thesis/packages/subsections.sty?view=co
新的 .sty 文件可能包含无限数量的标题
%% How can I use \subsubsubsection in Latex, so that I can refer to it and also it appears in the table of contents?
% Here is a style file that you will need to use. It has entries to create subsubsubsection and subsubsubsubsection. If you need more then you should add whatever you need by taking the previous level of sub and adding a "sub" everywhere and change the level indicator {5} to {6}.
% I call this file subsections.sty:
% Here is an example file that worked with this style file:
%
% \documentstyle[subsections]{article}
% \setcounter{secnumdepth}{5}
% \setcounter{tocdepth}{5}
% \begin{document}
% \tableofcontents
% \section{section}
% line 1.
% \subsection{subsection}
% line 2.
% \subsubsection{subsub}
% line 3.
% \subsubsubsection{subsubsub}
% line 4.
% \subsubsubsubsection{subsubsubsub}
% line 5.
% \subsubsubsubsection{subsubsubsub}
% line 6.
% \subsubsubsection{subsubsub}
% line 7.
% \subsubsubsubsection{subsubsubsub}
% line 8.
% \subsubsubsubsection{testing}
% line 9.
% \end{document}
%
\newcounter{subsubsubsection}[subsubsection]
\def\subsubsubsectionmark#1{}
\def\thesubsubsubsection {\thesubsubsection
.\arabic{subsubsubsection}}
\def\subsubsubsection{\@startsection
{subsubsubsection}{4}{\z@} {-3.25ex plus -1
ex minus -.2ex}{1.5ex plus .2ex}{\normalsize\bf}}
% mj02r: original:
%\def\l@subsubsubsection{\@dottedtocline{4}
% {4.8em}{4.2em}}
% mj02r: for VCE reports:
%\def\l@subsubsubsection{\@dottedtocline{4}
% {7em}{3.8em}}
% mj02r, 29/12/2004: for thesis:
\def\l@subsubsubsection{\@dottedtocline{4}
{11.1em}{4.6em}}
\newcounter{subsubsubsubsection}[subsubsubsection]
\def\subsubsubsubsectionmark#1{}
\def\thesubsubsubsubsection {\thesubsubsubsection
.\arabic{subsubsubsubsection}}
\def\subsubsubsubsection{\@startsection
{subsubsubsubsection}{5} {\z@} {-3.25ex plus -1
ex minus -.2ex}{1.5ex plus .2ex}{\normalsize\bf}}
% mj02r: original:
%\def\l@subsubsubsubsection{\@dottedtocline{5}
% {5.8em}{5.2em}}
% mj02r: for VCE reports:
\def\l@subsubsubsubsection{\@dottedtocline{5}
{10.7em}{4.5em}}
我会尝试稍后看一下。
希望它能起作用:)