
Gostaria de saber se você poderia oferecer alguma ajuda. Quero personalizar os títulos das seções em um scrbook
documento de classe. Algo semelhante a isto:
Número da seção em uma caixa seguida por uma linha centralizada Nome da seção e outra linha centralizada verticalmente preenchendo a largura do texto.
Até agora, procurei soluções neste StackExchange, mas sem sucesso. Eu verifiquei oManual Koma-Scripte encontrei dois comandos possíveis para fazer algo semelhante: \sectionformat
e \sectionlinesformat
. Mas, honestamente, o meu conhecimento muito limitado de látex não me permite saber quando usar um ou outro.
Olhando soluções semelhantes encontradas neste fórum, consegui o seguinte:
\documentclass[openright]{scrbook}
\usepackage{geometry}
\geometry{a4paper,twoside, margin=3cm}
\usepackage{blindtext}% only dummy text
\usepackage{xcolor}
\renewcommand*{\sectionformat}{%
\usekomafont{section}
\makebox[0pt][r]{\fboxrule=1.5pt\fcolorbox{black}{white!0}{\color{black}\thesection}\rule[.7ex]{10pt}{1.5pt}}
}
\begin{document}
\chapter{Introduction}
\section{Section 1}
\Blindtext[2]
\section{Section 2}
\Blindtext[2]
\section{Section 3}
\Blindtext[2]
\section{Section 4}
\Blindtext[2]
\end{document}
Mas não encontrei uma maneira de adicionar a linha alinhada à altura do texto horizontal-vertical para preencher a largura do texto.
Outra opção que tentei foi usar:
%%%%% Simple + underline
\renewcommand{\sectionlinesformat}[4]{%
\Ifstr{#1}{section}{%
\parbox[c]{\linewidth}{%
\raggedsection{\hskip #2{\color{black}#3}}{#4}\par%
\kern-.75\ht\strutbox\rule{\linewidth}{1pt}%
}%
}{%
{\hskip #2#3}{#4}}%
}
Veja, aqui \sectionlinesformat
é usado em vez de \sectionformat
, mas não faço ideia do porquê. Pelo qual recebo:
Uma terceira opção que encontrei foi usar \makeatletter
and \makeatother
:
\makeatletter
\renewcommand\@seccntformat[1]{%
\makebox[0pt][l]{\rule[-\dimexpr\fboxsep+2pt\relax]{\columnwidth}{1.5pt}}%
\colorbox{blue}{%
\rule[-2pt]{0pt}{0pt}%
\color{white}\csname the#1\endcsname
}%
\quad
}
\makeatother
E eu recebo:
Alguma orientação sobre como posso obter o resultado desejado?
Além disso, seria bom se pudéssemos ter a opção de alinhar o número da seção e sua caixa com o texto ou na margem.
Responder1
Algo assim?
\documentclass[openright]{scrbook}
\usepackage{geometry}
\geometry{a4paper,twoside, margin=3cm}
\usepackage{blindtext}% only dummy text
\usepackage{xcolor}
\usepackage{xhfill}
\renewcommand*{\sectionformat}{%
\usekomafont{section}%
\fboxrule=1pt\fcolorbox{blue}{white!0}{\color{black}\thesection}%
\color{blue}\rule[.7ex]{10pt}{1pt}\>%
}
\makeatletter
\renewcommand*{\sectionlinesformat}[4]{%
\@hangfrom{\hskip #2#3}{\color{blue}#4}\>%
\xrfill[.7ex]{1pt}[blue]%
}
\makeatother
\begin{document}
\chapter{Introduction}
\section{Section 1}
\Blindtext[2]
\section{Section 2}
\Blindtext[2]
\section{Section 3}
\Blindtext[2]
\section{Section 4}
\Blindtext[2]
\end{document}
Responder2
Apenas como complemento à resposta de @Vincent:
Se apenas as seções (e não as subseções e subseções) deveriam usar o formato diferente:
\documentclass[twoside,open=right]{scrbook}
\usepackage{geometry}
\geometry{margin=3cm}
\usepackage{blindtext}% only for dummy text
\usepackage{xcolor}
\usepackage{xhfill}
\renewcommand*{\sectionformat}{%
\fboxrule=1.5pt\fcolorbox{.}{white}{\color{black}\thesection}%
\rule[.7ex]{10pt}{1pt}\;%
}
\NewCommandCopy{\originalsectionlinesformat}{\sectionlinesformat}
\renewcommand*{\sectionlinesformat}[4]{%
\originalsectionlinesformat{#1}{#2}{#3}{#4\Ifstr{#1}{section}{\;\xrfill[.6ex]{1.5pt}[.]}{}}%
}
\addtokomafont{section}{\color{blue!50!black}}
\begin{document}
\chapter{Introduction}
\section{Section 1}
\subsection{Subsection}
\subsubsection{Subsubsection}
\Blindtext[2]
\end{document}
Se subseções e subseções devem usar o mesmo formato, mas cores diferentes:
\documentclass[twoside,open=right]{scrbook}
\usepackage{geometry}
\geometry{margin=3cm}
\usepackage{blindtext}% only for dummy text
\usepackage{xcolor}
\usepackage{xhfill}
\renewcommand*{\sectionformat}{%
\fboxrule=1.5pt\fcolorbox{.}{white}{\normalcolor\thesection}%
\rule[.7ex]{10pt}{1pt}\;%
}
\renewcommand*{\subsectionformat}{%
\fboxrule=1.5pt\fcolorbox{.}{white}{\normalcolor\thesubsection}%
\rule[.7ex]{10pt}{1pt}\;%
}
\renewcommand*{\subsectionformat}{%
\fboxrule=1.5pt\fcolorbox{.}{white}{\normalcolor\thesubsubsection}%
\rule[.7ex]{10pt}{1pt}\;%
}
\NewCommandCopy{\originalsectionlinesformat}{\sectionlinesformat}
\renewcommand*{\sectionlinesformat}[4]{%
\originalsectionlinesformat{#1}{#2}{#3}{#4\;\xrfill[.6ex]{1.5pt}[.]}%
}
\addtokomafont{section}{\color{blue!50!black}}
\addtokomafont{subsection}{\color{green!50!black}}
\addtokomafont{subsubsection}{\color{red!50!black}}
\begin{document}
\chapter{Introduction}
\section{Section 1}
\subsection{Subsection}
\subsubsection{Subsubsection}
\Blindtext[2]
\end{document}