答案1
我建议使用 titlesec 的leftmargin
预定义格式,因为它是为此目的而设计的(请参阅 titlesec 文档的第 3.1 节)。示例:
\documentclass{article}
\usepackage{titlesec}
\titleformat{\section}[leftmargin]
{\normalfont\bfseries\filleft}
{\thesection.}{.5em}{}
\titlespacing{\section}
{4pc}{1.5ex plus .1ex minus .2ex}{1pc}
\begin{document}
\section{my section content}
First line of paragraph
\end{document}
编辑 - 第二个示例具有更宽的边距和“挂起”(评论中的以下问题):
\documentclass{article}
\usepackage{titlesec}
\usepackage{lipsum} % For filler text
\titleformat{\section}[leftmargin]
{\normalfont\bfseries\filright}% Now right justfy
% 'hang' hack - put some negative space before section number
% Now with an adjustment for section numbers with double figures
{\ifnum\thesection>9\relax\hspace{-1.56em}\else\hspace{-1.1em}\fi\thesection.}{.3em}{}% Adjust values to your tastes
\titlespacing{\section}%
{4.5pc}% Increase this value to have more words per line in the title
{1.5ex plus .1ex minus .2ex}%
{0.5pc}% Space between title and section text (adjust as see fit)
\begin{document}
\section{First section} % Example 2
\lipsum[1][1-5]
% Bump up the section number so we can test things
\setcounter{section}{9}
\section{The tenth section}
\lipsum[1][1-5]
\end{document}
输出:
请注意,如果您的部分文本很少,标题可能会重叠。如果发生这种情况,我建议在第一部分的文本后添加一些额外的垂直空间,例如\vpsace{1cm}
。