我正在尝试在 latex 中定义一个环境,该环境将按固定量缩进一小段文本的每一行。例如,第一行将没有缩进,第二行将有 1cm 缩进,第三行将有 2cm 缩进,等等。这将用于最多可能为三行的短文本。有人知道是否有一个环境可以做这样的事情,或者我是否可以创建一个?我在这里找不到答案。
答案1
你可以使用这个shapepar
包来实现这一点。语法需要一点时间来适应,但对于像这样简单的事情来说,它还不算太糟糕:
\documentclass{article}
\usepackage{shapepar}
\usepackage{lipsum}
\def\truncatedtriangle{%
{0}
{0}b{0}\\ % Start at the top left
{0}t{0}{10}\\ % First line (at y=0) is 10 units wide
{4}t{2}{8}\\ % Last line (at y=4) starts at x=2 and is 8 units wide
{4}e{10} % the paragraph ends at y=4 and x=10
}
\begin{document}
% Use the paragraph shape. 1 unit is 1/10 of \textwidth.
\Shapepar[0.1\textwidth]\truncatedtriangle{Long text. This won't work with lipsum, unfortunately. The more text you have in your paragraph, the better. We'll just add another paragraph, for good measure. There, that's already much better. Another couple of words.}
\end{document}
答案2
您还可以使用\parshape
指定每行的开始和结束来执行此操作。下面我指定第 4 行不缩进。如果段落超过 3 行,这也将适用于所有后续行。
\documentclass{article}
\usepackage[showframe]{geometry}
\begin{document}
\noindent\parshape=4
0.00\linewidth 1.00\linewidth
0.05\linewidth 0.95\linewidth
0.10\linewidth 0.90\linewidth
0.00\linewidth 1.00\linewidth% All subsequent lines are not indented
Long text. This will also work with lipsum. The more text you have in your paragraph,
the better. We'll just add another paragraph, for good measure. There, that's already
much better. Another couple of words.
\end{document}