KOMA スクリプトを使用した番号なしセクション タイトルの前の箇条書き

KOMA スクリプトを使用した番号なしセクション タイトルの前の箇条書き

ドキュメント内のすべてのセクションの余白に箇条書きを入れようとしましたが、KOMA コマンドは番号付きセクションにのみ影響し、番号なしセクションには影響しないようです。何か見落としているのでしょうか? (最終的にはすべてのセクションに番号が付けられず、箇条書きのみになります。)

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}

\renewcommand*{\sectionformat}{%
\makebox[0pt][r]{\textcolor{gray}{\textbullet}~}}

\begin{document}


\section{Section}

\section*{Unnumbered section}

\end{document}

1]

答え1

次のように再定義できます\sectionlinesformat:

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{section}{\makebox[0pt][r]{\normalfont\textcolor{gray}{\textbullet}~}}%
  \@hangfrom{\hskip #2#3}{#4}% original definition
}
\makeatother

\usepackage{lipsum}% only for dummy text

\begin{document}
\section{Section}
\lipsum[1]
\addsec*{Unnumbered section}
\lipsum[2]
\end{document}

ここに画像の説明を入力してください

または、次のコマンドを実行することもできます:

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}

\usepackage{xpatch}
\xpretocmd\sectionlinesformat
  {\ifstr{#1}{section}{\makebox[0pt][r]{\normalfont\textcolor{gray}{\textbullet}~}}}
  {}{\PatchFailed}

\usepackage{lipsum}% only for dummy text

\begin{document}
\section{Section}
\lipsum[1]
\addsec*{Unnumbered section}
\lipsum[2]
\end{document}

結果は上記と同じです。

答え2

セクションの再定義に関する私の古い回答から(「toc セクション」などに問題が発生する可能性があるため、ニーズに合う場合は改善できます):

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}

%\renewcommand*{\sectionformat}{%
%\makebox[0pt][r]{\textcolor{gray}{\textbullet}~}}
\let\oldsection\section
\makeatletter
\def\section{%
\@ifstar{\def\thesection{~}\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\setkomafont{section}{\sectionformat}%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}      
\def\@StarredWith[#1]#2{%
\oldsection*{\makebox[0pt][r]{\textcolor{gray}{\textbullet}~}#2}%
}
\def\@StarredWithout#1{
\oldsection*{\makebox[0pt][r]{\textcolor{gray}{\textbullet}~}#1}%
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\oldsection[#1]{\textcolor{gray}{\textbullet}~#2}%
}
\def\@nonStarredWithout#1{%
\oldsection{\textcolor{gray}{\textbullet}~#1}%
}
\makeatother

\begin{document}


\section{Section}

\section*{Unnumbered section}

\end{document}

出力:

ここに画像の説明を入力してください

このドキュメントクラスをあまり使用していないので、より良い回答をお待ちください

関連情報