# Adding a line break after \paragraph section and making it justified

I had a friend help me change the \paragraph section to include a line break after the end of the section title. However the end result is a ragged section that isn't justified and if the title is too long and requires more than one line it ends up away from the margin.

Is there a better way to achieve a justified \paragraph (or \subparagraph) with a line break, and on another note a way to control the line spacing between the \paragraph and the text?

MWE:

\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{setspace}
\usepackage{kpfonts}
\usepackage[T1]{fontenc}
\usepackage[left=2.5cm,right=2.5cm,top=3cm,bottom=3cm]{geometry}

\doublespacing

\setcounter{secnumdepth}{5} %

\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
{-3.25ex \@plus -1ex \@minus -0.2ex}%
{0.01pt}%
{\raggedsection\normalfont\sectfont\nobreak\size@paragraph}%
}
\makeatother

\begin{document}

\chapter{Testing begins}

\section{Going deeper}

\paragraph{Testing an unnecessarily long title to see what happens with the end of the paragraph margin, whether it aligns to the text margin or not}

\lipsum[1]

\end{document}

• Only \paragraph and \subparagraph should be justified? Or the same applies to \chapter, \section etc ? – esdd Mar 13 '15 at 12:16
• Well the others were already defined as such, the paragraph in the 'KOMA-script' is generally part of the written text as a section title – Fiztban Mar 13 '15 at 12:22
• Yes, \chapter, \section etc. are defined as ragged sections. – esdd Mar 13 '15 at 12:31
• Ah you are right, I may want to end up applying it to them too. I think I may be able to mash together a redefinition – Fiztban Mar 13 '15 at 13:01
• You should not redefine paragraphs this way in KOMA-script anymore. Use the internal command instead. This is especially important for KOMA-script version 3.16 and upwards. See page 154 in the manual. – Sveinung Mar 13 '15 at 13:30

Simply remove \raggedsection from your definition.

MWE

\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{setspace}
\usepackage{kpfonts}
\usepackage[T1]{fontenc}
\usepackage[left=2.5cm,right=2.5cm,top=3cm,bottom=3cm]{geometry}

\doublespacing

\setcounter{secnumdepth}{5} %

\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
{-3.25ex \@plus -1ex \@minus -0.2ex}%
{0.01pt}%
{\normalfont\sectfont\nobreak\size@paragraph}%
}
\makeatother

\begin{document}

\chapter{Testing begins}

\section{Going deeper}

\paragraph{Testing an unnecessarily long title to see what happens with the end of the paragraph margin, whether it aligns to the text margin or not}

\lipsum[1]

\end{document}


• Sigh it was as simple as that, thanks :) my naivety knows no bounds – Fiztban Mar 13 '15 at 11:09

With an up to date KOMA-Script version (3.15 or newer) you can use \RedeclareSectionCommand and \RedeclareSectionCommands to change the appearance of the sections.

\RedeclareSectionCommands[
beforeskip=-3.25ex plus -1ex minus -0.2ex,
afterskip=1sp
]{paragraph,subparagraph}
\RedeclareSectionCommand[indent=0pt]{subparagraph}


If all sections should be justified you could use

\let\raggedsection\relax


Note there could be a problem with the huge font of the \chapter sections. If I use the long title also as argument of \chapter I will get an overfull \hbox. So maybe it is better to still use a ragged \chapter section.

\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{setspace}
\usepackage{kpfonts}
\usepackage[T1]{fontenc}
\usepackage[left=2.5cm,right=2.5cm,top=3cm,bottom=3cm]{geometry}
\doublespacing

\setcounter{secnumdepth}{5}

\RedeclareSectionCommands[
beforeskip=-3.25ex plus -1ex minus -0.2ex,
afterskip=1sp
]{paragraph,subparagraph}
\RedeclareSectionCommand[indent=0pt]{subparagraph}

\let\raggedsection\relax% -> justified sections
%\let\raggedchapter\raggedright% -> still ragged chapter

\newcommand\dummytext{Testing an unnecessarily long title to see
what happens with the end of the paragraph margin,
whether it aligns to the text margin or not}

\begin{document}
\chapter{Test begins}
%\chapter{\dummytext}

\section{\dummytext}
\paragraph{\dummytext}
\subparagraph{\dummytext}
\lipsum[1]
\end{document}

• Ah thank you so much for you elaboration, I learn something new every time I post a question. I do have chapters redefined completely differently in order to achieve a style I desired (tex.stackexchange.com/questions/159869/…) I will play around with these more innate commands to the KOMA-script documentclass. I probably would want to relax all the sections I just didn't notice they were ragged as every time they have gone onto a new line they seemed justified, unlike my recent paragraph section that was 2cm from the margin – Fiztban Mar 13 '15 at 14:12
• your MWE doesn't seem to work I am afraid, I don't seem to understand why, it says Undefined control sequence and something about begin{document} not being present. – Fiztban Mar 13 '15 at 14:27
• I get a first page with [ beforeskip=-3.25ex plus -1ex minus -0.2ex, afterskip=1sp ]paragraph,subparagraph[indent=0pt]subparagraph written on it, yet I have checked that my KOMA-script version is 3.16, which it is. – Fiztban Mar 13 '15 at 14:32
• Use \listfiles in the preamble of your document and look in the log file which KOMA-Script version is really used. Up to date is scrreprt.cls 2015/02/07 v3.16 KOMA-Script document class (report). – esdd Mar 13 '15 at 14:52
• I worked it out, didn't realise that I'd have to flush out the old files from the Roaming directory for the TexStudio editor to pick up the already updated version. Thank you it works – Fiztban Mar 14 '15 at 11:13