我正在为学校创建一份文档,我需要遵循特定的编号格式 - 即:“1”,然后是“1.”,然后是“1.1”等等。我是 Latex 和 Lyx 的初学者,还没有找到以这种特定方式(或以足够简单的方式)执行此操作的方法。我应该使用一些软件包吗?有没有什么前言?或者我必须手动执行此操作?
预先感谢您的帮助。
编辑 1:发布 MWE。我正在使用文章文档类,手动更改章节编号,使其从 0 开始。代码:
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\setcounter{section}{-1}
\makeatother
\usepackage{babel}
\begin{document}
\title{Title}
\author{John Doe}
\maketitle
\section{Preface}
\section{Characteristics}
\section{Division}
\subsection{Group A}
\subsubsection{A}
\subsubsection{B}
\paragraph{B1}
\section{Conclusion}
\end{document}
答案1
一个强力解决方案是运行
\renewcommand\thesubsection{\arabic{subsection}.}
\renewcommand\thesubsubsection{\thesubsection\arabic{subsubsection}.}
\renewcommand\theparagraph{\thesubsubsection\arabic{paragraph}.}
不幸的是,如果您需要交叉引用小节、小节和段落级别的单元,这将产生不必要的问题。因此,我建议您采取以下间接或“谨慎”的方法。几年前,我在阅读《The LaTeX Companion》(第 2 版)一书时采用了这种方法。
\documentclass[english]{article}
\usepackage[T1]{fontenc}
%\usepackage[latin9]{inputenc} %% Are you absolutely sure about 'latin9'?!
\usepackage{babel}
\setcounter{secnumdepth}{4} % default is '3'
\setcounter{tocdepth}{4}
%% Brute-force method:
%\renewcommand\thesubsection{\arabic{subsection}.}
%\renewcommand\thesubsubsection{\thesubsection\arabic{subsubsection}.}
%\renewcommand\theparagraph{\thesubsubsection\arabic{paragraph}.}
%% Circumspect method:
\makeatletter
% the next 4 lines are straight from "The LaTeX Companion", 2nd ed.
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
{\csname the#1\endcsname\quad} % default
{\csname #1@cntformat\endcsname} % enable individual control
}
\renewcommand\thesubsection{\arabic{subsection}}
\newcommand{\subsection@cntformat}{\thesubsection.\quad}
\newcommand{\subsubsection@cntformat}{\thesubsubsection.\quad}
\newcommand{\paragraph@cntformat}{\theparagraph.\quad}
\makeatother
\begin{document}
\setcounter{section}{-1}
\section{Preface}
\section{Characteristics}
\section{Division}
\subsection{Group A}
\subsubsection{A} \label{sec:A}
\subsubsection{B} \label{sec:B}
\paragraph{B1} \label{sec:B1}
\section{Conclusion}
Cross-references to subsubsections \ref{sec:A} and \ref{sec:B}
and to parapraph \ref{sec:B1}.
\end{document}