需要帮助构建环境

需要帮助构建环境

我正在排版文档,并尝试将命令转换为环境。这是原始代码和第一个环境(实际上有效)。

\newcommand{\crub}[1]{%
\begin{center}
\textcolor{red}{\textbf{\small #1}}%
\end{center}
}

\newenvironment{crub}{   % new environment instead of command
\begin{trivlist}
\centering
\bfseries
\color{red}
\item\relax
}{\end{trivlist}}

现在,这是我似乎无法进入适当环境的命令的代码。

\newcommand{\psalmheading}[1]{%
\begin{center}
\noindent\textcolor{red}{\textbf{\large #1}}%
\end{center}
}

为了进一步解释,这里是我尝试将命令更改为环境之前的原始文档的一部分:

%Beginning of the Preamble % % % % % % % % % % % % % % % % % % % %

%Document Class and Packages to use % % % % % % % % % % % % % % % %
\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[left=2.05cm,right=2.10cm,top=2.45cm,bottom=2.5cm]{geometry}
\usepackage{amsmath,amssymb,color,fancyhdr,framed,titlesec}

\pagestyle{fancy}
\setcounter{chapter}{-1}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}
\lhead{\leftmark}
\rhead{\rightmark}
\cfoot{\thepage}

%Shortcut Commands % % % % % % % % % % % % % % % % % % % % % % % %
\newcommand\stich[1]{%
\textcolor{red}{S.  }#1%
}

\newcommand\response[1]{%
\textcolor{red}{R.  }#1%
}

\newcommand{\psalmheading}[1]{%
\begin{center}
\noindent\textcolor{red}{\textbf{\large #1}}%
\end{center}
}

\newcommand{\prayerheading}[1]{%
\begin{center}
\noindent\textcolor{black}{\textbf{\large #1}}%
\end{center}
}


\newcommand{\hourheading}[1]{%
\begin{center}
\noindent\textcolor{black}{\textbf{\large #1}}%
\end{center}
}

\newcommand{\lessonheading}[1]{%
\begin{center}
\noindent\normalsize\textcolor{red}{#1}
\end{center}
}

\newcommand{\rub}[1]{%
\textcolor{red}{\textbf{\small #1}}%
}

\newcommand{\brub}[1]{%
\textcolor{black}{\textbf{\small #1}}%
}

\newcommand{\crub}[1]{%
\begin{center}
\textcolor{red}{\textbf{\small #1}}%
\end{center}
}

\newcommand{\cbrub}[1]{%
\begin{center}
\textcolor{red}{\textbf{\small #1}}%
}


%Formatting to Center the Chapter, Section, and Subsection Titles % 
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries\centering}{}{20pt}{\Huge}
\titlespacing*{\chapter}
{0pt}{50pt}{40pt}

\titleformat{\section}
{\normalfont\Large\bfseries\centering}{}{1em}{}
\titlespacing*{\section}
{0pt}{3.5ex plus 1.0ex minus 0.2ex}{2.3ex plus 0.2ex}

\titleformat{\subsection}
{\normalfont\large\bfseries\centering}{}{1em}{}
\titlespacing*{\subsection}
{0pt}{3.25ex plus 1.0ex minus 0.2ex}{1.5ex plus 0.2ex}
%End of the Preamble % % % % % % % % % % % % % % % % % % % % % % % 

%Title Info % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\title{AN ORTHODOX RULE OF PRAYER.}
\author{Father Thomas Moore, Michael Dykes}
\date{\today}
\begin{document}
\maketitle
\tableofcontents



\part{SUNDAY PRAYERS.}
\chapter{SATURDAY EVENING PRAYERS.}
\crub{Towards evening, we stand before the holy icons (having lit a candle     and maybe some incense), with reverence and fear of God; we gather our thoughts, make the Sign of the Cross, and say:}

In the Name of the Father, and of the Son, and of the Holy Spirit. Amen.

\begin{framed}
\crub{From St. Thomas Sunday until Ascension, instead of \textbf{O God,  cleanse me, a sinner \ldots we say:}}
\textrm{Christ is risen from the dead, trampling down death by death, and  upon those in the tombs bestowing life. \crub{(thrice)}}

\crub{During any Vigil-rank Festal Period [(see Appendix A) - including your and your Temple's Patronal Feast Day], we begin our prayers by praying the Festal Troparia (again, see Appendix A).}

\crub{Then, in either case, we immediately pray the Trisagion Prayers as below:}
\end{framed}

\crub{Afterwards, we collect our thoughts, and make seven prostrations (or metanoias), saying:}

\section{THE SEVEN--BOW BEGINNING.}
O God, be merciful to me, a sinner. 

O God, cleanse me, a sinner, and have mercy on me.

Thou hast created me, O Lord, have mercy on me. 

Countless times have I sinned, O Lord, forgive me. 

All-holy Lady Theotokos, save me, a sinner, 

O Angel, my holy Guardian, protect me from all evil. 

O Saint, \crub{N}, my Patron pray to God for me. 

\crub{Then, we begin the Evening Prayers with these words:}

\section{THE INTRODUCTORY PRAYERS.}
O Lord Jesus Christ our God, through the prayers of our Thine All-pure Mother, of our holy and God-bearing Fathers, and of all the saints, have mercy on us. Amen.

Glory to Thee, O our God, Glory to Thee.

O Heavenly King, the Comforter, the Spirit of Truth, Who art everywhere present and fillest all things, Treasury of blessings and Giver of Life: Come and abide in us; and cleanse us from every impurity, and save our souls, O Good One.

\section{TRISAGION PRAYERS.}
Holy God. Holy Mighty. Holy Immortal. Have mercy on us. \crub{(thrice)}

\end{document}

编译后,我看到了章节标题,然后在这些标题的左侧,我看到了“阴影”章节标题。这就是我试图摆脱的。再次感谢,因为此时,我有点迷茫了。

答案1

您对环境的定义中存在不必要的部分crub

\newenvironment{crub}
  {\begin{center}\color{red}\bfseries\small}
  {\end{center}}

更简单。实际上center是用 定义的trivlist,但最好尽可能坚持使用更高级别的对象。

同样的策略适用于psalmheading

\newenvironment{psalmheading}
  {\begin{center}\color{red}\bfseries\large}
  {\end{center}}

您可能遇到了由启动 LR 模式引起的问题,\noindent因此您在输出中得到了虚假的空间;但缩进center无论如何都是零。

答案2

我希望这是一个解决方案(它定义环境psalmheading,仅使用 TeX 原语,我更喜欢这种方式):

\usepackage{xcolor}
\def\psalmheading{\center\large\bfseries\color{red}}
\def\endpsalmheading{\endcenter}

使用更标准的 LaTeX 命令应该是相同的:

\usepackage{xcolor}
\newenvironment{psalmheading}{% percent-sign and the end of line to remove spaces
  \center\large\bfseries\color{red}%
}{\endcenter}

\endcenter是 的结束命令\center。您习惯于输入\begin{center}...\end{center},但\center...\endcenter运行速度会更快一些(并且还有一些技术差异)。

并且您可以在 的位置使用任何格式命令\large\bfseries\color{red}

完整测试代码:

\documentclass{article}

\usepackage{xcolor}
\def\psalmheading{\center\begingroup\noindent\large\bfseries\color{red}}
\def\endpsalmheading{\endgroup\endcenter}

\usepackage{lipsum} % package to add some dummy text

\begin{document}

\lipsum[1] % inputs some random text

\begin{psalmheading}
\lipsum[2] % inputs some random text
\end{psalmheading}

\lipsum[3] % inputs some random text

\end{document}

编辑:rub环境中最棘手的是删除下一个空行(如果有的话):

\documentclass{article}

\usepackage{lipsum}
\usepackage{xcolor}

\makeatletter
% got from http://phaseportrait.blogspot.com/2011/08/using-gobblepars-to-prevent-latex-from.html
\newcommand\gobblepars{%
    \@ifnextchar\par%
        {\expandafter\gobblepars\@gobble}%
        {}}
\def\aftergobblepars{\expandafter\gobblepars}
\makeatother

\newenvironment{rub}{%
  \small\bfseries\color{red}%
}{%
  \quad % put any space command here
  \aftergroup\aftergobblepars\gobblepars%
}

\begin{document}

\lipsum[1]

\begin{rub}
LABEL
\end{rub}

\lipsum[4]

\end{document}

相关内容