
我不確定是否\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 文件中,標題的範例之一是:
\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 Jun 2021 中引入的段落鉤子,可以實現更強大的功能(與其他套件/設定不相容的可能性較小)。您可能需要為 設定較小的 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}