完全居中的诗歌环境

完全居中的诗歌环境

This is LuaHBTeX, Version 1.15.0 (TeX Live 2022)

你好。我正在尝试在 lualatex 中排版一些诗句。这是我想要获得的内容: 在此处输入图片描述 给定以下 mwe:

\documentclass{book}
\usepackage{showframe}
\usepackage{verse}

\newcommand{\attrib}[1]{%
\nopagebreak{\raggedleft\footnotesize #1\par}}
\renewcommand{\poemtitlefont}{\normalfont\large\itshape\centering}

\begin{document}

\settowidth{\versewidth}{We do injuriously by licensing and prohibiting,}
\begin{verse}[\versewidth]
    \begin{center}
        Though all the winds of doctrine\\
        Were let loose to play upon the earth;\\
        So Truth be in the field,\\
        We do injuriously by licensing and prohibiting,\\
        to misdoubt her strength.\\
        Let her and falsehood grapple,\\
        Who ever knew Truth put to the worse,\\
        In a free and open encounter.
    \end{center}
\end{verse}
\attrib{Milton}

\end{document}

我得到以下信息: 在此处输入图片描述

如您所见,第一行与其余行完全未对齐,即使对齐,整个块也与正常打印区域未对齐,事实上,使用 showframe 包时它似乎是右对齐的。

答案1

可选的 width 参数用于将左对齐的诗句设置为居中。要真正将行本身居中,您不应使用此参数,而应仅使用\begin{center}\end{center}或更灵活的\centering

除了第一行以外,此方法有效,第一行仍是左对齐的。您可以手动添加水平空间,使此行居中,水平空间的大小为最长行的宽度减去第一行的宽度除以二。

梅威瑟:

\documentclass{book}
\usepackage{showframe}
\usepackage{verse}

\newcommand{\attrib}[1]{%
\nopagebreak{\raggedleft\footnotesize #1\par}}
\renewcommand{\poemtitlefont}{\normalfont\large\itshape\centering}

\newlength{\firstline}
\begin{document}

\settowidth{\versewidth}{We do injuriously by licensing and prohibiting,}
\settowidth{\firstline}{Though all the winds of doctrine}
\begin{verse}
\centering
\hspace{\dimexpr(\versewidth-\firstline)/2}Though all the winds of doctrine\\
Were let loose to play upon the earth;\\
So Truth be in the field,\\
We do injuriously by licensing and prohibiting,\\
to misdoubt her strength.\\
Let her and falsehood grapple,\\
Who ever knew Truth put to the worse,\\
In a free and open encounter.
\end{verse}
\attrib{Milton}
\end{document}

在此处输入图片描述

但确实正如评论中指出的那样不是使用verse包或环境,即

\documentclass{book}
\usepackage{showframe}
\newcommand{\attrib}[1]{%
\nopagebreak{\raggedleft\footnotesize #1\par}}
\begin{document}
\begin{center}
Though all the winds of doctrine\\
Were let loose to play upon the earth;\\
So Truth be in the field,\\
We do injuriously by licensing and prohibiting,\\
to misdoubt her strength.\\
Let her and falsehood grapple,\\
Who ever knew Truth put to the worse,\\
In a free and open encounter.
\end{center}
\attrib{Milton}
\end{document}

更容易。

答案2

正如您所发现的,该verse环境与不兼容。center

在这里,我提出了一个修改后的center环境,以保证诗句和(可选)归属之间没有分页符。

\documentclass{book}
\usepackage{showframe}

\NewDocumentEnvironment{centerverse}{o}
 {%
  \parindent=0pt
  \par\addvspace{\topsep}
  \leftskip=0pt plus 1fill \rightskip=0pt plus 1fill
  \let\\\break
  \interlinepenalty10000
 }
 {%
  \par\nobreak
  \IfValueT{#1}{\makebox[\columnwidth][r]{\footnotesize#1\qquad}}\par
  \addvspace{\topsep}
 }

\begin{document}

%\vspace*{34\baselineskip}
%\vspace*{34.5\baselineskip}

Noted for his desire to diffuse the truth throughout the
world, he penned these words:

\begin{centerverse}[Milton]
Though all the winds of doctrine\\
Were let loose to play upon the earth;\\
So Truth be in the field,\\
We do injuriously by licensing and prohibiting,\\
to misdoubt her strength.\\
Let her and falsehood grapple,\\
Who ever knew Truth put to the worse,\\
In a free and open encounter.
\end{centerverse}

\end{document}

在此处输入图片描述

如果取消注释第一\vspace*行,诗歌将位于页面底部。如果取消注释第二行,整首诗将移至下一页。

这也许可以得到改进,以允许在选定点处分页,并在节之间提供空间。

相关内容