在amsart
包中,小节后的文本与小节标题在同一行。我想在小节后放置一些彩色文本。这是我的示例:
\documentclass{amsart}
\usepackage{xcolor}
\title{War and Peace}
\author{Leo Tolstoy}
\begin{document}
\maketitle
\section{Book One: 1805}
\subsection{Chapter 1}
{
\color{blue}
``Well, Prince, so Genoa and Lucca are now just family estates of the
Buonapartes. But I warn you, if you don't tell me that this means war, if you
still try to defend the infamies and horrors perpetrated by that Antichrist --- I
really believe he is Antichrist --- I will have nothing more to do with you and you
are no longer my friend, no longer my `faithful slave', as you call yourself!
But how do you do? I see I have frightened you --- sit down and tell me all the
news.''
}
It was in July, 1805, and the speaker was the well-known Anna Pavlovna Scherer,
maid of honor and favorite of the Empress Marya Fedorovna. With these words she
greeted Prince Vasili Kuragin, a man of high rank and importance, who was the
first to arrive at her reception. Anna Pavlovna had had a cough for some days.
She was, as she said, suffering from la grippe; grippe being then a new word in
St. Petersburg, used only by the elite.
\end{document}
我想要的是先显示一些彩色文本,然后再切换回普通文本。但是,括号中的文本被解析为命令的一些附加参数,\subsection
这意味着该子部分也是彩色的。我尝试在彩色区域前添加额外的括号,但这没有帮助。
有谁知道避免这种情况的优雅方法吗?
答案1
使用 \leavevmode。\textcolor 在您的示例中也有效,但如果参数中有一个新段落则不会喜欢。
\documentclass{amsart}
\usepackage{xcolor}
\title{War and Peace}
\author{Leo Tolstoy}
\begin{document}
\maketitle
\section{Book One: 1805}
\subsection{Chapter 1}
{\leavevmode\color{blue}%
``Well, Prince, so Genoa and Lucca are now just family estates of the
Buonapartes. But I warn you, if you don't tell me that this means war, if you
still try to defend the infamies and horrors perpetrated by that Antichrist --- I
really believe he is Antichrist --- I will have nothing more to do with you and you
are no longer my friend, no longer my `faithful slave', as you call yourself!
But how do you do? I see I have frightened you --- sit down and tell me all the
news.''
}
It was in July, 1805, and the speaker was the well-known Anna Pavlovna Scherer,
maid of honor and favorite of the Empress Marya Fedorovna. With these words she
greeted Prince Vasili Kuragin, a man of high rank and importance, who was the
first to arrive at her reception. Anna Pavlovna had had a cough for some days.
She was, as she said, suffering from la grippe; grippe being then a new word in
St. Petersburg, used only by the elite.
\end{document}
答案2
使用\textcolor{blue}{…}
而不是\color{blue}
产生所需的输出:
\documentclass{amsart}
\usepackage{xcolor}
\begin{document}
\subsection{Chapter 1}
\textcolor{blue}{Blue text.}
Black text.
\end{document}
原因是内联章节标题不会立即排版,而只会在下一个段落开始时排版;该段落以
``Well
其中第一个反引号是暂时搁置的触发器;只有在那时,TeX 才会插入记住的章节标题并从搁置的反引号开始重新排版段落。发生这种情况时,颜色已经设置为蓝色,因此标题也显示为蓝色。这种情况\textcolor
不会发生,因为\textcolor
问题\leavevmode
触发段落开头的前将当前颜色设置为蓝色。