titlesecとインデント
Oct 02 2020
titlesecパッケージを使用して記事のセクションをフォーマットしています。基本的に、次のように、セクション番号をメインテキストの左マージンに揃え、セクションタイトルをインデントされた段落の最初の行に揃えたいと思います。
1. Section title
text text text text text text text text text text text text
text text text text text text text text text text
次のような解決策をいくつか試しましたが、うまくいきませんでした。お手伝いありがとう。
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\setlength{\parindent}{2em}
\usepackage{titlesec}
\titleformat{\section}{\normalfont\bfseries}{\thesection.}{\the\parindent}{}
\begin{document}
\section{Section name}
\end{document}
回答
1 Vincent Oct 02 2020 at 21:35
そのための最も簡単な方法は、を定義するために使用したものと同じ、固定長のセクション番号を配置することだと思います\parindent。
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\setlength{\parindent}{1cm}
\usepackage{titlesec}
\titleformat{\section}{\normalfont\bfseries}{\makebox[1cm][l]{\thesection.}}{0pt}{}
\titlespacing{\section}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\usepackage{lipsum}
\begin{document}
\section{Section name}
\lipsum[1]
\end{document}
セクションタイトルが太字であるため、セクションタイトルの長さが段落と同じにならないため1cm、2emを設定する代わりに使用しました。の使用は、セクションタイトルの直後の段落を自動的にインデントすることだけです。使用される長さは、のドキュメントに記載されているデフォルトの長さです。\parindent2em\titlespacingtitlesec