自动调整首字下沉字母的高度

自动调整首字下沉字母的高度

我如何修改以下宏以自动获得图中所示高度的首字母?

\documentclass{article}

\makeatletter

\RequirePackage{tikz}

\newlength\CLett% Nuova dimensione

 \newcommand*\capolettera[2]{% #1 lettera da ingrandire #2 testo in maiuscoletto
\par\noindent\setbox\z@\hbox{%
             \scalebox{1.35}{%
                            \huge#1}%
                            }%
\CLett=\wd\z@\hangindent\CLett\hangafter-2\relax%
\raisebox{-\baselineskip}[0pt][0pt]{\llap{\box\z@\kern1pt}}\textsc{#2}}

\makeatother

\begin{document}

\capolettera{L}{orem ipsum} at nusquam appellantur his, ut eos erant homero
concludaturque. Albucius appellantur deterruisset id eam, vivendum
partiendo dissentiet ei ius. Vis melius facilisis ea, sea id convenire
referrentur, takimata adolescens ex duo. Ei harum argumentum per. Eam
vidit exerci appetere ad, ut vel zzril intellegam interpretaris.

\end{document}

在此处输入图片描述

答案1

在此处输入图片描述

我使用\resizebox而不是\scalebox强制首字母为\baselineskip+ 小型大写字母文本的高度。

\documentclass{article}

\makeatletter

\RequirePackage{tikz}

\newlength\CLett% Nuova dimensione

 \newcommand*\capolettera[2]{% #1 lettera da ingrandire #2 testo in maiuscoletto
\par\noindent
 \setbox8\hbox{\textsc{#2}}%
 \setbox\z@\hbox{%
             \resizebox{!}{\dimexpr\baselineskip+\ht8\relax}{%
                            \huge#1}%
                            }%
\CLett=\wd\z@\hangindent\CLett\hangafter-2\relax%
\raisebox{-\baselineskip}[0pt][0pt]{\llap{\box\z@\kern1pt}}{\box8}}

\makeatother

\begin{document}

\capolettera{L}{orem ipsum} at nusquam appellantur his, ut eos erant homero
concludaturque. Albucius appellantur deterruisset id eam, vivendum
partiendo dissentiet ei ius. Vis melius facilisis ea, sea id convenire
referrentur, takimata adolescens ex duo. Ei harum argumentum per. Eam
vidit exerci appetere ad, ut vel zzril intellegam interpretaris.

\end{document}

答案2

我非常喜欢这个。我做了一些小改动:1) 我引入了一个可选参数来告诉宏要删除多少行大写字母(默认值为 2);2) 我使用小写字母,\unhbox8这样小写字母之间的间距与行的其余部分一致。

\documentclass{article}

\makeatletter

\usepackage{graphicx}

\newlength\CLett% Nuova dimensione

 \newcommand*\capolettera[3][2]{% #1 lettera da ingrandire #2 testo in maiuscoletto
    \par
    \noindent
    \setbox8\hbox{\textsc{#3}}%
    \setbox\z@\hbox{%
        \resizebox{!}{\dimexpr#1\baselineskip-\baselineskip+\ht8\relax}{\huge#2}%
    }%
    \CLett=\wd\z@%
    \hangindent\CLett
    \hangafter-#1\relax
    \raisebox{\dimexpr-#1\baselineskip+\baselineskip\relax}[0pt][0pt]%
        {\llap{\box\z@\kern1pt}}{\unhbox8}%
}

\makeatother

\begin{document}

\capolettera[4]{L}{orem ipsum} at nusquam appellantur his, ut eos erant homero
concludaturque. Albucius appellantur deterruisset id eam, vivendum
partiendo dissentiet ei ius. Vis melius facilisis ea, sea id convenire
referrentur, takimata adolescens ex duo. Ei harum argumentum per. Eam
vidit exerci appetere ad, ut vel zzril intellegam interpretaris.

\end{document}

4 行首字下沉。

这个功能非常好用,因为你可以做这样的事情:

\capolettera[4]{\textbf{L}}{\kern-6pt orem ipsum}

在此处输入图片描述

相关内容