Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like the chapter and (sub)section headings to be indented as much as the first lines of paragraphs (\parindent value).

By default using koma-script I get them aligned with left boundary of the page: enter image description here

The desired effect is the following: enter image description here

The MWE I use is the following:

\documentclass{scrreprt}

\usepackage[english]{babel}
\usepackage{indentfirst}
\usepackage{lipsum}

\setlength{\parindent}{1cm} 

\begin{document}

\addchap{Chapter without number}
\addsec{Section without number}
\lipsum[1-4]

\chapter{Chapter with number}
\section{Section with number}
\lipsum[1-4]

\end{document}
share|improve this question
1  
I'd have thought \addtokomafont{sectioning}{\hspace{1cm}} would work but it seems it is inserted twice for \addchap... –  clemens Jun 18 '13 at 9:42
    
I tried renewing \chapterformat and \othersectionlevelsformat commands but unfortunately they affect only headings with numbers. –  megabyde Jun 18 '13 at 10:27
    
@clemens seems, it's no longer the case. But I use custom chapter title format from fncychap and just needed an answer to OP's question that works for (sub)sections, so I stick to yours. –  Artem Pelenitsyn Feb 12 at 20:09
    
@clemens ouch, it seems that your solution shifts chapter title inside toc. –  Artem Pelenitsyn Feb 13 at 4:59
    
With a recent KOMA-Script version it is easily possible to redefine the sectioning commands... My idea from above clearly is no solution! –  clemens Feb 13 at 9:05

2 Answers 2

up vote 3 down vote accepted

Some redefinitions of internal commands are required:

\documentclass[openany]{scrreprt}
\usepackage[a5paper]{geometry}
\usepackage[english]{babel}
\usepackage{indentfirst}
\usepackage{linegoal}
\usepackage{lipsum}

\newlength\MyIndent
\setlength\MyIndent{1cm}

\setlength\parindent{\MyIndent} 

\makeatletter
\renewcommand\section{\@startsection{section}{1}{\MyIndent}%
  {-3.5ex \@plus -1ex \@minus -.2ex}%
  {2.3ex \@plus.2ex}%
  {\ifnum \scr@compatibility>\@nameuse{scr@v@2.96}\relax
    \setlength{\parfillskip}{\z@ plus 1fil}\fi
    \raggedsection\normalfont\sectfont\nobreak\size@section}%
}
\renewcommand\subsection{\@startsection{subsection}{2}{\MyIndent}%
  {-3.25ex\@plus -1ex \@minus -.2ex}%
  {1.5ex \@plus .2ex}%
  {\ifnum \scr@compatibility>\@nameuse{scr@v@2.96}\relax
    \setlength{\parfillskip}{\z@ plus 1fil}\fi
    \raggedsection\normalfont\sectfont\nobreak\size@subsection
  }%
}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\MyIndent}%
  {-3.25ex\@plus -1ex \@minus -.2ex}%
  {1.5ex \@plus .2ex}%
  {\ifnum \scr@compatibility>\@nameuse{scr@v@2.96}\relax
    \setlength{\parfillskip}{\z@ plus 1fil}\fi
    \raggedsection\normalfont\sectfont\nobreak\size@subsubsection
  }%
}
\renewcommand\paragraph{\@startsection{paragraph}{4}{\MyIndent}%
  {3.25ex \@plus1ex \@minus.2ex}%
  {-1em}%
  {\raggedsection\normalfont\sectfont\nobreak\size@paragraph}%
}
\renewcommand\subparagraph{\@startsection{subparagraph}{5}{\MyIndent}%
  {3.25ex \@plus1ex \@minus .2ex}%
  {-1em}%
  {\raggedsection\normalfont\sectfont\nobreak\size@subparagraph}%
}
\renewcommand*{\@@makeschapterhead}[1]{%
  \chapterheadstartvskip%
  {\normalfont\sectfont\nobreak\size@chapter{}\hspace*{0cm}%
    \setlength{\parindent}{3cm}\setlength{\parfillskip}{\fill}%
    \raggedsection \interlinepenalty \@M\size@chapter{%
      \parbox[t]{\dimexpr\linewidth-\MyIndent\relax}{#1}}\par}%
  \nobreak\chapterheadendvskip%
}
\renewcommand*{\@@makechapterhead}[1]{\chapterheadstartvskip
  {%
    \hspace*{0pt}\setlength{\parindent}{\MyIndent}\setlength{\parfillskip}{\fill}%
    \normalfont\sectfont\nobreak\size@chapter{}%
    \if@chapterprefix
      \let\@tempa\raggedsection
    \else
      \let\@tempa\@hangfrom
    \fi
    \@tempa{\ifnum \c@secnumdepth >\m@ne%
          \if@chapterprefix
            \expandafter\size@chapterprefix
          \else
            \expandafter\size@chapter
          \fi
          {\chapterformat}%
          \if@chapterprefix
            \size@chapterprefix{}\endgraf\nobreak\vskip.5\baselineskip
          \fi
      \fi
    }%
    {\raggedsection \interlinepenalty \@M \size@chapter{%
      \parbox[t]{\linegoal}{#1}}\par}}%
  \nobreak\chapterheadendvskip
}
\makeatother

\setcounter{secnumdepth}{3}

\begin{document}

\addchap{Chapter without number}
\addsec{Section without number}
\subsection*{Subsection without number}
\subsubsection*{Subsubsection without number}
\lipsum[2]\lipsum[4]

\chapter{Chapter with number}
\section{Section with number}
\subsection{Subsection with number}
\subsubsection{Subsubsection with number}
\lipsum[2]\lipsum[4]

\end{document}

enter image description here

share|improve this answer
    
And the result shows that it's better to stick with the original setup. –  egreg Jun 18 '13 at 14:34
    
@egreg definitively! –  Gonzalo Medina Jun 18 '13 at 14:35

Since v3.15 (the newest version is v3.16) KOMA-Script provides the macros

  • \DeclareSectionCommand, \RedeclareSectionCommand, \DeclareNewSectionCommand and \ProvideSectionCommand
  • \DeclareSectionCommands, \RedeclareSectionCommands, \DeclareNewSectionCommands and \ProvideSectionCommands

which can be used to change the layout of the sectioning commands via a keyvalue interface. Gonzalo's answer can then be shortened as follows:

\documentclass{scrreprt}

\usepackage[english]{babel}
\usepackage{indentfirst}
\usepackage{lipsum}
\usepackage{etoolbox}

\setlength{\parindent}{1cm} 

% a hack for the chapter commands:
\makeatletter
\patchcmd\@@makeschapterhead{\setlength{\parindent}{\z@}}{\hspace*{0pt}}{}{}
\patchcmd\@@makechapterhead{\setlength{\parindent}{\z@}}{\hspace*{0pt}}{}{}
\makeatother

% all other sectioning commands:
\RedeclareSectionCommands[indent=\the\parindent]{section,subsection,subsubsection,paragraph}

\begin{document}

\tableofcontents

\addchap{Chapter without number}
\addsec{Section without number}
\subsection*{Subsection without number}
\subsubsection*{Subsubsection without number}
\paragraph*{Paragraph without number}
\lipsum[2]\lipsum[4]

\chapter{Chapter with number}
\section{Section with number}
\subsection{Subsection with number}
\subsubsection{Subsubsection with number}
\paragraph{Paragraph with number}
\lipsum[2]\lipsum[4]

\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.