问题澄清

问题澄清

我需要防止我的 TikZ 覆盖的字体设置继承发货时的字体设置。我知道这是一个分组问题,因为}在发货时尚未达到本地化字体更改的结束。

所以也许另一种问这个问题的方式是说“我怎样才能使我的 TikZ 覆盖成为全局范围的一部分”?

问题澄清

在示例中,您将看到第 2 页上覆盖的字体大小受到了第 2 页上 shipout 设置的不良影响。

推理

假设我想创建一个名为“开发者模式”的草稿模式,我可以打开和关闭它。此模式使用由 TikZ 创建的叠加层,并使用 放置在每个页面上(发货时)atbegshi。不幸的是,发货时有效的字体设置由 TikZ 叠加层继承。我可以明确设置每个字体设置,但我认为更聪明的方法是某种方式隔离范围。

代码

\documentclass{article}
\usepackage{fontspec}% xelatex
\usepackage{tikz}
\usetikzlibrary{calc}% for calculating distance between points
\usepackage{tikzpagenodes}% get area nodes
\usepackage{atbegshi}% for shipout access
\usepackage{lipsum}% for dummy text
\definecolor{blueprint}{cmyk}{.85,.51,0,0}% For visual effect

\makeatletter% for \f@size
\def\printfontsize{\f@size pt}
\makeatother

\def\false{false}
\def\officialbuild{false}
\ifx\officialbuild\false
  \AtBeginShipout{\AtBeginShipoutUpperLeftForeground{\draftpage}}% use upperleftforeground to make (0,0) at north west corner as TikZ expects
\fi

\def\draftpage{
  \begin{tikzpicture}[overlay,remember picture]
    \tikzset{blueprintmeasurement/.style={draw,dashed,color=blueprint,<->,opacity=0.5}}
    \tikzset{blueprintborder/.style={draw,color=blueprint,opacity=0.5}}
    \tikzset{blueprinttext/.style={color=blueprint,opacity=0.5}}
    \node [blueprinttext,anchor=north east,font=\sffamily\bfseries] at ($(current page.north east)+(-2mm,-2mm)$) {{Developer Mode \printfontsize}};
     % Draw Current Page Text Area Frame
    \draw [blueprintborder]% text area west
      let \p{pathID1} = ($(current page text area.south west)-(current page text area.north west)$)
        in
          (current page text area.north west)
          node [left,yshift=-1cm] {\pgfmathparse{veclen(\x{pathID1},\y{pathID1})/1mm}\pgfmathprintnumber[precision=2]{\pgfmathresult} mm}
        to
          (current page text area.south west);
    \draw [blueprintborder]% text area north
      let \p{pathID} = ($(current page text area.north east)-(current page text area.north west)$)
        in
          (current page text area.north west)
          node [above,xshift=1cm] {\pgfmathparse{veclen(\x{pathID},\y{pathID})/1mm}\pgfmathprintnumber[precision=2]{\pgfmathresult} mm}
        to (current page text area.north east);
    \draw [blueprintborder] % text area east
      (current page text area.north east)
      to (current page text area.south east);
    \draw [blueprintborder] % text area south
      (current page text area.south east)
      to (current page text area.south west);
        % Margins
    \draw [blueprintmeasurement]% left margin
      let \p{pathID} = ($(current page text area.west)-(current page.west)$)
        in
        (current page.west)
          node [above,xshift=10mm] {\pgfmathparse{veclen(\x{pathID},\y{pathID})/1mm}\pgfmathprintnumber[precision=2]{\pgfmathresult} mm}
        to (current page.west -| current page text area.west);
    \draw [blueprintmeasurement]% right margin
      let \p{pathID} = ($(current page text area.east)-(current page.east)$)
        in
        (current page.east)
          node [above,xshift=-10mm] {\pgfmathparse{veclen(\x{pathID},\y{pathID})/1mm}\pgfmathprintnumber[precision=2]{\pgfmathresult} mm}
        to (current page.west -| current page text area.east);
    \draw [blueprintmeasurement]% top margin
      let \p{pathID} = ($(current page text area.north)-(current page.north)$)
        in
        (current page.north)
          node [left,yshift=-10mm] {\pgfmathparse{veclen(\x{pathID},\y{pathID})/1mm}\pgfmathprintnumber[precision=2]{\pgfmathresult} mm}
        to (current page text area.north -| current page.north);
    \draw [blueprintmeasurement]% top margin
      let \p{pathID} = ($(current page text area.south)-(current page.south)$)
        in
        (current page.south)
          node [left,yshift=20mm] {\pgfmathparse{veclen(\x{pathID},\y{pathID})/1mm}\pgfmathprintnumber[precision=2]{\pgfmathresult} mm}
        to (current page text area.south -| current page.south);
  \end{tikzpicture}
}

\begin{document}
\section{Section of Lipsum in \textbackslash normalfont}
\printfontsize\ \lipsum
\section{Section of Lipsum in \textbackslash tiny}
{\tiny\printfontsize\ \lipsum
\lipsum}
\section{Following tiny font}
\lipsum[1]
\end{document}

输出

在此处输入图片描述 在此处输入图片描述

相关内容