首行缩进

首行缩进

如何创建单个首行缩进?其目的是产生与 Microsoft Word“首行缩进”完全相同的效果:

Word 首行缩进

这会产生一个输出,例如: 在此处输入图片描述

附注:目的不是缩进段落,而是让扩展行(大句子 - 不是新行)在正常(未缩进)的第一行之前开始。也就是说,如何才能减少除第一行之外的所有行的缩进(包括章节、小节等)?

提前致谢!

答案1

首行缩进

这实际上是 TeX 中的默认行为。可以通过设置长度来控制缩进量\parindent

\documentclass{article}

\setlength{\parindent}{20mm}

\begin{document}
   A quite long sentence a quite long a sentence quite a long sentence a quite long sentence.

   A quite long sentence a quite long a sentence quite a long sentence a quite long sentence.
\end{document}

在此处输入图片描述

请注意,缩进仅适用于普通段落而不适用于章节标题等。如果您也希望这些缩进(我不推荐!)您必须重新定义它们,例如使用titlesec包或在使用 KOMA-Script 时\RedeclareSectionCommand

除第一行外,所有行均减少缩进

如果想要除第一行之外的所有行,可以\parshape与一起使用\everypar(必须在之后\begin{document}或与一起使用\AtBeginDocument)。

\documentclass{article}

\usepackage{showframe}

\setlength{\parindent}{0pt}

\AtBeginDocument{
   \everypar{%
      \parshape 2
          0pt \textwidth
          -2em \dimexpr\textwidth+2em\relax
   }
}

\begin{document}
   A quite long sentence a quite long a sentence quite a long sentence a quite long sentence.
   A quite long sentence a quite long a sentence quite a long sentence a quite long sentence.
   A quite long sentence a quite long a sentence quite a long sentence a quite long sentence.

   A quite long sentence a quite long a sentence quite a long sentence a quite long sentence.
\end{document}

在此处输入图片描述

然而它看起来确实很奇怪而且不寻常——不要使用它;-)

更多关于\parshape与 \parindent 相反


编辑:为了保留此设置,\section您必须在之后重新应用它,因为\everypar已重新设置。我\ReneowDocumentCommandsparse包中使用。

\documentclass{article}

\usepackage{showframe}

\setlength{\parindent}{0pt}

\newcommand{\activateoutdenting}{%
   \everypar{%
      \parshape 2
          0pt \textwidth
          -2em \dimexpr\textwidth+2em\relax
   }
}

\AtBeginDocument{\activateoutdenting}

\usepackage{xparse}

\let\origsection\section
\RenewDocumentCommand{\section}{ s o m }{%
   \IfBooleanTF{#1}{%
      \IfValueTF{#2}{%
         Impossible case!%
      }{%
         \origsection*{#3}%
      }
   }{%
      \IfValueTF{#2}{%
         \origsection[#2]{#3}%
      }{%
         \origsection{#3}%
      }
   }
   \activateoutdenting
}

\begin{document}
   A quite long sentence a quite long a sentence quite a long sentence a quite long sentence.
   A quite long sentence a quite long a sentence quite a long sentence a quite long sentence.
   A quite long sentence a quite long a sentence quite a long sentence a quite long sentence.

   A quite long sentence a quite long a sentence quite a long sentence a quite long sentence.

   \section{Test}
   A quite long sentence a quite long a sentence quite a long sentence a quite long sentence.
\end{document}

请注意,其他章节标题也必须这样做,这不是一个可靠的实现。我再说一遍:你为什么要这样做?看起来很糟糕……

相关内容