1

so I know this is not that of a best practice but I have a template that I need to reproduce and words makes it easy to do so.... I need to indent the full text (not just \parindent) depending on the level. I need to set this for heading and text separately, e.g.

  1. Section, Heading (inl. number) at left margin
  2. Section, Text indented 0.7cm from left margin
  3. Subsection, Heading on text with section, e.g. indented 0.7cm from left margin
  4. Subsectin, Text indented 1.4cm from left margin

Is there an easy way to accomplish this using KOMA?

Current State of the document

\documentclass[11pt, oneside, a4]{scrartcl}

% Packages, Design
\usepackage[top=1.5cm, bottom=2.5cm, left=2.5cm, right=1.6cm]{geometry}
\usepackage{lipsum}
\pagestyle{empty}
%\usepackage{showframe}

% Section style
\setkomafont{section}{\bfseries\fontsize{14pt}{14pt}\selectfont}
\setkomafont{subsection}{\bfseries}
\setkomafont{subsubsection}{\bfseries}

\RedeclareSectionCommand[
beforeskip=-2\baselineskip,
afterskip=0.2\baselineskip,
]{section}

\RedeclareSectionCommands[
beforeskip=-2\baselineskip,
afterskip=0.2\baselineskip
]{subsection, subsubsection}

% Opening
\title{Report}
\author{A Anme}

\begin{document}

\section{Test 1}
Text\\
More text on a second line\par
\lipsum
\section{Test 2}
Text\\
Equation: 
\begin{equation}
    E = m\cdot c^2
\end{equation}
\subsection{Test 2 2}
Text
\subsubsection{TestSub}
Something

\end{document}

1 Answer 1

0

Doing something like this, is not as trivial as it seems. The left margin is a value used always for the whole page. So to add extra left margin, you could either move the whole content of a sub…section into an environment, e.g., an indented minipage (issue: no page break), or an addmargin, or maybe even a tcolorbox, or you can manipulate the \leftskip. In the following example, I do the last (and use generic hooks of LaTeX from 2020/10/01) and additionally redefine \sectionlinesformat (see the KOMA-Script manuals for more information about this):

\documentclass{scrartcl}% All default options removed

% Packages, Design
\usepackage[top=1.5cm, bottom=2.5cm, left=3.2cm, right=1.6cm]{geometry}% left
                                % margin increased by the text indent of
                                % sections

\usepackage{mwe}
\pagestyle{empty}
%\usepackage{showframe}

% Section style
\setkomafont{section}{\bfseries\fontsize{14pt}{14pt}\selectfont}
\setkomafont{subsection}{\bfseries}
\setkomafont{subsubsection}{\bfseries}

\makeatletter
\renewcommand*{\sectionlinesformat}[4]{%
  \hskip#2\parbox{\dimexpr\linewidth+0.7cm}{%
    \@hangfrom{#3}{#4}%
  }%
}
\makeatother

\RedeclareSectionCommand[
  indent=-0.7cm,
  runin=false,
  afterindent=false,
  beforeskip=2\baselineskip,
  afterskip=0.2\baselineskip,% IMHO not enough
]{section}

\RedeclareSectionCommands[
  indent=0cm,
  afterindent=false,
  beforeskip=2\baselineskip,
  afterskip=0.2\baselineskip,% IMHO not enough
]{subsection, subsubsection}

\AddToHook{cmd/section/before}{%
  \par
  \setlength{\leftskip}{0pt}%
  \setlength{\linewidth}{\textwidth}%
}
\AddToHook{cmd/subsection/before}{%
  \par
  \setlength{\leftskip}{0.7cm}%
  \setlength{\linewidth}{\textwidth}%
  \addtolength{\linewidth}{-\leftskip}%
}

% Opening
\title{Report}
\author{A Anme}

\begin{document}
\tableofcontents

\section{Test 1}
\lipsum[1]
\begin{itemize}
\item Testitem
\item Testitem
\end{itemize}
\lipsum[2-3]

\section{Test 2}
\lipsum[1]
\begin{equation}
    E = m\cdot c^2
\end{equation}
\lipsum[2]
\subsection{Test 2 2}
\lipsum[3]
\subsubsection{TestSub}
\lipsum[4]

\blinddocument

\end{document}

At page 1 and 2 this seems to fit the request:

page 1 and 2 with the requested indents

But the indent of the lists at page 3 and 4 is not correct:

two pages with wrong list indent

If this is relevant for you, you should also have to change \leftmargini etc. within the hooks. Alternatively you could use package enumitem to adapt the lists.

There may be other issues with changing \leftskip for almost the complete document. For example environments derived from trivlist like addmargin could also behave strange.

So IMHO, the answer to your question

Is there an easy way to accomplish this using KOMA?

would be: No, not easy.

2
  • Thanks, that dies exactly what I want at this time! I will patch the lists with enumitem and see if I can change the layout request in the future since Im not a fan of the layout itself
    – Max
    Mar 17, 2023 at 7:40
  • FWIW: I fixed the lists with the following which is fairly easy (customindent is defined as the 0.7cm): ` \setlist[enumerate]{ leftmargin=\dimexpr(\leftskip + \customindent)\relax, } \setlist[itemize]{ leftmargin=\dimexpr(\leftskip + \customindent)\relax, } `
    – Max
    Mar 17, 2023 at 8:07

You must log in to answer this question.

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