我有这个要求,即使用首字母大写,并使用 parshape。我本来想使用莱特林还有类似的东西皮辛帕尔或者皮钦斯,但所有这些似乎都是\parshape
内部使用的,因此不能很好地协同工作。
一种选择似乎是重新定义\lettrine
宏并在使用它之前修改其内容\L@parshape
,但这看起来超出了我的能力。
然后我认为应该可以使用该\hanging
包并在完成后应用 parshape \hangpara{2\baselineskip}{-2}
,但仍然没有运气,因为它也不能很好地播放\parshape
。
经过一段时间的折腾,我终于想出了一个看似可行的办法,代码和输出如下所示。我使用 xetex 进行编译,pdfLaTeX 输出看起来略有不同。
主要问题是:我假设我使用此代码犯了多项罪行。它们是什么?我应该如何更改?
梅威瑟:
\documentclass[a4paper]{scrbook}
\usepackage[showframe]{geometry}
\usepackage{xparse}
\usepackage{xcolor}
\newlength{\myindent}
\newlength{\mywindow}
\newlength{\myline}
\newlength{\myshortline}
\newlength{\htdiff}
\NewDocumentCommand{\dropcap}{m m}{%
% #1: window text
% #2: dropped cap
% width to reserve for dropped cap
\setlength{\myindent}{2\baselineskip}%
% width of short part of parshape
\setlength{\myline}{.5\textwidth}%
% width of short part of parshape with dropped cap
\setlength{\myshortline}{\myline}%
\addtolength{\myshortline}{-\myindent}%
% start
\leavevmode
% define parshape
\parshape 5 \myindent \myshortline \myindent \myshortline 0pt \myline 0pt \myline 0pt \textwidth
% "window" output
\smash{%
\hskip-\myindent
\hskip\textwidth
\llap{%
\setlength{\fboxsep}{0pt}%
\colorbox{green}{%
% adjust vertical position (tables!)
\settoheight{\htdiff}{#1}%
\addtolength{\htdiff}{-\ht\strutbox}%
\raisebox{-\htdiff}{%
\vtop to 4\baselineskip{%
\hsize\myline
#1\vfill
}%
}%
}%
}%
\hskip\myindent
\hskip-\textwidth
}%
% dropped cap
\smash{%
\llap{%
\raisebox{-\baselineskip}{%
\hbox to \myindent{%
\fontsize{32pt}{30pt}%
\selectfont%
\null\hfill\textcolor{red}{#2}\hfill\null
}%
}%
}%
}%
}
\setlength{\parindent}{0pt}
\begin{document}
\dropcap{This is a test for a text that should appear in the window cut out by my fancy parshape. I made it work, but probably not without committing several crimes ...}{1}%
This is a paragraph that should start with a dropped capital. But it should also utilize \textit{parshape}, which is why the \textit{lettrine} package does not seem to be an option. And here's some more useless text. And still more text, and more, and more, and more, and more, and more, and more, and even more.
\
\
\dropcap{%
\begin{tabular*}{.4\textwidth}{r|l}
this & now after some fiddling\\
with & vertical position\\
also & works as I'd have expected.
\end{tabular*}}{2}%
This is a paragraph that should start with a dropped capital. But it should also utilize \textit{parshape}, which is why the \textit{lettrine} package does not seem to be an option. And here's some more useless text. And still more text, and more, and more, and more, and more, and more, and more, and even more.
\end{document}
输出: