背景

背景

背景

希望使用标题的第一个字符来创建风格化的章节标题。

问题

文本的主干(下降部分)距离导致包含框架的偏移改变强调的第一个字母的位置,这从下图中可以明显看出:

有影响力的

下面代码中有问题的行是这一行,它被添加以确保标题文本不会引起换行,正如一个答案回到上一个问题:

\scale[maxwidth=\textwidth-(\marginwidth)]{#1}

当上面这一行简单来说就是:

#1

这样对齐就完美了,但是当文本太长时就会出现不必要的换行。

代码

一个最小的工作示例:

\definecolor[BookColourPrimary][h=A45F62]
\definecolor[BookColourSecondary][h=9A957A]
\definespotcolor[BookColourSecondaryLightest]
  [BookColourSecondary][a=1,t=.2]
\definefont[BookFontChapterHeader][SansBoldItalic scaled 5000]
\definefont[BookStyleFontChapterCharacter][SerifItalic scaled 20000]

\defineframed[BookStyleChapterFramed][
  frame=on,
  align={left,low,nothyphenated,verytolerant},
  width=\dimexpr\textwidth-(.2\marginwidth),
  height=\dimexpr\textheight+0.25\footerheight,
]

% Extract first character
\define[1]\BookStyleChapterChar{\cldcontext{string.sub("#1",1,1)}}

% Use a nested frame to keep the overlain large letter together with
% the chapter title.
\define[1]\BookStyleChapter{%
  \BookStyleChapterFramed{%
    \inframed[align=right, frame=on]{%
      \startoverlay
        % Calculate the large letter's offset using the first character's
        % width. This allows font changes without significantly affecting
        % the distance between the emphasized first character of the
        % chapter title and the complete chapter title.
        \setbox\scratchbox\hbox{%
          \BookStyleFontChapterCharacter\BookStyleChapterChar{#1}}%
        % Shift the first character back relative to the chapter title.
        \hskip-.55\wd\scratchbox%
        \color[BookColourSecondaryLightest]{%
          \BookStyleFontChapterCharacter%
          \BookStyleChapterChar{#1}%
        }
        \vskip-1.9em
        % Ensure the text fits on the page.
        \scale[maxwidth=\textwidth-(\marginwidth)]{#1}
      \stopoverlay
    }
  }
}

% Avoid duplication...
\define[1]\BookChapterText{
  \BookColourPrimary{\BookFontChapterHeader{\BookStyleChapter{#1}}}
}

\starttext
  \BookChapterText{Test-a}
  \page
  \BookChapterText{Test-g}
\stoptext

问题

如何让 ConTeXt 忽略字干高度,同时仍缩放文本以适合边距\textwidth

答案1

BookStyleChapterFramed 需要调整其高度:

height=\dimexpr\textheight-\footerheight,

框架需要根据phg评论进行调整:

\inframed[align=right, frame=off, location=height]

相关内容