我是 Latex 的新手,我正在使用titlesec
它来格式化章节标题titlesec
。
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\bfseries\huge}
{\filleft\Large\chaptertitlename~\thechapter}
{1ex}
{\titlerule\vspace{1.5ex}\filright}
[\vspace{1ex}\titlerule]
但我没有正确获取章节标题。我只获取纯文本。
我创建了一个小型的 MME
\documentclass{scrbook}
\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}
\usepackage{graphicx}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\bfseries\huge}
{\filleft\Large\chaptertitlename~\thechapter}
{1ex}
{\titlerule\vspace{1.5ex}\filright}
[\vspace{1ex}\titlerule]
\begin{document}
\chapter{Introduction}
\label{ch:Introduction}
\end{document}
答案1
请勿titlesec
与 KOMA-Script 类一起使用。
使用 KOMA 版本 3.19 或更新版本,可以通过重新定义以下内容插入标题规则\chapterlineswithprefixformat
:
\newcommand\titlerule[1][.4pt]{\rule[.5\baselineskip]{\textwidth}{#1}}
\renewcommand\chapterlineswithprefixformat[3]{%
{\raggedleft#2}\nobreak%
\ifstr{#2}{}{\kern-.5\baselineskip}{}%
\titlerule\\*%
\kern-.5ex%
#3\par\nobreak%
\kern1.75ex%
\titlerule%
}
要更改章节标题之前和之后的跳过以及章节前缀和标题之间的跳过,您可以使用RedeclareSectionCommand
。
\documentclass[
headings=chapterprefix
]{scrbook}[2015/10/03]
\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}
\addtokomafont{chapterprefix}{\Large}
\addtokomafont{disposition}{\rmfamily}
\RedeclareSectionCommand[%
beforeskip=\dimexpr4.6\baselineskip+\parskip\relax,
innerskip=0pt,
afterskip=1.5\baselineskip plus .115\baselineskip minus .192\baselineskip
]{chapter}
\newcommand\titlerule[1][.4pt]{\rule[.5\baselineskip]{\textwidth}{#1}}
\renewcommand\chapterlineswithprefixformat[3]{%
{\raggedleft#2}\nobreak%
\ifstr{#2}{}{\kern-.5\baselineskip}{}%
\titlerule\\*%
\kern-.5ex%
#3\par\nobreak%
\kern1.75ex%
\titlerule%
}
\usepackage{blindtext}% only for dummy text
\begin{document}
\chapter{Test}
\blindtext
\addchap{Test the second}
\blindtext
\end{document}
如果这些行也应该在那里而没有选项,headings=chapterprefix
请添加重新定义chapterlinesformat
:
\makeatletter
\renewcommand\chapterlinesformat[3]{%
\titlerule\\*%
\kern-.5ex%
\@hangfrom{#2}{#3}\par\nobreak%
\kern1.75ex%
\titlerule%
}
\makeatother
代码:
\documentclass[
%headings=chapterprefix
]{scrbook}[2015/10/03]
\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}
\addtokomafont{chapterprefix}{\Large}
\addtokomafont{disposition}{\rmfamily}
\RedeclareSectionCommand[%
beforeskip=\dimexpr4.6\baselineskip+\parskip\relax,
innerskip=0pt,
afterskip=1.5\baselineskip plus .115\baselineskip minus .192\baselineskip
]{chapter}
\newcommand\titlerule[1][.4pt]{\rule[.5\baselineskip]{\textwidth}{#1}}
\renewcommand\chapterlineswithprefixformat[3]{%
{\raggedleft#2}\nobreak%
\ifstr{#2}{}{\kern-.5\baselineskip}{}%
\titlerule\\*%
\kern-.5ex%
#3\par\nobreak%
\kern1.75ex%
\titlerule%
}
\makeatletter
\renewcommand\chapterlinesformat[3]{%
\titlerule\\*%
\kern-.5ex%
\@hangfrom{#2}{#3}\par\nobreak%
\kern1.75ex%
\titlerule%
}
\makeatother
\usepackage{blindtext}% only for dummy text
\begin{document}
\chapter{Test}
\blindtext
\addchap{Test the second}
\blindtext
\end{document}
答案2
这可能不是最好的方法,但我希望了解该课程的人可以纠正我。
像这样吗?
\documentclass[chapterprefix]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}
% see manual esp. chapter 21
\makeatletter
\renewcommand*{\chapterheadstartvskip}{\vspace{\@tempskipa}\hfill}
\renewcommand*{\chapterheadmidvskip}{\vskip.5\@tempskipa\par\nobreak\noindent\rule{\textwidth}{1pt}\vskip.5\@tempskipa\par\nobreak}
\renewcommand*{\chapterheadendvskip}{\vskip.25\@tempskipa\par\nobreak\noindent\rule{\textwidth}{1pt}}
\makeatother
\setkomafont{chapter}{\bfseries\huge}
\setkomafont{chapterprefix}{\bfseries\Large}
\addtokomafont{disposition}{\rmfamily}
\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
\raggedchapter
\@hangfrom{#2}#3%
}
\makeatother
\renewcommand{\chapterlineswithprefixformat}[3]{%
\raggedleft
#2%
\raggedright
#3%
}
\begin{document}
\chapter{Introduction}
\label{ch:Introduction}
\end{document}