2

I have search a lot about this with no luck at all. So here I am asking for help. I would like to indent the first line of paragraphs after the section title with the same indentation as the title itself. But after a lot of tryouts, and nothing similar to what I need, I am getting desperate. This is my MWE, actually, my Minimal Not Working Example:

\documentclass{scrbook} 
\usepackage{lipsum}

\DeclareSectionCommand[
    afterindent=true,
    indent=10mm,
    beforeskip=10mm,
    afterskip=5mm,
]{section}

\begin{document}
\chapter{Chapter Title}
\lipsum[75]

\lipsum[75]
\section{Section Title}
\lipsum[75]

\lipsum[75]
\end{document}

enter image description here While I am searching for output like the following one, where the first line after the section title keeps the indentation of the title above it. enter image description here In the Koma-script manual, I could find how to control the vertical separations, or if there is an indentation or not at all, but what I didn't find was how to set a quantity for the first paragraph indentation. I don't even know if this is in any way straight forward or even possible using the scrbook class.

3 Answers 3

1

indentfirst.sty does the trick

\documentclass{scrbook} 
\usepackage{indentfirst}
\usepackage{lipsum}

\begin{document}
\chapter{Chapter Title}
\lipsum[75]

\lipsum[75]
\section{Section Title}
\lipsum[75]

\lipsum[75]
\end{document}
3
  • Thanks for the answer. But actually Identfirst doesn't solve the issue with setting values for the indentation. I think it just activate the indentation of the first line without allowing to set the value of that indention. Thank you anyway for the help.
    – MickFM
    Jan 24, 2020 at 12:21
  • \parindent value as same as indentfirst value...
    – MadyYuvi
    Jan 24, 2020 at 12:44
  • I have been reading the identfirst documentation, which indeed, is very scarce. An I didn't see how to do it. Do you have any idea of how to achieve that. Thanks for the hint.
    – MickFM
    Jan 24, 2020 at 15:39
1

Disclaimer: The following suggestion uses internal commands, so it may break in the future.

\documentclass{scrbook}
\KOMAoptions{fontsize=12pt}
\recalctypearea% <- added, because of the fontsize change
\usepackage{lipsum}

\renewcommand\raggedchapter{\raggedleft}

\DeclareSectionCommand[
    indent=10mm,
    afterindent=true,
    beforeskip=10mm,
    afterskip=5mm,
]{section}

\RedeclareSectionCommand[
    indent=15mm,
    afterindent=true,
    beforeskip=15mm,
    afterskip=5mm,
]{subsection}

\usepackage{xpatch}
\newlength\firstindent

\makeatletter
\xpatchcmd{\@afterheading}
  {\if@afterindent \else}
  {\if@afterindent \hspace{\firstindent}\else}
  {}{\PatchFailed}

\newcommand*\setfirstindent[1]{%
  \scr@ifundefinedorrelax{scr@#1@sectionindent}
    {\setlength{\firstindent}{-\parindent}}
    {\setlength{\firstindent}{\dimexpr\@nameuse{scr@#1@sectionindent}-\parindent\relax}}%
}
\makeatother
\AddtoDoHook{heading/postinit}{\setfirstindent}

\begin{document}
\chapter{Chapter Title}
\lipsum[75]\par\lipsum[75]
\section{Section Title}
\lipsum[75]\par\lipsum[75]
\subsection{Subsection Title}
\lipsum[75]\par\lipsum[75]
\end{document}

Result:

enter image description here

12
  • Very nice hack, specially the second one. It seems to be quite close to the one needed. Do you know how to reset to the document indentation of the other paragraphs following the first one. In the example seems that the second paragraph keeps the indentation of the first one. Thanks a lot for the code. It is very nice.
    – MickFM
    Jan 24, 2020 at 15:35
  • @MickFM See my updated answer.
    – esdd
    Jan 25, 2020 at 17:30
  • \firstindent=\skip64 ! Illegal unit of measure (pt inserted). <to be read again> \par l.25 Dimensions can be in units of em, ex, in, pt, pc, cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one! I'll assume that you meant to say pt, for printer's points. To recover gracefully from this error, it's best to delete the erroneous units; e.g., type 2' to delete two letters. (See Chapter 27 of The TeXbook.) ! Illegal unit of measure (pt inserted). <to be read again> `
    – MickFM
    Jan 26, 2020 at 18:36
  • Trying the updated code, the above error shows up several times. It looks like some error with the units! Is there anything that I could do to fix it? Thanks again for the help. (Using koma-script 3.28 - Updated TexLive 2019).
    – MickFM
    Jan 26, 2020 at 18:43
  • There was a bug in \Ifundefinedorrelax in KOMA-Script 3.28, see komascript.de/release3.28 (German). This is fixed in 3.29 (komascript.de/release3.29, not yet on CTAN). Nevertheless I have replaced \Ifundefinedorrelax by \scr@ifundefinedorrelax in the examples.
    – esdd
    Jan 27, 2020 at 10:07
0

Finally, I get two different solutions. The first one thanks to @esdd, and the other one by mail.

\documentclass[fontsize=12pt]{scrbook}
\usepackage{lipsum}

\DeclareSectionCommand[
    indent=20mm,
    afterindent=true,
    beforeskip=3ex,
    afterskip=0.5ex,
]{section}

\usepackage{xpatch}
\newlength\firstindent

\makeatletter
\xpatchcmd{\@afterheading}
  {\if@afterindent \else}
  {\if@afterindent \hspace{\firstindent}\else}
  {}{\PatchFailed}

\newcommand*\setfirstindent[1]{%
  \scr@ifundefinedorrelax{scr@#1@sectionindent}
    {\setlength{\firstindent}{-\parindent}}
    {\setlength{\firstindent}{\dimexpr\@nameuse{scr@#1@sectionindent}-\parindent\relax}}%
}
\makeatother
\AddtoDoHook{heading/postinit}{\setfirstindent}

\begin{document}
    \chapter{Chapter Title}
        \lipsum[75] 

        \lipsum[75]
    \section{Section Title}
        \lipsum[75] 

        \lipsum[75]
\end{document}

The second one (doesn't need xpatch package):

\documentclass[fontsize=12pt]{scrbook}
\usepackage{lipsum}

\RedeclareSectionCommand[
    indent=20mm,
    beforeskip=3ex,
    afterskip=0.5ex,
    afterindent=true,
    runin=false,
]{section}

% Change the paragraph indent after the sectio:
\AddtoDoHook{heading/endgroup/section}{\global\parindent=20mm}

\makeatletter
\def\@afterheading{%
    \@nobreaktrue
    \everypar{%
        \if@nobreak
        \@nobreakfalse
        \clubpenalty \@M
        \if@afterindent
        \else
        {\setbox\z@\lastbox}%
        \fi
        \global\parindent=\scr@parindent% reset the paragraph indent
        \else
        \clubpenalty \@clubpenalty
        \everypar{}%
        \fi}}
\makeatother

\begin{document}
    \chapter{Chapter Title}
    \lipsum[75] 

    \lipsum[75]
    \section{Section Title}
    \lipsum[75] 

    \lipsum[75]
\end{document}

Running nice now. Thank you!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .