运行我的 latex 文件时出现错误:
A number should have been here; I inserted `0'. (If you can't figure out why I needed to see a number, look up `weird error' in the index to The TeXbook.)
经过多次测试,我意识到错误一定出在下面几行,但我不明白我做错了什么。我为这些行的“粗鲁”道歉,并提前感谢您的评论。
%Test for making chapter marks
\usepackage{background}
\usetikzlibrary{calc}
\usepackage{xifthen}
\usepackage{totcount}
\usepackage{lipsum}
% This registers the counter ''chapter'' as total counter.
\regtotcounter{chapter}
\backgroundsetup%
{ contents={%
\begin{tikzpicture}[overlay]
% \totvalue{} returns the maximum value of the counter, that in our case is ''chapter''
% The following line defines \mytotalchapters macro, if the number of chapter is larger then 0
% then the macro is equal to the total number of chapters, otherwise it is equal to 6. Finally,
% \pgfmathtruncatemactro truncates the decimal part, returning back an integer.
\pgfmathtruncatemacro{\mytotalchapters}{\totvalue{chapter} > 0 ? \totvalue{chapter} : 6}
% \paperheight is the physical height of the page in pt
\pgfmathsetmacro{\mypaperheight}{\paperheight/28.453}
% The chapter returns the number of the chapter
\pgfmathsetmacro{\mytop}{-(\thechapter-1)/\mytotalchapters*\mypaperheight}
\pgfmathsetmacro{\mybottom}{-\thechapter/\mytotalchapters*\mypaperheight}
\xdef\mytop{-8} \xdef\mybottom{-9} \xdef\num{}
\ifnum \thechapter=1 \xdef\mytop{12.25} \xdef\mybottom{9.92} \xdef\num{I} \fi
\ifnum \thechapter=2 \xdef\mytop{9.92} \xdef\mybottom{7.45} \xdef\num{2} \fi
\ifnum \thechapter=3 \xdef\mytop{7.45} \xdef\mybottom{4.95} \xdef\num{3} \fi
\ifnum \thechapter=4 \xdef\mytop{4.95} \xdef\mybottom{2.45} \xdef\num{4} \fi
\ifnum \thechapter=5 \xdef\mytop{2.45} \xdef\mybottom{-0.05} \xdef\num{5} \fi
\ifnum 128<\thepage<135 \xdef\mytop{-0.05} \xdef\mybottom{-0.75} \xdef\num{B} \fi
\ifnum 134<\thepage < 137 \xdef\mytop{-0.75} \xdef\mybottom{-1.45} \xdef\num{R} \fi
\ifnum 136<\thepage<149 \xdef\mytop{-1.45} \xdef\mybottom{-3.45} \xdef\num{S} \fi
\ifnum 148<\thepage \xdef\mytop{-8} \xdef\mybottom{-9} \xdef\num{S} \fi
\xdef\mycolor{gray}
%\draw[help lines] (-10,-6) grid (0,17); this grid helps to define distances
height
\ifthenelse{\isodd{\value{page}}}
{\fill[\mycolor] (8.3,\mybottom) rectangle (9,\mytop);\fill[\mycolor, opacity=1.] (8.4,{\mybottom+(\mytop-\mybottom)/2.}) circle (0.3) node {\num};\fill[fill=yellow] (8.35,{\mybottom+(\mytop-\mybottom)/2.}) node {\textcolor{black} \large {\num}};}
{\fill[\mycolor] (-8.3,\mybottom) rectangle (-9,\mytop);\fill[\mycolor, opacity=1.] (-8.4,{\mybottom+(\mytop-\mybottom)/2.}) circle (0.3) node {\num};\fill[fill=yellow] (-8.35,{\mybottom+(\mytop-\mybottom)/2.}) node {\textcolor{black} \large {\num}};}
\end{tikzpicture}
},
scale=1,
angle=0
}