Como incluir duas linhas horizontais abaixo e acima da seção no scartcl, bem como no rótulo "Capítulo X"?

Como incluir duas linhas horizontais abaixo e acima da seção no scartcl, bem como no rótulo "Capítulo X"?

Estou usando a scrartclclasse document no LaTeX (e preciso usá-la por vários motivos). Agora, quero obter algo assim para cada seção:

insira a descrição da imagem aqui

Atualmente estou fazendo o seguinte:

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

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

Isso produz o seguinte:

insira a descrição da imagem aqui

No entanto, não descobri:

  1. como fazer o LaTeX adicionar automaticamente o texto do Capítulo X acima

  2. como adicionar a segunda linha

  3. como evitar que essa formatação também aconteça no índice.

Responder1

Primeiro de tudo: não use titleseccom uma classe KOMA-Script.

Se você precisar de capítulos, mude para scrreprt, por exemplo:

\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}

Resultado:

insira a descrição da imagem aqui

Exemplo com scrartcle seções:

\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}

Resultado:

insira a descrição da imagem aqui

informação relacionada