如果可能的话,如何将引文归属右对齐,并与引文在同一行?

如果可能的话,如何将引文归属右对齐,并与引文在同一行?

引文通常将署名置于右对齐位置:

引用内容右对齐,引用内容位于引用下方

引文后面的引文注释另起一行。但是,假设引文最后一行有足够的空白来容纳引文注释。那么我们可能希望它在同一行,以避免过多的空白。

引用内容与右对齐归属在同一行

我们想要定义一个命令(称之为quoteattr),来计算报价是否合适,并自动将其放置在相应的位置。

没有命令定义的代码:

\documentclass[12pt]{book}

\begin{document}

\quoteattr{Early to bed and early to rise,\\
Makes a man healthy, wealthy, and wise.}{Benjamin Franklin, 1706--1790}

\quoteattr{Seek not the favor of the multitude; it is seldom got by honest and lawful means. But seek the testimony of few; and number not voices, but weigh them.}{Immanuel Kant, 1724--1804}

\end{document}

答案1

看来该tabto计划可以在这方面提供帮助。

\documentclass[12pt]{book}
\usepackage{tabto}
\def\quoteattr#1#2{\setbox0=\hbox{#2}#1\tabto{\dimexpr\linewidth-\wd0}\box0}
\parskip 1em
\begin{document}
\quoteattr{Early to bed and early to rise,\\
Makes a man healthy, wealthy, and wise.}{Benjamin Franklin, 1706--1790}

\quoteattr{Seek not the favor of the multitude; it is seldom got by honest and lawful means. But seek the testimony of few; and number not voices, but weigh them.}{Immanuel Kant, 1724--1804}

\quoteattr{In attempting to make this not give enough space... Seek not the favor of the multitude; it is seldom got by honest and lawful means. But seek the testimony of few; and number not voices, but weigh them.}{Immanuel Kant, 1724--1804}
\end{document}

在此处输入图片描述

答案2

这可以以经典的 TeX 方式使用宏来处理TeXBook,第 106 页,只需摆弄处罚、跳过和框即可:

\def\signed #1 (#2){{\unskip\nobreak\hfil\penalty50
    \hskip2em\hbox{}\nobreak\hfil\sl#1\/ \rm(#2)
    \parfillskip=0pt \finalhyphendemerits=0 \par}}

您可以按如下方式输入报价:

\begin{quote}Here is one way to solve the problem.
    \signed Donald E. Knuth (Berkeley, CA)
\end{quote}

如果在同一行上有 2em 的空间和签名,那么就行了;否则,就换行。当然,也许你只想要一个名字,而不是名字和位置,或者你只是想要更像 LaTeX 风格;在这种情况下,你可以这样做:

\def\signed#1{{\unskip\nobreak\hfil\penalty50
    \hskip2em\hbox{}\nobreak\hfil\sl#1
    \parfillskip=0pt \finalhyphendemerits=0 \par}}

您可以像上面一样输入,但是要用\signed{Donald E. Knuth}代替。

答案3

为了实现这一点,我们将使用\newsavebox来查找填充空行的长度。我们不能使用\hfill,因为它的名义长度始终为 0。相反,我们将使用 包linegoal

我们还将使用它xifthen来让我们写条件。

需要两次传球。

\documentclass[12pt]{book}

\usepackage{linegoal}
\usepackage{xifthen}

\newsavebox{\quotebox}
\newlength{\emptywidth}% To save the length of empty space
\newlength{\attrwidth}% To save the length of the attribution

% Define the new command
\newcommand{\quoteattr}[2]{
  \begin{quote}#1%
  \begin{lrbox}{\quotebox}\hspace{\linegoal}\end{lrbox}
  \setlength{\emptywidth}{\linegoal}
  \settowidth{\attrwidth}{\textit{#2}}
  % The following line can be tweaked to force attributions
  % onto a new line if it would be a very tight squeeze
  \addtolength{\attrwidth}{0em}
  % Compare the two widths.
  \ifthenelse{\lengthtest{\emptywidth>\attrwidth}}
    % If it fits:
    {\null\hfill\textit{#2}}
    % If it doesn't:
    % We need to provide a stretch in this way because TeX
    % might compress a slightly-too-long line to prevent
    % a loose line followed by a lonely word. However, then
    % on the next run, TeX won't compress it because of the
    % following text on a new line.
    {\hspace{0pt plus \textwidth minus 3pt}\null\nopagebreak\linebreak\null\hfill{\textit{#2}}}%

  % For debugging, display the lengths.
  Empty space: \the\emptywidth
  \\Attribution space: \the\attrwidth
  \end{quote}
}

\begin{document}

\quoteattr{Early to bed and early to rise,\\
Makes a man healthy, wealthy, and wise.}{Benjamin Franklin, 1706--1790}

\quoteattr{Seek not the favor of the multitude; it is seldom got by honest and lawful means. But seek the testimony of few; and number not voices, but weigh them.}{Immanuel Kant, 1724--1804}

\end{document}

相关内容