Fonts & Character SetsAdd horizontal line beneath subsection heading and subsubsection heading

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
Christoph
Posts: 29
Joined: Tue Mar 22, 2022 5:22 pm

Add horizontal line beneath subsection heading and subsubsection heading

Post by Christoph »

Hello

This Topic is complementary to my first forum topics:
https://latex.org/forum/viewtopic.php?f=48&t=34795
https://latex.org/forum/viewtopic.php?f=48&t=34799
Till now I´ve been mainly working with KOMA-script and it´s documentation scrguide.

Here are the adjustments I´ve done before:

Code: Select all

\documentclass[
%	paper=a4,
fontsize=12pt,
]{scrreprt}

\usepackage{lipsum}
\usepackage{tgadventor}

\renewcommand*\familydefault{\sfdefault} % Only if the base font of the document is to be sans serif
\usepackage[T1]{fontenc}

\setcounter{secnumdepth}{3}

\renewcommand*{\chapterformat}{
	\thechapter.\enskip} %\autodet wurde durch . ersetzt
\renewcommand*{\sectionformat}{
	\thesection.\enskip} %\autodet wurde durch . ersetzt
\renewcommand*{\subsectionformat}{
	\thesubsection.\enskip} %\autodet wurde durch . ersetzt
\renewcommand*{\subsubsectionformat}{
	\thesubsubsection.\enskip} %\autodet wurde durch . ersetzt

\addtokomafont{chapter}{\normalfont\sffamily}
\addtokomafont{paragraph}{\normalfont\underline}

\usepackage{xcolor}
\setlength{\fboxsep}{10pt}
\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
	\fcolorbox{black}{lightgray}{%
		%	\framebox{
			\parbox{\dimexpr\linewidth-5
				\fboxrule-2\fboxsep}{%
				\@hangfrom{#2}\MakeUppercase{#3}%
			}%
		}%
	}%}
\makeatother



\makeatletter
\renewcommand{\sectionlinesformat}[4]{%
	\ifstr{#1}{section}{%
		\parbox[t]{\linewidth}{%
			\raggedsection\@hangfrom{\hskip #2#3}{#4}\par%
			\vspace*{-1\ht\strutbox}\rule{\linewidth}{.8pt}%
		}%
	}{%
		\@hangfrom{\hskip #2#3}{#4}}% 
}
\makeatother

%% changes of the
%\makeatletter
%\renewcommand{\subsectionlinesformat}[4]{%
%	\ifstr{#1}{section}{%
%		\parbox[t]{\linewidth}{%
%			\raggedsection\@hangfrom{\hskip #2#3}{#4}\par%
%			\vspace*{-1\ht\strutbox}\rule{\linewidth}{.8pt}%
%		}%
%	}{%
%		\@hangfrom{\hskip #2#3}{#4}}% 
%}
%\makeatother


%\makeatletter
%\renewcommand{\subsubsectionlinesformat}[4]{%
%	\Ifstr{#1}{section}{%
%		\hspace*{#2}%
%		\colorbox{red}{%
%			\parbox{\dimexpr\linewidth
%				-2\fboxrule-2\fboxsep-#2}{%
%				\raggedsection
%				\@hangfrom{#3}{#4}%
%			}%
%		}%
%	}{%
%		\@hangfrom{\hskip #2#3}{#4}%
%	}%
%}
%\makeatother



\begin{document}
	
\chapter{Allgemeine Angaben}
\lipsum[2]
\section{Konsensinhaber}
\lipsum[5]
\subsection{Subsection}
\lipsum[3]
\subsubsection{Subsubsection}
\lipsum[2]
\paragraph{Paragraph}
\lipsum[2]


\end{document}
Ta achieve the headings to have the same horizontal line as the section heading I first tried to replace the "\sectionlinesformat" by "\subsectionlinesformat" and "\subsubsectionlinesformat" but as far I´ve detected "\subsectionlinesformat" has a different syntax than "\sectionlinesformat"

I would also like to insert a linebreak with a small gap after the paragraph heading
And I´m not shure if I really want to do that, but how can I set the sectionnumber justified to the paragraph text?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Bartman
Posts: 366
Joined: Fri Jan 03, 2020 2:39 pm

Add horizontal line beneath subsection heading and subsubsection heading

Post by Bartman »

You should get an error message if you try to modify the undefined commands \subsectionlinesformat and \subsubsectionlinesformat. Use the \Ifstr command shown if you want to change selected outline levels below the chapter level.

Apart from the last wish, most of it should have been taken into account in the following proposal:

Code: Select all

\documentclass[fontsize=12pt]{scrreprt}

\usepackage[T1]{fontenc}
\usepackage{tgadventor}
\usepackage{xcolor}
\usepackage{blindtext}

% Only if the base font of the document is to be sans serif
\renewcommand*\familydefault{\sfdefault}

\setcounter{secnumdepth}{3}

\renewcommand*{\chapterformat}{
	\thechapter.\enskip} %\autodet wurde durch . ersetzt
\renewcommand*{\sectionformat}{
	\thesection.\enskip} %\autodet wurde durch . ersetzt
\renewcommand*{\subsectionformat}{
	\thesubsection.\enskip} %\autodet wurde durch . ersetzt
\renewcommand*{\subsubsectionformat}{
	\thesubsubsection.\enskip} %\autodet wurde durch . ersetzt

% Read about \mdseries in section 3.16. Document Structure.
% Removed \sffamily because sans serif has already been set 
% as the document's default.
\addtokomafont{chapter}{\mdseries}
% Removed \underline because the horizontal line was added 
% in \sectionlinesformat.
\addtokomafont{paragraph}{\mdseries}

\setlength{\fboxsep}{10pt}

\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
	\fcolorbox{black}{lightgray}{%
%		\framebox{
			\parbox{\dimexpr\linewidth-5
				\fboxrule-2\fboxsep}{%
				\@hangfrom{#2}\MakeUppercase{#3}%
			}%
%		}%
	}
}

% Removed the conditional statement if this setting should apply 
% to every outline level below the chapters level.
\renewcommand{\sectionlinesformat}[4]{%
	\parbox[t]{\linewidth}{%
		\raggedsection\@hangfrom{\hskip #2#3}{#4}\par%
		\vspace*{-1\ht\strutbox}\rule{\linewidth}{.8pt}%
	}%
}
\makeatother

% Section 21.8. Sections
\RedeclareSectionCommands[
	afterindent=false,
	runin=false,
	afterskip=1.5ex plus .2ex% subsubsection default
]{paragraph,subparagraph}

\begin{document}
\blinddocument
\end{document}
Christoph
Posts: 29
Joined: Tue Mar 22, 2022 5:22 pm

Add horizontal line beneath subsection heading and subsubsection heading

Post by Christoph »

actuallay I want the horizontal Line only beneath section, subsection and subsubsection

I tried the following crazy thing to renew the sectionlinesformat. But in the pdf the subsection, subsubsection and paragraph headings are compleatly missing now.

Code: Select all

\renewcommand{\sectionlinesformat}[4]{%
	\ifstr{#1}{section}{%
		\parbox[t]{\linewidth}{%
			\raggedsection\@hangfrom{\hskip #2#3}{#4}\par%
			\vspace*{-1\ht\strutbox}\rule{\linewidth}{.8pt}%
		}%
	}{
	\ifstr{subsection}{%
		\parbox[t]{\linewidth}{%
			\raggedsection\@hangfrom{\hskip #2#3}{#4}\par%
			\vspace*{-1\ht\strutbox}\rule{\linewidth}{.8pt}%
		}%
	}{
	\ifstr{subsubsection}{%
	\parbox[t]{\linewidth}{%
		\raggedsection\@hangfrom{\hskip #2#3}{#4}\par%
		\vspace*{-1\ht\strutbox}\rule{\linewidth}{.8pt}%
		}%
	}{
		\@hangfrom{\hskip #2#3}{#4}}% 
}}}

Code: Select all

\sectionlinesformat{level}{indent}{number}{text}
level... is the same used in secnumdepth?
indent...

Where are the {level}, {indent} {number} and {text} part in \sectionlinesformat command predefined as:

Code: Select all

\newcommand{\sectionlinesformat}[4]{%
\@hangfrom{\hskip #2#3}{#4}%
}
level... [4]
indent...{\@hangfrom{\hskip #2#3}{#4}}
number...
text...
Christoph
Posts: 29
Joined: Tue Mar 22, 2022 5:22 pm

Add horizontal line beneath subsection heading and subsubsection heading

Post by Christoph »

indent.png
indent.png (18.33 KiB) Viewed 50719 times
is the red boxed space the "\hskip"?
Bartman
Posts: 366
Joined: Fri Jan 03, 2020 2:39 pm

Add horizontal line beneath subsection heading and subsubsection heading

Post by Bartman »

Christoph wrote:actuallay I want the horizontal Line only beneath section, subsection and subsubsection

I tried the following crazy thing to renew the sectionlinesformat. But in the pdf the subsection, subsubsection and paragraph headings are compleatly missing now.
You omitted an argument on the second and third \ifstr command.
Christoph
Posts: 29
Joined: Tue Mar 22, 2022 5:22 pm

Add horizontal line beneath subsection heading and subsubsection heading

Post by Christoph »

Code: Select all

\renewcommand{\sectionlinesformat}[4]{%
	\ifstr{#1}{section}{%
		\parbox[t]{\linewidth}{%
			\raggedsection\@hangfrom{\hskip #2#3}{#4}\par%
			\vspace*{-1\ht\strutbox}\rule{\linewidth}{0.8pt}%
		}%
	}{
	\ifstr{#1}{subsection}{%
		\parbox[t]{\linewidth}{%
			\raggedsection\@hangfrom{\hskip #2#3}{#4}\par%
			\vspace*{-1\ht\strutbox}\rule{\linewidth}{.8pt}%
		}%
	}{
	\ifstr{#1}{subsubsection}{%
	\parbox[t]{\linewidth}{%
		\raggedsection\@hangfrom{\hskip #2#3}{#4}\par%
		\vspace*{-1\ht\strutbox}\rule{\linewidth}{.8pt}%
		}%
	}{
		\@hangfrom{\hskip #2#3}{#4}}% 
}}}
GREAT, THANK YOU!
Christoph
Posts: 29
Joined: Tue Mar 22, 2022 5:22 pm

Add horizontal line beneath subsection heading and subsubsection heading

Post by Christoph »

But still no idea how to set the indention of the paragraph and subparagraph heading to zero...
Should I put it in a new forum topic?
Bartman
Posts: 366
Joined: Fri Jan 03, 2020 2:39 pm

Add horizontal line beneath subsection heading and subsubsection heading

Post by Bartman »

As I said in an older subject, it's basically advisable to limit a topic to just one issue.

In the example, there is no space in front of the numbering of the heading for the paragraph level. The reason for the space before the numbering of the other outline levels is that line endings are treated as spaces. Compare the definition of the \chapterformat, \sectionformat etc. commands in section 3.16. "Document Structure" with your changes.
User avatar
MjK
Posts: 89
Joined: Fri Jan 28, 2022 6:09 pm

Add horizontal line beneath subsection heading and subsubsection heading

Post by MjK »

Please read also https://sourceforge.net/p/koma-script/w ... ecated_if/. The support for these deprecated commands will end some time. The support of some has already ended.
Christoph
Posts: 29
Joined: Tue Mar 22, 2022 5:22 pm

Add horizontal line beneath subsection heading and subsubsection heading

Post by Christoph »

New post: How to avoid spaces (indent) at paragraph and subparagraph heading:
https://latex.org/forum/viewtopic.php?f ... 31#p117331
Post Reply