我正在使用环境来排版一些具有不同字体的文本段落。我希望后面的第一段\begin{environment}
没有缩进。我的代码是
\newenvironment{aut}{\par}{\par}
\AtBeginEnvironment{aut}{\vspace{\baselineskip}\fontfamily{pzc}\selectfont \par\noindent}
由于第一段已缩进,因此这并没有达到预期的效果。
我也试过
\newenvironment{aut}{\par}{\par}
\AtBeginEnvironment{aut}{\vspace{\baselineskip}\fontfamily{pzc}\selectfont\par\parindent0pt}
但这会将环境中所有段落的缩进设置为零,而我只希望第一段没有缩进。有什么建议吗?提前谢谢!
答案1
最好避免,\noindent
因为如果源代码中有空行,很容易产生不良影响。列表环境允许指定变体缩进:
\documentclass{article}
\newenvironment{abc}
{\list{}{%
\leftmargin0pt
\itemindent0pt
\listparindent15pt
}\item\relax}{\endlist}
\begin{document}
\noindent X\dotfill X
\begin{abc}
One two three four five one two three four five
One two three four five one two three four five
One two three four five one two three four five
Red yellow green blue red yellow green blue
Red yellow green blue red yellow green blue
Red yellow green blue red yellow green blue
\end{abc}
\begin{abc}
One two three four five one two three four five
One two three four five one two three four five
One two three four five one two three four five
Red yellow green blue red yellow green blue
Red yellow green blue red yellow green blue
Red yellow green blue red yellow green blue
\end{abc}
\end{document}
答案2
根据您的方法:
\documentclass{article}
\usepackage{etoolbox}% needed for \AtBeginEnvironment
\usepackage{lipsum}
\newenvironment{aut}{\par\hspace*{-\parindent}}{\par}
\AtBeginEnvironment{aut}{\vspace{\baselineskip}\fontfamily{pzc}\selectfont\par}
\AtEndEnvironment{aut}{\vspace{\baselineskip}}
\begin{document}
\lipsum[2]
\begin{aut}\bfseries
\lipsum[1-2]
\end{aut}
\lipsum[2]
\end{document}
\AtBeginEnvironment
正如 cfr 在她的评论中所说,您也可以将内容\AtEndEnvironment
(由我添加)放入您的环境定义中。