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
    
I'd have thought \addtokomafont{sectioning}{\hspace{1cm}} would work but it seems it is inserted twice for \addchap... –  cgnieder 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

1 Answer 1

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

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.