![几乎每个段落都添加悬挂缩进的最佳方法](https://linux22.com/image/279877/%E5%87%A0%E4%B9%8E%E6%AF%8F%E4%B8%AA%E6%AE%B5%E8%90%BD%E9%83%BD%E6%B7%BB%E5%8A%A0%E6%82%AC%E6%8C%82%E7%BC%A9%E8%BF%9B%E7%9A%84%E6%9C%80%E4%BD%B3%E6%96%B9%E6%B3%95.png)
我希望每个段落都有悬挂缩进,但节标题没有。我可以使用 和 来实现这一点titlesec
,\leftskip
但这种解决方案感觉很肮脏/粗俗,我相信一定有更好的方法。
梅威瑟:
\documentclass[12pt]{article}
\usepackage{parskip}
\usepackage{titlesec}
\titleformat{\section}[runin]{\bfseries\normalsize}{}{0pt}{\hspace*{-2em}\thesection }[\\]
\titleformat{\subsection}[runin]{\normalsize}{}{0pt}{}[:\\]
\leftskip=2em
\begin{document}
\section{Section Headings Not Indented}
Every line of this section should be indented the exact same amount. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean adipiscing lacus ut nibh laoreet malesuada. Nulla vehicula mauris eu imperdiet varius. Etiam pellentesque eros a urna pulvinar, nec condimentum lectus gravida. Suspendisse vehicula, mauris id fermentum iaculis, massa neque convallis neque, in vestibulum quam felis in enim.
Sed dapibus, nisl vitae consectetur sodales, augue sem laoreet urna, ut eleifend velit augue vel leo. Nulla facilisi. Suspendisse potenti. Phasellus scelerisque porta risus ut luctus. Ut lobortis magna purus, at rhoncus quam interdum quis. Sed vestibulum, leo non rhoncus sollicitudin, erat enim dignissim dolor, quis commodo nunc elit at arcu.
\subsection{also indented same as a paragraph}
Phasellus vitae ultricies augue. Vivamus non ipsum odio. Etiam id lectus non sapien hendrerit consectetur. Suspendisse porta magna at metus dignissim pharetra. Nulla bibendum mauris sit amet feugiat interdum. Nulla porta sollicitudin lorem eget pharetra. Etiam dictum, dolor vitae vulputate ultricies, quam nibh consectetur leo, nec ultricies felis tortor eget leo. In pulvinar felis nec diam fringilla rhoncus a at lacus.
\end{document}
我遇到了hanging
包和hangparas
环境,但这似乎无法跨多个部分工作。我也考虑过简单地在每个段落中添加一个\hangindent
and \hangafter=0
,但这太繁琐了,我更喜欢更全局的解决方案。
如果可能的话,我还希望能够撤消给定部分(特别是我的附录)的这些设置。目前,我通过在它们前面加上 来实现此目的\leftskip=0
。但是,如果这是不可能的(或需要大量额外的努力),那么这并不是一个交易破坏者。
答案1
这是一个解决方案(您可以将“3em”值设置为您想要的值):
\makeatletter
\newenvironment{exemple}
{\list{}{%
\leftmargin 3em}
\item\relax}
{\endlist}
\makeatother
分数维:
documentclass[12pt]{article}
\makeatletter
\newenvironment{exemple}
{\list{}{%
\leftmargin 3em}
\item\relax}
{\endlist}
\makeatother
\begin{document}
\section{Section Headings Not Indented}
\begin{exemple}
Every line of this section should be indented the exact same
amount. Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Aenean adipiscing lacus ut nibh laoreet malesuada. Nulla
vehicula mauris eu imperdiet varius. Etiam pellentesque eros a urna
pulvinar, nec condimentum lectus gravida. Suspendisse vehicula,
mauris id fermentum iaculis, massa neque convallis neque, in
vestibulum quam felis in enim.
Sed dapibus, nisl vitae consectetur sodales, augue sem laoreet urna,
ut eleifend velit augue vel leo. Nulla facilisi. Suspendisse
potenti. Phasellus scelerisque porta risus ut luctus. Ut lobortis
magna purus, at rhoncus quam interdum quis. Sed vestibulum, leo non
rhoncus sollicitudin, erat enim dignissim dolor, quis commodo nunc
elit at arcu.
\end{exemple}
\subsection{also indented same as a paragraph}
Phasellus vitae ultricies augue. Vivamus non ipsum odio. Etiam id lectus non sapien hendrerit consectetur. Suspendisse porta magna at metus dignissim pharetra. Nulla bibendum mauris sit amet feugiat interdum. Nulla porta sollicitudin lorem eget pharetra. Etiam dictum, dolor vitae vulputate ultricies, quam nibh consectetur leo, nec ultricies felis tortor eget leo. In pulvinar felis nec diam fringilla rhoncus a at lacus.
\end{document}
如果您不想在每个标题内创建一个环境,那么应该有一种方法可以重新定义段落LaTeX
(我不知道如何实现)但你说你希望段落不缩进,但这样会比较困难。