在自定义环境中缩进

在自定义环境中缩进

你好。我有一个文档,正在使用自定义环境。我曾尝试将下一节的标题简单地作为子节,但就像我创建的自定义环境一样。但是,我希望所述环境“内”的文本(甚至是第一段)像我的文档的其余部分一样缩进(我使用包“indentfirst”)。这是一个 MWE:

\documentclass{book}
\usepackage{xcolor}
\usepackage{amssymb}
\usepackage{indentfirst}

\begin{document}
\chapter{Weekday Morning Prayers}
\section{Morning Prayers of Light}
\begin{prayerheading} 
  Tuesday Morning-Prayer V
\end{prayerheading}

O Treasury of Good Things, Ever-flowing fountain, Holy Father, etc etc

For Thou art our God, and unto Thee do we send up glory: to the Father, and to the Son, and to the Holy Spirit, now and ever, and unto ages of ages. Amen. 

\end{document}

对于祈祷,我使用的环境如下:

\newenvironment{prayerheading}{% 
 \center\large\bfseries\color{red}%
 }
{\endcenter}

谢谢大家的帮助!

答案1

这里有几个选项:

  1. \end{prayerheading}在和 以下文本之间留一个空行:

    \documentclass{book}
    \usepackage{xcolor}
    \newenvironment{prayerheading}
      {\center\large\bfseries\color{red}}
      {\endcenter}
    \begin{document}
    
    O Treasury of Good Things, Ever-flowing fountain, Holy Father, etc etc
    O Treasury of Good Things, Ever-flowing fountain, Holy Father, etc etc
    \begin{prayerheading}
    Tuesday Morning-Prayer V
    \end{prayerheading}
    
    O Treasury of Good Things, Ever-flowing fountain, Holy Father, etc etc
    O Treasury of Good Things, Ever-flowing fountain, Holy Father, etc etc
    \end{document}
    
  2. 在结束环境后添加一个\par(这样就不需要明确给出一个空行);注意,在这种情况下,需要 在环境定义中使用\begin{center}和而\end{center}不是:\center\endcenter

    \documentclass{book}
    \usepackage{xcolor}
    
    \newenvironment{prayerheading}
      {\begin{center}\large\bfseries\color{red}}
      {\end{center}\par}
    
    \begin{document}
    O Treasury of Good Things, Ever-flowing fountain, Holy Father, etc etc
    O Treasury of Good Things, Ever-flowing fountain, Holy Father, etc etc
    \begin{prayerheading}
    Tuesday Morning-Prayer V
    \end{prayerheading}
    O Treasury of Good Things, Ever-flowing fountain, Holy Father, etc etc
    O Treasury of Good Things, Ever-flowing fountain, Holy Father, etc etc
    \end{document}
    

在此处输入图片描述

  1. 使用该titlesec包并自定义一个分段单元标题来产生所需的布局;在下面的例子中我使用了\subsection*(因为使用了无星号的版本\titlespacing,所以下面的段落将收到标准缩进):

    \documentclass{book}
    \usepackage{xcolor}
    \usepackage{titlesec}
    
    \titleformat{name=\subsection,numberless}
      {\normalfont\large\bfseries\filcenter\color{red}}{}{0em}{}
    \titlespacing{\subsection}
      {0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
    
    \begin{document}
    O Treasury of Good Things, Ever-flowing fountain, Holy Father, etc etc
    O Treasury of Good Things, Ever-flowing fountain, Holy Father, etc etc
    \subsection*{Tuesday Morning-Prayer V}
    O Treasury of Good Things, Ever-flowing fountain, Holy Father, etc etc
    O Treasury of Good Things, Ever-flowing fountain, Holy Father, etc etc
    \end{document}
    

在此处输入图片描述

相关内容