verse
软件包中有\settowidth
命令可以将诗歌置于中心。例如:
\settowidth{\versewidth}{There was an old party of Lyme}
\begin{verse}[\versewidth]
There was an old party of Lyme \\
Who married three wives at one time. \\
\vin When asked: ‘Why the third?’ \\
\vin He replied: ‘One’s absurd, \\
And bigamy, sir, is a crime.’
\end{verse}
我有很多诗歌,不可能为每个人都做到这一点。
有没有一种方法可以做同样的事情而不需要规范\versewidth
?
例如这样:
\begin{verse}
\start{unknown_command}
There was an old party of Lyme \\
Who married three wives at one time. \\
\vin When asked: ‘Why the third?’ \\
\vin He replied: ‘One’s absurd, \\
And bigamy, sir, is a crime.’
\end{unknown_command}
\end{verse}
答案1
最后一个\cenverse
似乎是你期望的命令。当然,它可以转换成环境。你的打油诗的前两次出现是为了比较。
\documentclass{article}
\usepackage{verse}
\begin{document}
I have a lot of poetry, and it's impossible to do this for everyone.
I have a lot of poetry, and it's impossible to do this for everyone.
\settowidth{\versewidth}{There was an old party of Lyme}
\begin{verse}[\versewidth]
There was an old party of Lyme \\
Who married three wives at one time. \\
\vin When asked: ‘Why the third?’ \\
\vin He replied: ‘One’s absurd, \\
And bigamy, sir, is a crime.’
\end{verse}
I have a lot of poetry, and it's impossible to do this for everyone.
I have a lot of poetry, and it's impossible to do this for everyone.
\begin{verse}
There was an old party of Lyme \\
Who married three wives at one time. \\
\vin When asked: ‘Why the third?’ \\
\vin He replied: ‘One’s absurd, \\
And bigamy, sir, is a crime.’
\end{verse}
\def\cenverse#1\\{\settowidth{\versewidth}{#1}\begin{verse}[\versewidth]#1\\}
I have a lot of poetry, and it's impossible to do this for everyone.
I have a lot of poetry, and it's impossible to do this for everyone.
\cenverse
There was an old party of Lyme \\
Who married three wives at one time. \\
\vin When asked: ‘Why the third?’ \\
\vin He replied: ‘One’s absurd, \\
And bigamy, sir, is a crime.’
\end{verse}
\end{document}
答案2
这将使用最宽的诗句来决定诗歌的宽度和中心。
\documentclass{article}
\usepackage{verse,varwidth,environ}
\usepackage{lipsum} % just for the example
\newsavebox{\versebox}
\NewEnviron{cverse}{%
\setlength{\leftmargini}{0pt}%
\begin{lrbox}{\versebox}
\begin{varwidth}{\textwidth}
\begin{verse}
\BODY
\end{verse}
\end{varwidth}
\end{lrbox}%
\begin{verse}[\wd\versebox]
\BODY
\end{verse}
}
\begin{document}
\lipsum[2]
\begin{cverse}
There was an old party of Lyme \\
Who married three wives at one time. \\
\vin When asked: ‘Why the third?’ \\
\vin He replied: ‘One’s absurd, \\
And bigamy, sir, is a crime.’
\end{cverse}
\begin{cverse}
Clof, clop, cloch,\\
cloffete,\\
cloppete,\\
clocchette,\\
chchch\dots\\
\`E gi\`u,\\
nel cortile,\\
la povera\\
fontana\\
malata;\\
che spasimo!\\
sentirla\\
tossire.\\
Tossisce,\\
tossisce,\\
un poco\\
si tace\dots\\
di nuovo.\\
tossisce.
\end{cverse}
\end{document}
第二首诗是阿尔多·帕拉泽斯基 (Aldo Palazzeschi) 的《病态喷泉》 (La fontana malata) 的开头。
我用varwidth
它来测量宽度;由于verse
工作原理,我们需要将其设置\leftmargini
为零(设置在内部cverse
,因此是本地的)。
如果你需要诗歌脚注,请将上面的代码改为
\newsavebox{\versebox}
\newcounter{mockfootnote}
\NewEnviron{cverse}{%
\setlength{\leftmargini}{0pt}%
\begin{lrbox}{\versebox}
% remember the current value of footnote
\setcounter{mockfootnote}{\value{footnote}}%
% disable footnotes in the first pass over the poem
\renewcommand\footnote[1]{\stepcounter{mockfootnote}\textsuperscript{\themockfootnote}}%
\begin{varwidth}{\textwidth}
\begin{verse}
\BODY
\end{verse}
\end{varwidth}
\end{lrbox}%
\begin{verse}[\wd\versebox]
\BODY
\end{verse}
}