派生文章类别derivedarticle.cls

派生文章类别derivedarticle.cls

所以我注意到当\hoffset\voffset改变时,TikZ 不再找到正确的原点。 是否可以帮助 TikZ 找到正确的原点?(比如全局转移之类的?)

另外,为什么该geometry包不首先设置\hoffset\voffset设置为-1in,而是稍后将其包含在计算中?无论如何,它使用\def\Gm@magtooffset{%并提到每个偏移量 4 次,因此它会对它们进行处理。

无论如何,在查看几何代码之前,我曾尝试编写自己的代码。我注意到我会怎么做不同于几何是如何做到的,我称之为自上而下、从左到右的方法固定正文文本区域方法, 分别。

自上而下、从左到右的方法

仅凭信息\topmargin就让我发疯。甚至size10.clo包含

 \addtolength\topmargin{-\footskip}     % this might be wrong!

我认为它错误(除非通过除以 2 来完美居中正文区域,我猜当它乘以 0.5 时就可以做到这一点)

  1. 首先反转 1 英寸的内置 TeX 边距。

自顶向下

  1. \headheight
  2. \headsep
  3. \footskip
  4. 由此计算\topmargin\textheight

左右

  1. 从...开始\oddsidemargin
  2. 由此计算\textwidth

请注意,即使我将偏移量设置为 0,并从 oddsidemargin 和 topmargin 中减去 1 英寸,TikZ 也无法通过此方法找到正确的原点。 另请注意,我不需要或不打算在文档中使用边注,因此我只需将这些值设置为零。

固定正文文本区域方法

geometry包中: 在此处输入图片描述

\topmargin请注意固定的文本高度和文本宽度(用作其他计算的基础)以及此代码如何在和的计算中减去 1 英寸\oddsidemargin,我认为这是为了否定 1 英寸的内置 TeX 边距。

派生文章类别derivedarticle.cls

这两个方法均未注释,这意味着底部方法将覆盖第一个方法。固定正文文本区域方法位于下方,且在此优先。

\ProvidesClass{derivedarticle}[1642 v 0.01 derived article class with different dimensions (jlk)]
\LoadClass{article}

\global\def\@mm{mm}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TOP DOWN, LEFT RIGHT METHOD: HOW I WOULD DO IT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% BASELINE PAGE OFFSETS
\hoffset         -1in % <-- reverse irritating TeX built-in 1in left margin
\voffset         -1in % <-- reverse irritating TeX built-in 1in top margin
% TOP DOWN ALIGNMENT
\headheight             1\baselineskip  % header box height
\headsep                10\@mm  % distance from bottom of header box to top of body box, can cancel out footer margin!
\footskip               \dimexpr 10\@mm + \baselineskip\relax  % distance from bottom of body box to BOTTOM of footer box, if 0, then body box will not subtract anything from its height and extend to end of the page

\topmargin              \dimexpr \headheight + \headsep \relax % distance from top of page to top of header box
\textheight             \dimexpr \paperheight - \headheight - \headsep - \footskip -2cm \relax

\marginparpush          0\@mm  % minimum space below margin notes boxes and the next box

% LEFT RIGHT ALIGNMENT
\oddsidemargin          \dimexpr 20\@mm \relax  % left margin for even/odd pages in single-side docs
\textwidth              \dimexpr (\paperwidth - 2\oddsidemargin) \relax

\marginparsep           0\@mm  % distance from right of body area to margin notes area


%END%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FIXED BODY TEXT AREA METHOD: GEOMETRY PACKAGE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \setlength\textwidth{7in}
%      \setlength\textheight{10in}
%      \setlength\oddsidemargin{(\paperwidth-\textwidth)/2 - 1in}
%      \setlength\topmargin{(\paperheight-\textheight
% -\headheight-\headsep-\footskip)/2 - 1in}

% BASELINE PAGE OFFSETS
\hoffset         0in % <-- reverse irritating TeX built-in 1in left margin
\voffset         0in % <-- reverse irritating TeX built-in 1in top margin

% TOP DOWN ALIGNMENT
\headheight             1\baselineskip  % header box height
\headsep                10\@mm  % distance from bottom of header box to top of body box, can cancel out footer margin!
\footskip               \dimexpr 10\@mm + \baselineskip\relax  % distance from bottom of body box to BOTTOM of footer box, if 0, then body box will not subtract anything from its height and extend to end of the page

\textheight             43\baselineskip % <-- FIXED TEXTHEIGHT
\topmargin              \dimexpr (\paperheight - \textheight - \headheight - \headsep - \footskip)/2 - 1 in \relax % <-- reverse irritating TeX build-in 1in left margin here


\marginparpush          0\@mm  % minimum space below margin notes boxes and the next box

% LEFT RIGHT ALIGNMENT
\textwidth              7 in % <-- FIXED TEXTWIDTH
\oddsidemargin          \dimexpr (\paperwidth-\textwidth)/2 - 1 in % <-- reverse irritating TeX build-in 1in left margin here


\marginparsep           0\@mm  % distance from right of body area to margin notes area

\endinput

使用派生文章类的文档

本文档有一个 TikZ 覆盖,用于演示目的。

\documentclass{derivedarticle}
\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

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

\def\draftpage{% <-- normally in a savebox to calculate once for better performance
  \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}};
     % 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}
\lipsum
\end{document}

输出 hoffset 和 voffset 设置为 -1in

在此处输入图片描述

输出 hoffset 和 voffset 不变

在此处输入图片描述

答案1

答案似乎是双重的。

不要改变偏移量,因为

  1. 许多包(可能错误地)依赖于\hoffset并且\voffset为 0。摘要:不要改变它。(除非计算机与打印机接口存在问题) - 感谢 egreg
  2. 蒂克兹如果从边距中取出 1 英寸,则找到正确的页面原点。

我很固执,无论如何我都会改变 hoffset 和 voffsets!

不建议这么做。 调整的方法tikzpagenodes是在加载后添加此项并删除英寸调整:

\def\current@textarea@left{(-1in+\hoffset+\currentsidemargin)}
\def\current@textarea@top{(-1in+\voffset+\topmargin+\headheight+\headsep)}

我还不确定该如何做tikz,或多或少是因为有很多文件需要整理。

我对包裹假设的思考

盲目地依赖偏移量为 0 似乎并不是一个好主意。例如,如果我真的有打印错误怎么办(正如 egreg 在评论中提出的现实情况)?我需要稍微调整一下偏移量,在这种情况下,TikZ 覆盖坐标会偏离相同的量。这是一个小问题,但对齐对于视觉上吸引人的文档很重要。

\documentclass{derivedarticle}
\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

\AtBeginShipout{\AtBeginShipoutUpperLeftForeground{\draftoverlay}}% use upperleftforeground to make (0,0) at north west corner as TikZ expects


\def\draftoverlay{% <-- normally in a savebox to calculate once for better performance
  \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}};
     % 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}
\draftoverlay%
\tikz [overlay,remember picture] \node [fill=black,anchor=north west] at (current page.north west) {};%
\tikz [overlay,remember picture] \node [fill=black,anchor=south west] at (current page.south west) {};%
\tikz [overlay,remember picture] \node [fill=black,anchor=north east] at (current page.north east) {};%
\tikz [overlay,remember picture] \node [fill=black,anchor=south east] at (current page.south east) {};%
\lipsum
\end{document}

相关内容