新定义的环境中所有段落的新悬挂格式

新定义的环境中所有段落的新悬挂格式

我试图定义一个新的环境,其中所有段落都应采用新的缩进。我尝试使用\hangafter\hangindent来执行此操作。但是,这些命令仅适用于其后的第一个段落。如下例所示:

\documentclass{book}
\usepackage{indentfirst} %make first para after title indented
\setlength{\parindent}{2em}

\newenvironment{poemcontent}{\hangafter=1 \setlength{\hangindent}{4em}}{\par}
\newcommand{\text}{This is some content to be written as a single paragraph. 
This is some content to be written as a single paragraph. This is some content 
to be written as a single paragraph. This is some content to be written as a 
single paragraph.}

\begin{document}
\chapter{Poem}
\begin{poemcontent}
  \text

  \text

  \text
\end{poemcontent}
\end{document}

结果是: 在此处输入图片描述 我怎么解决这个问题?

答案1

使用以下命令的简单解决方案 everypar

\documentclass{book}
\usepackage{indentfirst} %make first para after title indented
\setlength{\parindent}{2em}

\newenvironment{poemcontent}{\everypar{\hangafter=1 \setlength{\hangindent}{4em}}}{\par}
\newcommand{\text}{This is some content to be written as a single paragraph.
This is some content to be written as a single paragraph. This is some content
to be written as a single paragraph. This is some content to be written as a
single paragraph.}

\begin{document}

\chapter{Poem}
\begin{poemcontent}
  \text

  \text

  \text
\end{poemcontent}

\end{document} 

在此处输入图片描述

答案2

传播段落形状正是乳胶列表环境的设计目的。

在此处输入图片描述

\documentclass{book}
\usepackage{indentfirst,enumitem} %make first para after title indented
\setlength{\parindent}{2em}
\newlist{plist}{description}{1}

\newenvironment{poemcontent}{%
\plist}{%
\endplist}
\newcommand{\text}{\item This is some content to be written as a single paragraph. 
This is some content to be written as a single paragraph. This is some content 
to be written as a single paragraph. This is some content to be written as a 
single paragraph.}

\begin{document}
\chapter{Poem}
\begin{poemcontent}
  \text

  \text

  \text
\end{poemcontent}
\end{document}

正如您所看到的,我只是在这里采用了默认值,这可能没问题,或者摆弄选项enumitem以进一步定制它。

或者您可能更喜欢这种形式,它只使用一个隐藏\item[]并且只使用空白行\par来触发悬挂缩进:

\documentclass{book}
\usepackage{indentfirst,enumitem} %make first para after title indented
\setlength{\parindent}{2em}
\newlist{plist}{description}{1}

\newenvironment{poemcontent}{%
\plist[listparindent=-2em]\item\relax}{%
\endplist}
\newcommand{\text}{This is some content to be written as a single paragraph. 
This is some content to be written as a single paragraph. This is some content 
to be written as a single paragraph. This is some content to be written as a 
single paragraph.}

\begin{document}
\chapter{Poem}
\begin{poemcontent}
  \text

  \text

  \text
\end{poemcontent}
\end{document}

答案3

如果您确实要排版诗歌,我强烈建议您查看一些已经支持此功能的软件包。(为什么要重新发明轮子?)

例如,允许您执行这样的操作,并且非常易于配置:

\documentclass{book}
\usepackage{indentfirst} %make first para after title indented
\usepackage{verse}
\setlength\vindent{4em}
\newcommand{\text}{This is some content to be written as a single paragraph.
This is some content to be written as a single paragraph. This is some content
to be written as a single paragraph. This is some content to be written as a
single paragraph.}

\begin{document}
\poemtitle{Poem}
\begin{verse}[\textwidth]
  \text\\
  \text\\
  \text\\
\end{verse}
\end{document}

诗

如果你正在排版一本诗集,请参阅诗歌文本这是为此设计的(并且可以与, 我认为)。

也许,悬挂很有趣。

答案4

尝试xgalley的“多段落\parshape设置”:

在此处输入图片描述

\documentclass{article}
\usepackage{xgalley}

% http://river-valley.zeeba.tv/media/conferences/tug-2015/0302-Joseph-Wright/
\ExplSyntaxOn
\cs_new_eq:NN \SetAllShape   \galley_parshape_set_multi:nnnN  % Normal, left, right, resume
\cs_new_eq:NN \SetOneShape   \galley_parshape_set_single:nnnN % Normal, left, right, resume
\cs_new_eq:NN \True          \c_true_bool
\cs_new_eq:NN \False         \c_false_bool
\ExplSyntaxOff

\newenvironment{poemcontent}[1][4em]
  {\par\setlength{\parindent}{0pt}% Remove regular paragraph indentation
   \SetAllShape{1}{#1}{0pt}{\False}}
  {\par}

\newcommand{\text}{This is some content to be written as a single paragraph. 
This is some content to be written as a single paragraph. This is some content 
to be written as a single paragraph. This is some content to be written as a 
single paragraph.}

\begin{document}

\text

\begin{poemcontent}
  \text

  \text
\end{poemcontent}

\text

\begin{poemcontent}[3em]
  \text
\end{poemcontent}

\text

\end{document}

\SetAllShape{<normal>}{<left>}{<right>}{<resume>}将定义范围内的所有段落设置为前几<normal>行不受影响/正常,后跟按长度 / 向左/向右缩进的段落形状<left><right>这可以是逗号分隔的长度列表。<resume>\True\False取决于您是否希望缩进停止或继续。

相关内容