`\titlesec` を使用してドロップキャップセクションを作成するにはどうすればよいですか?

`\titlesec` を使用してドロップキャップセクションを作成するにはどうすればよいですか?

これができるかどうかはわかりませんが、同じことを+\titlesecの代わりに使用したいと思います。\lettrine\addtocontents

私が望むのは次のようになります:

画像

を使用することに問題はありませんが\lettrine、同じ繰り返しスタイルの場合、手動コードが私の希望よりはるかに多くなります。マクロを作成することもできますが、それでもです。

編集: 明確だと思いましたが、明確にするために、1 という数字があります。これは章番号です。現在、これは次のようになっています。

            \lettrine[lines=2,nindent=0pt,findent=2pt]{\textbf{1}}{}%
            %
            In the beginning God creäted the heaven and the earth.
            %
            $^{2}$And the earth was without form, and void;
                %
                and darkness \textit{was} upon the face of the deep.
            %
            And the Spirit of God moved upon the face of the waters.

\lettrine[lines=2,nindent=0pt,findent=2pt]{\textbf{1}}{}%ただし、を に置き換えたいのです\section{}

titlesec ドキュメントでは、タイトルの例の 1 つは次のとおりです。

\titleformat{\section}[wrap]
        {\normalfont\fontseries{b}\selectfont\filright}
        {\thesection.}{.5em}{}
\titlespacing{\section}
        {12pc}{1.5ex plus .1ex minus .2ex}{1pc}

これにより、\section{}セクションの周囲にテキストが折り返され、下部に空行が配置されるように が変更されます。 で行ったことと同様の操作を実行したいのです\lettrineが、その方法がわかりません。

答え1

このようなもの?

\documentclass{article}
\usepackage{lettrine}
\usepackage{titlesec}
\usepackage{xparse}

\titleformat{\section}[wrap]
        {\normalfont\fontseries{b}\selectfont\filright}
        {}{0pt}{}
\titlespacing{\section}
        {12pc}{1.5ex plus .1ex minus .2ex}{1pc}

\NewDocumentCommand\mysection{ O{#2} m }{%
  \section[#1]{#2}
  \everypar\expandafter{%
    \the\everypar
    \lettrine[lines=2,nindent=0pt,findent=2pt]{\textbf{\thesection}}{}}
}

\begin{document}
\mysection{Title}

In the beginning God creäted the heaven and the earth.
$^{2}$And the earth was without form, and void;
    and darkness \textit{was} upon the face of the deep.
And the Spirit of God moved upon the face of the waters.

In the beginning God creäted the heaven and the earth.
$^{2}$And the earth was without form, and void;
    and darkness \textit{was} upon the face of the deep.
And the Spirit of God moved upon the face of the waters.
\end{document}

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

アップデート: LaTeX2e 2021 年 6 月に導入された段落フックを使用すると、これをより堅牢に実現できます (他のパッケージ/設定と互換性がなくなる可能性が低くなります)。 の after-sep を小さく設定することをお勧めします\section

\documentclass{article}
\usepackage{lettrine}
\usepackage{titlesec}
%\usepackage{xparse} % since latex2e Oct 2020, xparse is part of the kernel

\titleformat{\section}[hang]
        {\normalfont\fontseries{b}\selectfont\raggedright}
        {}{0pt}{}
\titlespacing{\section}
        {12pc}{1.5ex plus .1ex minus .2ex}{1pc}

\NewDocumentCommand\mysection{ O{#2} m }{%
  \section[#1]{#2}
  % need latex2e Jun 2021
  \AddToHookNext{para/begin}{%
    \lettrine[lines=2,nindent=0pt,findent=2pt]{\textbf{\thesection}}{}%
  }%
}

\begin{document}
\mysection{Title}

In the beginning God creäted the heaven and the earth.
$^{2}$And the earth was without form, and void;
    and darkness \textit{was} upon the face of the deep.
And the Spirit of God moved upon the face of the waters.

In the beginning God creäted the heaven and the earth.
$^{2}$And the earth was without form, and void;
    and darkness \textit{was} upon the face of the deep.
And the Spirit of God moved upon the face of the waters.
\end{document}

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

関連情報