答案1
答案2
如果您使用KOMA-Script
文档类(可以很好地替代标准类,如article
)report
,这些问题将为您提供一些如何重现标题的线索:
标题栏可根据包进行定制scrlayer-scrpage
。
代码如下:
\documentclass[DIV=10]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage{scrlayer-scrpage}
\usepackage{expl3}
\usepackage{blindtext} % dummy text
\usepackage{mdframed}
\makeatletter
\ExplSyntaxOn
\bool_new:N \l_processed_bool
% redefine section title
\renewcommand{\sectionlinesformat}[4]{
\bool_set_false:N \l_processed_bool
\str_if_eq:nnT {#1} {section} {
\begin{mdframed}[leftline=false, rightline=false, linewidth=0.8pt, innertopmargin=5mm, innerbottommargin=5mm, leftmargin=1cm, rightmargin=1cm]
\centering\@hangfrom{\hskip #2}{#4}\par
\end{mdframed}
\bool_set_true:N \l_processed_bool
}
\bool_if:nT {!\l_processed_bool} {
% use default style
\@hangfrom{\hskip #2#3}{#4}
}
}
% redefine chapter title
\renewcommand{\chapterlinesformat}[3]{
\bool_set_false:N \l_processed_bool
\str_if_eq:nnT {#1} {chapter} {
\begin{center}
Chapter~#2
\end{center}
\vspace*{-6mm} % reduce spacing
\bool_set_true:N \l_processed_bool
}
\bool_if:nT {!\l_processed_bool} {
% use default style
\@hangfrom{#2}{#3}
}
}
\tl_new:N \l_section_number_tl
% by default, the section numering is chapter.section
% we need to delete the chapter index here
\cs_set:Npn \fix_section_number:n #1 {
\tl_set:Nx \l_section_number_tl {#1}
\regex_replace_once:nnN {[0-9]+\.} {} \l_section_number_tl
}
% change chapter font
\addtokomafont{chapter}{\normalfont\Large\itshape}
% set header
\chead{}
\renewcommand{\sectionmark}[1]{
\fix_section_number:n{\thesection}
\markright{\l_section_number_tl .\ #1}
}
\ohead{\scshape \rightmark}
\ihead{\pagemark}
% disable page number
\cfoot{}
% activate head sep line
\KOMAoption{headsepline}{0.5pt}
% suppress page numbering on chapter start pages
\let\oldchapter\chapter
\RenewDocumentCommand{\chapter}{om}{
\IfValueTF{#1}{
\oldchapter[#1]{#2}
}{
\oldchapter{#2}
}
\thispagestyle{empty}
}
\ExplSyntaxOff
\makeatother
\begin{document}
\chapter{Some Chapter}
\section{Introduction}
\Blindtext[9]
\section{More Introduction}
\Blindtext[8]
\end{document}
更新
如果您想修改小节样式,您可以修改\sectionlinesformat
。除目录外,所有内容均正常运行 - 需要做更多工作来纠正它。
\documentclass[DIV=10]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage{scrlayer-scrpage}
\usepackage{expl3}
\usepackage{blindtext} % dummy text
\usepackage{mdframed}
\makeatletter
\ExplSyntaxOn
\bool_new:N \l_processed_bool
\tl_new:N \l_section_number_tl
% by default, the section numering is chapter.section
% we need to delete the chapter index here
\cs_set:Npn \fix_section_number:n #1 {
\tl_set:Nx \l_section_number_tl {#1}
\regex_replace_once:nnN {[0-9]+\.} {} \l_section_number_tl
}
% redefine section title
\renewcommand{\sectionlinesformat}[4]{
\bool_set_false:N \l_processed_bool
\str_if_eq:nnT {#1} {section} {
\begin{mdframed}[leftline=false, rightline=false, linewidth=0.8pt, innertopmargin=5mm, innerbottommargin=5mm, leftmargin=1cm, rightmargin=1cm]
\centering\@hangfrom{\hskip #2}{#4}\par
\end{mdframed}
\bool_set_true:N \l_processed_bool
}
\str_if_eq:nnT {#1} {subsection} {
\fix_section_number:n {#3}
\@hangfrom{\hskip #2\l_section_number_tl}{#4}
\bool_set_true:N \l_processed_bool
}
\bool_if:nT {!\l_processed_bool} {
% use default style
\@hangfrom{\hskip #2#3}{#4}
}
}
% redefine chapter title
\renewcommand{\chapterlinesformat}[3]{
\bool_set_false:N \l_processed_bool
\str_if_eq:nnT {#1} {chapter} {
\begin{center}
Chapter~#2
\end{center}
\vspace*{-6mm} % reduce spacing
\bool_set_true:N \l_processed_bool
}
\bool_if:nT {!\l_processed_bool} {
% use default style
\@hangfrom{#2}{#3}
}
}
% change chapter font
\addtokomafont{chapter}{\normalfont\Large\itshape}
% set header
\chead{}
\renewcommand{\sectionmark}[1]{
\fix_section_number:n{\thesection}
\markright{\l_section_number_tl .\ #1}
}
\ohead{\scshape \rightmark}
\ihead{\pagemark}
% disable page number
\cfoot{}
% activate head sep line
\KOMAoption{headsepline}{0.5pt}
% suppress page numbering on chapter start pages
\let\oldchapter\chapter
\RenewDocumentCommand{\chapter}{som}{
\IfValueTF{#2}{
\IfBooleanTF{#1}{
\oldchapter*[#2]{#3}
} {
\oldchapter[#2]{#3}
}
}{
\IfBooleanTF{#1}{
\oldchapter*{#3}
} {
\oldchapter{#3}
}
}
\thispagestyle{empty}
}
\ExplSyntaxOff
\makeatother
\begin{document}
\chapter{Some Chapter}
\section{Introduction}
\subsection{Subsection}
\Blindtext[9]
\section{More Introduction}
\Blindtext[8]
\end{document}