KOMA scartcl セクションごとのインデント

KOMA scartcl セクションごとのインデント

これはベストプラクティスではないことはわかっていますが、再現する必要があるテンプレートがあり、Wordsを使用すると簡単に再現できます。\parindentレベルに応じてテキスト全体をインデントする必要があります( だけではありません)。見出しとテキストに別々に設定する必要があります。例:

  1. セクション、見出し(内線番号)左端
  2. セクション、テキスト左端から0.7cmインデント
  3. サブセクション、見出しセクション付きのテキスト(例:左端から0.7cmインデント)
  4. サブセクション、テキスト左端から1.4cmインデント

KOMA を使用してこれを簡単に実現する方法はありますか?

文書の現在の状態

\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

このようなことをするのは、見た目ほど簡単ではありません。左余白は、ページ全体に常に使用される値です。したがって、左余白を追加するには、サブセクションのコンテンツ全体を環境 (たとえば、インデントされた 、 、minipageまたは )addmarginに移動するtcolorboxか、 を操作することができます\leftskip。次の例では、最後の操作 (および 2020/10/01 からの LaTeX の汎用フックを使用) を実行し、さらに を再定義します\sectionlinesformat(詳細については、KOMA-Script のマニュアルを参照してください)。

\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}

1 ページ目と 2 ページ目では、これが要求に適合しているようです。

要求されたインデントを含むページ 1 と 2

しかし、3 ページ目と 4 ページ目のリストのインデントは正しくありません。

リストのインデントが間違っている 2 ページ

\leftmarginiこれが該当する場合は、フック内の変更なども行う必要があります。あるいは、パッケージを使用してenumitemリストを調整することもできます。

ほぼ完全なドキュメントを変更すると、他にも問題が発生する可能性があります\leftskip。たとえば、trivlistlikeから派生した環境もaddmargin奇妙な行動をする

私の意見では、あなたの質問に対する答えは

KOMA を使用してこれを簡単に実現する方法はありますか?

いいえ、簡単ではありません。

関連情報