章节和小节的格式

章节和小节的格式

我是 Latex 新手,我希望章节、小节和小节采用以下格式样式

在此处输入图片描述

我正在使用以下代码来表示部分。输出中罗马数字后面缺少一个点。另外,我不确定如何使用子部分和子子部分。

  \titleformat{\section}
  {\normalfont\Large\centering}{%
    {\normalfont\thesection}
  }{1em}{}
  \renewcommand\thesection{\Roman{section}}

请帮忙

答案1

如果您使用的是标准文档类,调整章节标题外观的常用方法是使用 titlesec 包。我在下面提供了或多或少符合您要求的代码,并添加了注释,以便您了解每个代码的作用。

\documentclass{article}

% load the package; make centered titles default
\usepackage[center]{titlesec}

% use Roman numerals for sections
\renewcommand{\thesection}{\Roman{section}}

% use Arabic numerals for subsections
\renewcommand{\thesubsection}{\arabic{subsection}}

% use letters for subsubsections with a parenthesis
\renewcommand{\thesubsubsection}{\alph{subsubsection})}

% put a period and space after numbers
\titlelabel{\thetitle.\thickspace}

% Make section titles centered and bold
\titleformat*{\section}{\centering\bfseries}

% Make subsections centered and italc
\titleformat*{\subsection}{\centering\itshape}

% Make subsubsections centered
\titleformat*{\subsubsection}{\centering}

\usepackage{lipsum}% provides dummy text; not needed for solution

\begin{document}

\section{This is a Headline}

\lipsum[1][1-4]

\lipsum[1][5-6]

\subsection{This is a Subheadline}

\lipsum[2][1-4]

\lipsum[2][5-8]

\subsubsection{This is a Subsubheadline}

\lipsum[3][1-5]

\lipsum[3][6-8]

\end{document}

titlesec 示例

该软件包还提供了更复杂的命令。请参阅其文档

我还注意到,在您的示例中,标题后的第一个段落仍然缩进,这与 LaTeX 的正常行为不同。该软件包还允许您更改该行为。您可以将其添加到序言中:

% change spacing: not using * means indentation will not be
% suppressed
\titlespacing{\section}{0pt}{*4}{*1.5}
\titlespacing{\subsection}{0pt}{*4}{*1.5}
\titlespacing{\subsubsection}{0pt}{*4}{*1.5}

产量:

没有缩进

再次,文档中有更多详细信息。

编辑:我刚刚注意到,在你原来的小节中,句号在括号之前。这让事情变得复杂,因为你不能\titlelabel一致地使用。在这种情况下,你必须使用没有星号的版本,\titleformat它提供了更细粒度的控制:

\documentclass{article}

\usepackage[center]{titlesec}

% use Roman numerals for sections
\renewcommand{\thesection}{\Roman{section}}

% use Arabic numerals for subsections
\renewcommand{\thesubsection}{\arabic{subsection}}

% use letters for subsubsections with a parenthesis
\renewcommand{\thesubsubsection}{\alph{subsubsection}}

% Make section titles centered and bold
\titleformat%
    {\section}% command to format
    [block]% overall shape: see documentation
    {\centering\bfseries}% formatting applie to whole thing
    {\thesection.}% format of number label
    {0.5em}% spacing between number label and title
    {}% additional code before title

\titleformat%
    {\subsection}% command to format
    [block]% overall shape: see documentation
    {\centering\itshape}% formatting applie to whole thing
    {\thesubsection.}% format of number label
    {0.5em}% spacing between number label and title
    {}% additional code before title

\titleformat%
    {\subsubsection}% command to format
    [block]% overall shape: see documentation
    {\centering}% formatting applie to whole thing
    {\thesubsubsection.)}% format of number label
    {0.5em}% spacing between number label and title
    {}% additional code before title

\usepackage{lipsum}% provides dummy text; not needed for solution

% change spacing: not using * means indentation will not be
% suppressed
\titlespacing{\section}{0pt}{*4}{*1.5}
\titlespacing{\subsection}{0pt}{*4}{*1.5}
\titlespacing{\subsubsection}{0pt}{*4}{*1.5}

\begin{document}

\section{This is a Headline}

\lipsum[1][1-4]

\lipsum[1][5-6]

\subsection{This is a Subheadline}

\lipsum[2][1-4]

\lipsum[2][5-8]

\subsubsection{This is a Subsubheadline}

\lipsum[3][1-5]

\lipsum[3][6-8]

\end{document}

替代小节

答案2

这是一个采用教派包来确定如何显示节标题(例如,居中、粗体/非粗体等)。它进一步使用低级\@seccntformat宏来显示如何显示节标题的数字/字母。

在此处输入图片描述

\documentclass{article}
\usepackage[T1]{fontenc}

% First, set the way subsub/sub/sections are numbered:
\renewcommand\thesection{\Roman{section}}
\renewcommand\thesubsection{\arabic{subsection}}
\renewcommand\thesubsubsection{\alph{subsubsection}}

% Use method proposed in "The LaTeX Companion", 2nd ed., to determine
% how the section-like counters are displayed in sectioning headers
\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
    {\csname the#1\endcsname\space}%    default
    {\csname #1@cntformat\endcsname}}%  enable individual control
\newcommand\section@cntformat{\thesection.\quad}       % section
\newcommand\subsection@cntformat{\thesubsection.\quad} % subsection
\newcommand\subsubsection@cntformat{\thesubsubsection.)\space} % subsubsection
\makeatother

% Finally, control the way sectioning headers are displayed
\usepackage{sectsty}
\sectionfont{\centering\normalsize\bfseries}
\subsectionfont{\centering\normalsize\mdseries\itshape}
\subsubsectionfont{\centering\normalsize\mdseries\upshape}

% Optional: Load `hyperref` package.
\usepackage[colorlinks,allcolors=red]{hyperref}

\begin{document}
\section{This is a Headline}       \label{sec:Head}
\subsection{This is a Headline}    \label{subsec:Head}
\subsubsection{This is a Headline} \label{subsubsec:Head}

Cross-references to section \ref{sec:Head}, subsection \ref{subsec:Head}, and subsubsection \ref{subsubsec:Head}.
\end{document}

相关内容