我正在使用scrartcl
LaTeX 中的文档类(出于多种原因,我需要使用它)。现在,我想为每个部分获取类似以下内容:
目前我正在做以下事情:
\usepackage[usenames,dvipsnames]{xcolor}
\colorlet{titlerulecolor}{orange}
\usepackage{titlesec}
\titleformat{\section}{\Huge\scshape\raggedleft}{}{0em}
{ }[{\color{titlerulecolor}\titlerule}]
\titlespacing{\section}{0pt}{3pt}{3pt}
这将产生以下内容:
尽管如此,我还没有弄清楚:
如何让 LaTeX 自动添加上面的第十章文本
如何添加第二行
如何防止这种格式也发生在目录中。
答案1
首先:不要titlesec
与 KOMA-Script 类一起使用。
如果您需要章节请切换到scrreprt
,例如:
\documentclass[
headings=chapterprefix
]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[usenames,dvipsnames]{xcolor}
\colorlet{titlerulecolor}{orange}
\addtokomafont{disposition}{\rmfamily}
\addtokomafont{chapter}{\Huge\scshape}
\addtokomafont{chapterprefix}{\LARGE\upshape}
\RedeclareSectionCommand[%
afterindent=false,
beforeskip=3pt,
innerskip=0pt,
afterskip=3pt
]{chapter}
\newcommand\titlerule[1][.4pt]{\textcolor{titlerulecolor}{\rule[.5\baselineskip]{\textwidth}{#1}}}
\renewcommand\chapterlineswithprefixformat[3]{%
\ifstr{#1}{chapter}{%
\IfArgIsEmpty{#2}{#2#3}{%
\raggedleft%
#2%
\titlerule\\*%
\kern-1.5ex\nobreak%
#3\par\nobreak%
\kern1ex\nobreak%
\titlerule\par%
}%
}{#2#3}%
}
\usepackage{blindtext}% only for dummy text
\begin{document}
\tableofcontents
\chapter{Test}
\Blindtext
\blinddocument
\end{document}
结果:
包含scrartcl
和部分的示例:
\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[usenames,dvipsnames]{xcolor}
\colorlet{titlerulecolor}{orange}
\addtokomafont{disposition}{\rmfamily}
\addtokomafont{section}{\Huge\scshape}
\newkomafont{sectionprefix}{\LARGE\upshape}
\RedeclareSectionCommand[%
afterindent=false,
beforeskip=\dimexpr\baselineskip+3pt\relax,
afterskip=3pt
]{section}
\renewcommand\sectionformat{Section~\thesection\autodot}
\newcommand\titlerule[1][.4pt]{\textcolor{titlerulecolor}{\rule[.5\baselineskip]{\textwidth}{#1}}}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
\ifstr{#1}{section}{%
\ifstr{#3}{}{\@hangfrom{\hskip#2#3}#4}{%
\raggedleft%
{\usekomafont{sectionprefix}#3\par\nobreak}%
\titlerule\\*%
\kern-1.5ex\nobreak%
#4\par\nobreak%
\titlerule\par\nobreak%
}%
}{\@hangfrom{\hskip#2#3}#4}%
}
\makeatother
\usepackage{blindtext}% only for dummy text
\begin{document}
\tableofcontents
\section{Test}
\Blindtext
\blinddocument
\end{document}
结果: