scartcl のセクションの上下に 2 本の水平線と「Chapter X」ラベルを含めるにはどうすればよいでしょうか?

scartcl のセクションの上下に 2 本の水平線と「Chapter X」ラベルを含めるにはどうすればよいでしょうか?

私はscrartclLaTeX でドキュメント クラスを使用しています (いくつかの理由でこれを使用する必要があります)。ここで、各セクションで次のようなものを取得したいと考えています。

ここに画像の説明を入力してください

現在、私は次のことを行っています:

\usepackage[usenames,dvipsnames]{xcolor}
\colorlet{titlerulecolor}{orange}

\usepackage{titlesec}
\titleformat{\section}{\Huge\scshape\raggedleft}{}{0em}
{ }[{\color{titlerulecolor}\titlerule}]
\titlespacing{\section}{0pt}{3pt}{3pt}

これにより、次のものが生成されます。

ここに画像の説明を入力してください

それにもかかわらず、私は次のことを理解していません:

  1. LaTeXで第X章のテキストを自動的に追加する方法

  2. 2行目を追加する方法

  3. この書式設定が目次でも発生しないようにする方法。

答え1

まず第一に、titlesecKOMA-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}

結果:

ここに画像の説明を入力してください

関連情報