
私は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で第X章のテキストを自動的に追加する方法
2行目を追加する方法
この書式設定が目次でも発生しないようにする方法。
答え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}
結果: