將詩歌歸屬與詩句寬度的右側而不是頁面的右側對齊

將詩歌歸屬與詩句寬度的右側而不是頁面的右側對齊

我想在回憶錄中加入一些詩的歸屬。下面的程式碼執行此操作,但將屬性刷新到文字區塊的右側。我希望它們與詩句寬度的右邊齊平。

\documentclass[11pt]{memoir}

\newcommand{\attrib}[1]{%
  \vskip2ex\nopagebreak{\raggedleft\footnotesize #1\par}}

\begin{document}

\settowidth{\versewidth}{``This boy is forest-born.''}
\begin{verse}[\versewidth]
``This boy is forest-born.''\\
\attrib{\textit{-- As You Like It}}
\end{verse}

\end{document}

答案1

這裡的宏\attrib可以採用可選參數來手動覆蓋\versewidth.將可選參數設定為\textwidth將使屬性相對於頁面右對齊,如 MWE 中所示。

\documentclass[11pt]{memoir}
\newcommand{\attrib}[2][\versewidth]{%
  \vskip2ex\nopagebreak{\raggedleft\footnotesize%
  #2\hspace{\dimexpr.5\textwidth-.5\dimexpr#1}\mbox{}\par}}

\begin{document}

\settowidth{\versewidth}{``This boy is forest-born.''}
\begin{verse}[\versewidth]
``This boy is forest-born.''\\
\attrib{\textit{-- As You Like It}}
\end{verse}

\settowidth{\versewidth}{``This boy is forest-born blah blah.''}
\begin{verse}[\versewidth]
``This boy is forest-born blah blah.''\\
\attrib{\textit{-- As You Like It}}
\end{verse}

\settowidth{\versewidth}{``Override the default attib placement.''}
\begin{verse}[\versewidth]
``Override the default attib placement.''\\
\attrib[\textwidth]{\textit{-- As You Like It}}
\end{verse}

\end{document}

在此輸入影像描述

相關內容