为所有页面(第一页除外)添加虚线(垂直)时出错

为所有页面(第一页除外)添加虚线(垂直)时出错

我想为整个文档创建一条虚线,该虚线应在页边距后开始(在我的示例中,我将其设置为距纸张左边缘 3 厘米)。我发现这个帖子并尝试通过用ruledashrule 替换来将其用于我的代码,但他告诉我包括它在内的代码存在以下错误:

Missing number, treated as zero. \lipsum[1-10]
Missing number, treated as zero. \lettergroup{\begin{turn}{270} B \end{turn}}
Missing number, treated as zero. \lettergroup{C}
Missing number, treated as zero. \lettergroup{D}
Missing number, treated as zero. \lettergroup{E}
Missing number, treated as zero. \lettergroup{F}
Missing number, treated as zero. \lettergroup{G}
Missing number, treated as zero. \end{document}
usage of obsolete package!(scrpage2) Package `scrpage2' is obsolete.
seems you are using a constant headheight.
Font shape `OT1/cmss/bx/sl' undefined(Font) using `OT1/cmss/bx/n' instead
Some font shapes were not available, defaults substituted.
Label(s) may have changed. Rerun to get cross-references right.

遗憾的是,我不知道 TeX 试图通过该错误告诉我什么。

这是我插入的内容(当它开始失败时):

% everypage
\usepackage{everypage}
\usepackage[absolute]{textpos}
\usepackage{dashrule}

% for some blindtext
\usepackage{lipsum}

\begin{document}

\AddEverypageHook{
    \ifnum\thepage>1
    \begin{textblock}{1,21}(3.5,7)
        \hdashrule[0.5ex]{0.2pt}{\pageheigth}
    \end{textblock}
    \fi
}

%This part usually works but fails as I insert the code above
\lettergroup{\begin{turn}{270} A \end{turn}}

\section{A}
\lipsum[1-10]

完整代码:

\documentclass[a4paper]{article}

\usepackage[
%bindingoffset=0.2in,%
left=3cm,right=3cm,top=3cm,bottom=3cm,%
footskip=.25in]{geometry}

% load TikZ to draw the boxes
\usepackage{tikz}
\usetikzlibrary{calc}

% use scrpage2 or whatever you want to add
% the boxes to the header to make them appear
% on every page
\usepackage{scrpage2}
\pagestyle{scrheadings}

% rotation of letters for some cool styles
\usepackage{rotating}

% format colors
\usepackage{xcolor}

\definecolor{biffyellow}{RGB}{255,230,0}
\definecolor{pagebackground}{RGB}{243, 244, 239}%243, 239, 244}

%format page-background
\pagecolor{pagebackground}

% new counter to hold the current number of the 
% letter to determine the vertical position
\newcounter{letternum}
% newcounter to set the number of thumbs fitting vertical
% and setting the height of a boxes
\newcounter{letterdiv}
\setcounter{letterdiv}{6}
% some margin settings
\newlength{\thumbtopmargin}
\setlength{\thumbtopmargin}{0.5cm}
\newlength{\thumbbottommargin}
\setlength{\thumbbottommargin}{0.5cm}
% calculate the box height by dividing the page height
\newlength{\thumbheight}
\pgfmathsetlength{\thumbheight}{%
    (\paperheight-\thumbtopmargin-\thumbbottommargin)%
    /%
    \value{letterdiv}
}
% box width
\newlength{\thumbwidth}
\setlength{\thumbwidth}{1cm}
% style the boxes
\tikzset{
    thumb/.style={
        fill=biffyellow,
        text=black,
        minimum height=\thumbheight,
        text width=\thumbwidth,
        outer sep=0pt,
        font=\sffamily\bfseries\Huge,
        inner xsep=1.5em,
    }
}
% create two new commands to make the thumbs
% that makes it easy to use them im different header elements,
% like in the plain and normal page style etc.
\newcommand{\evenpageletterthumb}[1]{%
     % see pgfmanual.pdf for more information about this part
     \begin{tikzpicture}[remember picture, overlay]
         \node [thumb,align=left,anchor=north west,] at ($%
             (current page.north west)-%
             (0,{\thumbtopmargin+(\value{letternum}-1)*\thumbheight})%
         $) {#1};
     \end{tikzpicture}
}
\newcommand{\oddpageletterthumb}[1]{%
     \begin{tikzpicture}[remember picture, overlay]
         \node [thumb,align=right,anchor=north east,] at ($%
             (current page.north east)-%
             (0,{\thumbtopmargin+(\value{letternum}-1)*\thumbheight})%
         $) {#1};
     \end{tikzpicture}
}
% create a new command to set a new lettergroup
\newcommand{\lettergroup}[1]{%
    % but I recommend to start a new page
    \clearpage
    % set a title (optional)
    %{\Huge\bfseries\sffamily #1}\par\bigskip
    % check if we reached the last vertical position and reset it
    \ifnum\value{letternum}=\value{letterdiv}\relax
        \setcounter{letternum}{0}%
    \fi
    % check if we reached the last vertical position and reset it
    \ifnum\value{letternum}=\value{letterdiv}\relax
        \setcounter{letternum}{0}%
    \fi
    \stepcounter{letternum}%
    % use one head or foot element to put in the box
    % it doesn't matter which you use since the box
    % is positioned on the page absolutely
    \lohead[\oddpageletterthumb{#1}]{\oddpageletterthumb{#1}}%
    \lehead[\evenpageletterthumb{#1}]{\evenpageletterthumb{#1}}%
}

% customize sections format
\usepackage{titlesec}

\titleformat{\section}
{\Huge\bfseries\sffamily}
{\thesection}{1em}{}

%suppress page numbering
\pagenumbering{gobble}


%
%
% My routine starts here
%
%

% everypage
\usepackage{everypage}
\usepackage[absolute]{textpos}
\usepackage{dashrule}

% for some blindtext
\usepackage{lipsum}

\begin{document}

\AddEverypageHook{
    \ifnum\thepage>1
    \begin{textblock}{1,21}(3.5,7)
        \hdashrule[0.5ex]{0.2pt}{\pageheigth}
    \end{textblock}
    \fi
}


\lettergroup{\begin{turn}{270} A \end{turn}}

\section{A}
\lipsum[1-10]

\lettergroup{\begin{turn}{270} B \end{turn}}
\lipsum[1]

\lettergroup{C}
\lipsum[1]

\lettergroup{D}
\lipsum[1]

\lettergroup{E}
\lipsum[1]

\lettergroup{F}
\lipsum[1]

\lettergroup{G}
\lipsum[1]

\end{document}

答案1

首先,我最小化了你的例子。所有的 TiZ 内容和部分格式等与问题无关。剩余代码存在多个问题:

  • 没有定义任何\pageheigth内容\pageheight
  • \hdashrule和的语法textblock都是错误的;
  • \pagenumbering{gobble}如果你想做你想做的事,你就不能做,\ifnum\thepage<1因为你已经吞噬了\thepage你要求 TeX 进行测试;
  • \hdashrule产生水平虚线规则 - 而不是垂直虚线规则。

我并不总是能够辨别你的意图。具体如下:

  • 我使用\paperheight,但你可能想要textheight
  • 我修改了语法\hdashruletextblock因此代码可以编译并在第一页之后的左边距产生一条虚线垂直线,但您需要使用它作为模板并替换您想要的值;
  • 我去掉了狼吞虎咽;
  • 我改变了规则。

如果您只是不想打印页码,请使用\pagestyle{empty}and/or\thispagestyle{empty}或重新定义页脚,如果您想要页眉,如代码所示。很难猜出这里想要什么。您可能最好测试底层计数器而不是其文本表示,但吞噬所有编号仍然是一个坏主意。

请注意,您的原始代码也导致了许多来自 KOMA 的警告。KOMA 脚本包与geometry或不能很好地兼容titlesec,因此请考虑使用 KOMA 建议的或用于titleps页眉和页脚的脚本包。

无论如何,这有点像你想要的:

\documentclass[a4paper]{article}
\usepackage[left=3cm,right=3cm,top=3cm,bottom=3cm,footskip=.25in]{geometry}

% rotation of letters for some cool styles
\usepackage{rotating}

% everypage
\usepackage{everypage}
\usepackage[absolute]{textpos}
\usepackage{dashrule}

% for some blindtext
\usepackage{lipsum}

\begin{document}

\AddEverypageHook{%
  \ifnum\thepage>1
  \begin{textblock}{1}[0,0](0.8,0)
    \begin{turn}{270}\hdashrule[0pt]{\paperheight}{1pt}{3pt}\end{turn}
  \end{textblock}%
  \fi
}

\section{A}
\lipsum[1-20]


\end{document}

请注意,如果您无论如何都要加载tikz,那么您可能很快就会使用它并textpos完全取消它。另请参阅background包,这可能会让这变得更容易。

第一页后左边距处的虚线

相关内容