I want to have this type of section heading for my book.... Any suggestions how it can be achieved....
-
3Welcome to TSE. What did you try? – José Carlos Santos Jan 17 '23 at 14:07
1 Answers
If you are using a KOMA-Script class, you can redefine \sectionlinesformat to add the rule and use \addtokomafont to change the color. To remove the chapter counter from the section number, you can use \counterwithout and \counterwithin* (if the section counter should still depend on the chapter counter).
\documentclass{scrbook}
\usepackage{montserrat}
\usepackage[svgnames]{xcolor}
\counterwithout{section}{chapter}
\counterwithin*{section}{chapter}
\makeatletter
\renewcommand*{\sectionlinesformat}[4]{%
@hangfrom{\hskip #2#3}{#4}% Original code from scrbook.cls
\Ifstr{#1}{section}{% For sections only
\par\nobreak
\rule[1ex]{\textwidth}{1pt}%
}%
}
\makeatother
\addtokomafont{section}{\color{DodgerBlue}\nobreak}
\usepackage{blindtext}
\begin{document}
\chapter{Test}
\section{First section}
\blindtext
\section{Second section}
\blindtext
\section{Third section}
\blindtext
\section{Fourth section}
\blindtext
\section{Photodiode}
\blindtext
\end{document}
If you additionally want to change the space between the section number and the title text, you can redefine \sectionmarkformat. The original definition (from the KOMA-Script manual, Section 3.16) is:
\newcommand*{\sectionformat}{\thesection\autodot\enskip}
To, e.g., increase the space from half a quad to a full quad you could use
\renewcommand*{\sectionformat}{\thesection\autodot\quad}
Alternatively you can use every horizontal space you want, e.g., \qquad, \hspace{2em}, \hspace{1in}. To start the title text always at the same place, you can use a \makebox, e.g.,
\renewcommand*{\sectionformat}{\makebox[2in][l]{\thesection\autodot\hfill}}
You can even move the number into the left margin, as explained in an example in the KOMA-Script manual.
If you are not using a KOMA-Script class see the manual of the used class for information about similar features. If the class does not provide features to configure the section headings, you may use a package like titlesec. However, I'm almost always using KOMA-Script classes, so I cannot tell you, how the configuration has to be done in this case.
- 11,455
-
-
Can you please suggest how can I increase spacing between 5 and photodiode. Also when i try with long document "xcolor" package is showing error – Mehraj - ud - Din Jan 17 '23 at 17:57
-
@Mehraj-ud-Din These are two new questions. Usually you should ask a new question. However, I've added an answer to the first one into my answer. But I cannot answer the second one, because I even do not now the error. If it is an option clash, see, e.g., https://tex.stackexchange.com/questions/51488/option-clash-with-xcolor-and-tikz If this does not help, please ask a new question with a minimal working example, that reproduces the error message. And please do not forget to specify the exact error message. – cabohah Jan 18 '23 at 06:45

