以小写字母开头的第一行

以小写字母开头的第一行

我想用这个magaz包将文档文本的第一行排版为小写字母。但我还想将该行的首字母设置为大写字母。我无法同时满足这两个要求。

我尝试将lettrine同名包中的命令与包\FirstLine中的命令组合起来magaz,但结果——当我得到一个编译组合时——是小写字母行超出了文本的宽度。总而言之,我还没能弄清楚如何将开头的下拉大写字母与全小写字母的第一行文本结合起来。有人能提出一些暗示解决方案的建议吗?

根据请求,MWE:

\documentclass{memoir}

\usepackage{lettrine,magaz}

\begin{document}

\lettrine{A}{}{\FirstLine{<Insert here any dummy text spanning more than one line>.}}

\end{document}

答案1

这似乎有效,但我不能保证它不会引起任何其他麻烦......

首先,我采用了\FirstLinefrom的定义magaz.sty,并将所有出现的 替换\maxdim\linewidth

\makeatletter
\renewcommand\FirstLine[1]{\begingroup
 % typeset text 3 times: 1) using all breaks to count segments; 2) with
 % a full first line and \FirstLineFont to get first line and remaining
 % segments; 3) Using current font, keeping only `remaining segments'
 % on a single line.
 \setbox\z@\box\mz@firstbox \setbox\z@\box\mz@remains % void the global boxes
 \hbadness\linewidth \hfuzz\linewidth
 \setbox\@tempboxa\vbox{% 1) use all breaks
   \hsize\z@ \leftskip\z@skip \rightskip\z@skip \parfillskip\fill
   \parshape\z@ \pretolerance\m@ne \tolerance\@ne
   \doublehyphendemerits\z@ \finalhyphendemerits\z@
   #1\global\mathchardef\mz@spf\spacefactor\@@par
   \global\mathchardef\mz@numl\prevgraf
 }% end vbox "1)"
 \setbox\@tempboxa\vbox{% 2) first line, plus other segments
   \parshape \tw@ \z@\hsize \z@\linewidth
   \doublehyphendemerits\z@ \finalhyphendemerits\z@
   \pretolerance\m@ne \parfillskip\fill
   {\FirstLineFont{#1}\@@par}%
   \ifnum\prevgraf>\tw@ % Bad argument: not simple text or too much text
     \mz@handlebad{#1}%
   \else
     \unskip\unkern\unpenalty \unskip\unkern\unpenalty
     \ifnum\prevgraf<\tw@ % All text fits on first line
       \setbox\z@\lastbox
       \global\setbox\mz@firstbox\hbox{\unhbox\z@\unskip}%
       \global\setbox\mz@remains\hbox{}%
     \else % 2 lines: text fills first line with some left over
       \setbox\z@\lastbox
       \ifvoid\z@ % could not grab last line
         \mz@handlebad{#1}%
       \else
         \unskip\unkern\unpenalty \unskip\unkern\unpenalty
         \global\setbox\mz@firstbox\lastbox % 2a) break up "other segments"
         \hsize\z@ \leftskip\z@skip \rightskip\z@skip \parfillskip\fill
         \parshape\z@ \pretolerance\m@ne \tolerance\@ne
         \noindent\nobreak % \nobreak because leftskip adds breakpoint
         \unhbox\z@\unskip\@@par % gives number of "extra segments"
         \@tempcnta\mz@numl \advance\@tempcnta-\prevgraf
         \advance\@tempcnta\@ne % number of segs in 1st line plus 1
         \edef\@tempa{\the\@tempcnta\space}% 3) Collect "other segments"
         \@whilenum \@tempcnta>\@ne\do{% build \parshape lines
           \edef\@tempa{\@tempa \z@\z@}%
           \advance\@tempcnta\m@ne
         }%
         \parshape \@tempa \z@\linewidth
         #1\@@par
         \unskip\unkern\unpenalty \unskip\unkern\unpenalty
         \global\setbox\mz@remains\lastbox
       \fi
     \fi
   \fi
 }% end vbox "2)"
 \endgroup
 \ifvoid\mz@firstbox #1% Error case: just output the text
 \else
   \noindent
   \unhbox\mz@firstbox\unskip\unskip\unpenalty\break
   \unhbox\mz@remains\unskip\unskip\unpenalty \spacefactor\mz@spf
 \fi
}
\makeatother

然后我定义了一个接受两个参数的新命令\firstline,第一个是第一个大写字母,第二个是的参数\FirstLine

\newcommand{\firstline}[2]{\lettrine{#1}{\hspace{-\parindent}}\FirstLine{#2}}

因此你可以写类似

\firstline{I}{nsert here any dummy very very very very very long text spanning more than one line.}

在您的文档中。

梅威瑟:

\documentclass{memoir}

\usepackage{lettrine,magaz}

\makeatletter
\renewcommand\FirstLine[1]{\begingroup
 % typeset text 3 times: 1) using all breaks to count segments; 2) with
 % a full first line and \FirstLineFont to get first line and remaining
 % segments; 3) Using current font, keeping only `remaining segments'
 % on a single line.
 \setbox\z@\box\mz@firstbox \setbox\z@\box\mz@remains % void the global boxes
 \hbadness\linewidth \hfuzz\linewidth
 \setbox\@tempboxa\vbox{% 1) use all breaks
   \hsize\z@ \leftskip\z@skip \rightskip\z@skip \parfillskip\fill
   \parshape\z@ \pretolerance\m@ne \tolerance\@ne
   \doublehyphendemerits\z@ \finalhyphendemerits\z@
   #1\global\mathchardef\mz@spf\spacefactor\@@par
   \global\mathchardef\mz@numl\prevgraf
 }% end vbox "1)"
 \setbox\@tempboxa\vbox{% 2) first line, plus other segments
   \parshape \tw@ \z@\hsize \z@\linewidth
   \doublehyphendemerits\z@ \finalhyphendemerits\z@
   \pretolerance\m@ne \parfillskip\fill
   {\FirstLineFont{#1}\@@par}%
   \ifnum\prevgraf>\tw@ % Bad argument: not simple text or too much text
     \mz@handlebad{#1}%
   \else
     \unskip\unkern\unpenalty \unskip\unkern\unpenalty
     \ifnum\prevgraf<\tw@ % All text fits on first line
       \setbox\z@\lastbox
       \global\setbox\mz@firstbox\hbox{\unhbox\z@\unskip}%
       \global\setbox\mz@remains\hbox{}%
     \else % 2 lines: text fills first line with some left over
       \setbox\z@\lastbox
       \ifvoid\z@ % could not grab last line
         \mz@handlebad{#1}%
       \else
         \unskip\unkern\unpenalty \unskip\unkern\unpenalty
         \global\setbox\mz@firstbox\lastbox % 2a) break up "other segments"
         \hsize\z@ \leftskip\z@skip \rightskip\z@skip \parfillskip\fill
         \parshape\z@ \pretolerance\m@ne \tolerance\@ne
         \noindent\nobreak % \nobreak because leftskip adds breakpoint
         \unhbox\z@\unskip\@@par % gives number of "extra segments"
         \@tempcnta\mz@numl \advance\@tempcnta-\prevgraf
         \advance\@tempcnta\@ne % number of segs in 1st line plus 1
         \edef\@tempa{\the\@tempcnta\space}% 3) Collect "other segments"
         \@whilenum \@tempcnta>\@ne\do{% build \parshape lines
           \edef\@tempa{\@tempa \z@\z@}%
           \advance\@tempcnta\m@ne
         }%
         \parshape \@tempa \z@\linewidth
         #1\@@par
         \unskip\unkern\unpenalty \unskip\unkern\unpenalty
         \global\setbox\mz@remains\lastbox
       \fi
     \fi
   \fi
 }% end vbox "2)"
 \endgroup
 \ifvoid\mz@firstbox #1% Error case: just output the text
 \else
   \noindent
   \unhbox\mz@firstbox\unskip\unskip\unpenalty\break
   \unhbox\mz@remains\unskip\unskip\unpenalty \spacefactor\mz@spf
 \fi
}
\makeatother

\newcommand{\firstline}[2]{\lettrine{#1}{\hspace{-\parindent}}\FirstLine{#2}}

\begin{document}

\firstline{I}{nsert here any dummy very very very very very long text spanning more than one line.}

\end{document} 

输出:

在此处输入图片描述

答案2

我通过搜索找到了这个老话题。Karl 的答案对我(或 OP)不起作用。但与 OP 一样,我的自定义文档类中可能发生了其他事情,干扰了 Karl 的答案。我自己快速浏览了一下,我怀疑在所有情况下,\lettrine它们\FirstLine是否都能很好地协同工作。

唯一令人满意的解决方案是“手动操作”。但有一个技巧:不要将小写字母文本作为 的第二个强制参数\lettrine。相反,使用空括号来吸收第二个强制参数。然后跟上\textsc{text in small caps} more text...

\lettrine命令将其第二个强制参数放在一个框中。这意味着它不能在需要换行的地方换行。如果您尝试强制换行,那么第一行可能会太短或太长。

但是当您使用\textsc它时,它的内容可以换行,也可以连字。因此,在\textsc第一行中放置比您认为需要的更多的文本。编译并查看它换行的位置。然后将文本量减少到该点。您可以在单词中间\textsc结束,它将很好地连字。\textsc

\documentclass[letterpaper]{article}
\usepackage{lmodern} % scalable font
\usepackage{lettrine}
\begin{document}
\lettrine[lines=3,findent=0pt,nindent=0pt]{O}{}\textsc{ne dark and stormy night, Lord Withens mounted his horse} and sneaked out the servants' door. Don't know what gave him the idea that the servants didn't notice. But then, the servants know how to keep it quiet. That's how it is in these British novels.
\end{document}

上述代码的结果

“马”之后的结论\textsc是一个反复试验的过程。

高级:以下内容不适用于pdflatex。但适用LuaLaTeXfontspecpolyglossiamicrotypeactive 。该字体是一种 Open Type 字体,并且\textsc被定义为使用 从字体自己的 Open Type 功能中选择小写字母fontspec。我不知道其中有多少是必需的;但在我看来,如果您使用其中的一些,您可能会像我一样使用全部。

再次强调,技巧是使用空白括号吸收 的第二个参数\lettrine,然后使用 手动选择小写字母的第一行\textsc。但与基本 不同pdflatex,如果需要,您可以在单词中间的连字符处断开第一行。

在此示例中,初步编译显示第一行断开为 ECTOXYLO-PHONE:

\lettrine[lines=3,findent=0.2em]{O}{}\textsc{ne stormy night, Lord Withens rode his ectoxylophone through the gloom.} What's that? Don't know what an ectoxylophone is, eh? Neither did Lord Withens. He thought it was his horse.

然后,将右括号移动到连字点:

\lettrine[lines=3,findent=0.2em]{O}{}\textsc{ne stormy night, Lord Withens rode his ectoxylo}phone through the gloom. What's that? Don't know what an ectoxylophone is, eh? Neither did Lord Withens. He thought it was his horse.

高级代码的结果

相关内容