页边距中的页码和页面周围的框架:如何以合理的方式进行操作?

页边距中的页码和页面周围的框架:如何以合理的方式进行操作?

我在 tikz 中创建了一个漂亮的框架(嗯……以我的标准来说很不错)。从另一个问题中汲取灵感(即使用背景包获取特定类型的页面边框),tikzpagenodes这样边距的改变就不会影响边框。

我还决定在页面边缘放置页码,直接使用我在 stackexchange 上找到的代码(外边距中的页码会影响垂直标尺)。

以下是示例代码:

\documentclass[a4paper,11pt,twoside]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[B1,T1]{fontenc}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[margin=45mm]{geometry}

% page number in margins
\usepackage{scrpage2}
\clearscrheadfoot
\pagestyle{scrheadings}
\setlength{\footskip}{0pt}
\rofoot[\centerpageno{o}]{\centerpageno{o}}
\lefoot[\centerpageno{e}]{\centerpageno{e}}
\def\centerpageno#1{\leavevmode
  \vbox to 0pt{
    \vss
    \hbox to 0pt{\large
      \if#1o\kern 1.15cm\else\hss\fi\thepage
      \if#1o\hss\else\kern 1.15cm\fi}
    \vskip.5\textheight
    \vskip\baselineskip}}


\usepackage{background}
\usetikzlibrary{calc}
\usepackage{tikzpagenodes}

\backgroundsetup%
{   contents={
        \begin{tikzpicture}[overlay]   
        \checkoddpage
        \ifoddpage         
            \draw[color=BrickRed,line width=5pt, opacity=1] ($(current page text area.south west)+(-1.5,-1.5)$) rectangle ($(current page text area.north east)+(1.5,1.5)$);
            \draw[black, opacity=1] ($(current page text area.south west)+(-1.7,-1)$) -- ($(current page text area.north west)+(-1.7,1)$) -- ($(current page text area.north west)+(-1.25,1)$) -- ($(current page text area.north west)+(-1.25,1.7)$) -- ($(current page text area.north west)+(-1.7,1.7)$)  -- ($(current page text area.north west)+(-1.7,1.25)$) -- ($(current page text area.north west)+(-1,1.25)$)  -- ($(current page text area.north west)+(-1,1.7)$) -- ($(current page text area.north east)+(1,1.7)$) -- ($(current page text area.north east)+(1,1.25)$) -- ($(current page text area.north east)+(1.7,1.25)$) -- ($(current page text area.north east)+(1.7,1.7)$) -- ($(current page text area.north east)+(1.25,1.7)$) -- ($(current page text area.north east)+(1.25,1)$) -- ($(current page text area.north east)+(1.7,1)$) -- ($(current page text area.south east)+(1.7,-1)$) -- ($(current page text area.south east)+(1.25,-1)$) -- ($(current page text area.south east)+(1.25,-1.7)$) -- ($(current page text area.south east)+(1.7,-1.7)$) -- ($(current page text area.south east)+(1.7,-1.25)$) -- ($(current page text area.south east)+(1,-1.25)$) -- ($(current page text area.south east)+(1,-1.7)$)  -- ($(current page text area.south west)+(-1,-1.7)$) -- ($(current page text area.south west)+(-1,-1.25)$) -- ($(current page text area.south west)+(-1.7,-1.25)$) -- ($(current page text area.south west)+(-1.7,-1.7)$) -- ($(current page text area.south west)+(-1.25,-1.7)$) -- ($(current page text area.south west)+(-1.25,-1)$) -- ($(current page text area.south west)+(-1.7,-1)$) ;
            \draw[color=BrickRed,line width=5pt,opacity=1,fill=white] ($(current page text area.north east)+(1.5,-10.12)$) circle (25pt);
\else
            \draw[color=BrickRed,line width=5pt, opacity=1] ($(current page text area.south west)+(-1.5,-1.5)$) rectangle ($(current page text area.north east)+(1.5,1.5)$);
            \draw[black, opacity=1] ($(current page text area.south west)+(-1.7,-1)$) -- ($(current page text area.north west)+(-1.7,1)$) -- ($(current page text area.north west)+(-1.25,1)$) -- ($(current page text area.north west)+(-1.25,1.7)$) -- ($(current page text area.north west)+(-1.7,1.7)$)  -- ($(current page text area.north west)+(-1.7,1.25)$) -- ($(current page text area.north west)+(-1,1.25)$)  -- ($(current page text area.north west)+(-1,1.7)$) -- ($(current page text area.north east)+(1,1.7)$) -- ($(current page text area.north east)+(1,1.25)$) -- ($(current page text area.north east)+(1.7,1.25)$) -- ($(current page text area.north east)+(1.7,1.7)$) -- ($(current page text area.north east)+(1.25,1.7)$) -- ($(current page text area.north east)+(1.25,1)$) -- ($(current page text area.north east)+(1.7,1)$) -- ($(current page text area.south east)+(1.7,-1)$) -- ($(current page text area.south east)+(1.25,-1)$) -- ($(current page text area.south east)+(1.25,-1.7)$) -- ($(current page text area.south east)+(1.7,-1.7)$) -- ($(current page text area.south east)+(1.7,-1.25)$) -- ($(current page text area.south east)+(1,-1.25)$) -- ($(current page text area.south east)+(1,-1.7)$)  -- ($(current page text area.south west)+(-1,-1.7)$) -- ($(current page text area.south west)+(-1,-1.25)$) -- ($(current page text area.south west)+(-1.7,-1.25)$) -- ($(current page text area.south west)+(-1.7,-1.7)$) -- ($(current page text area.south west)+(-1.25,-1.7)$) -- ($(current page text area.south west)+(-1.25,-1)$) -- ($(current page text area.south west)+(-1.7,-1)$) ;
            \draw[color=BrickRed,line width=5pt,opacity=1,fill=white] ($(current page text area.north west)+(-1.5,-10.12)$) circle (25pt);            
\fi
\end{tikzpicture}
    },
    scale=1,
    angle=0
}

\usepackage{lipsum}



\begin{document}
\lipsum
\addtocounter{page}{+10}
\lipsum
\addtocounter{page}{+100}
\end{document}

可以看到,页边距中的页码不在圆圈内居中(为了更好地显示效果,我放大了字体);这是因为在添加数字时页码没有水平居中。

有没有办法使页码水平居中,以便无论数字有多少位,数字都保持在一个点的中心?

附加问题:有没有办法在同一点绘制圆圈,这样我就不必手动定位它了?

谢谢。

答案1

有一种可能性是:不要\draw使用圆圈并放置页码scrheadings,而是使用圆形\node直接放置页码:

\documentclass[a4paper,11pt,twoside]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[B1,T1]{fontenc}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[margin=45mm]{geometry}

\usepackage{scrpage2}
\clearscrheadfoot
\pagestyle{scrheadings}
\setlength{\footskip}{0pt}


\usepackage{background}
\usetikzlibrary{calc}
\usepackage{tikzpagenodes}

\backgroundsetup%
{   contents={
        \begin{tikzpicture}[overlay]   
        \checkoddpage
        \ifoddpage         
            \draw[color=BrickRed,line width=5pt, opacity=1] 
            ($(current page text area.south west)+(-1.5,-1.5)$) 
              rectangle 
            ($(current page text area.north east)+(1.5,1.5)$);
            \draw[black, opacity=1] ($(current page text area.south west)+(-1.7,-1)$) -- ($(current page text area.north west)+(-1.7,1)$) -- ($(current page text area.north west)+(-1.25,1)$) -- ($(current page text area.north west)+(-1.25,1.7)$) -- ($(current page text area.north west)+(-1.7,1.7)$)  -- ($(current page text area.north west)+(-1.7,1.25)$) -- ($(current page text area.north west)+(-1,1.25)$)  -- ($(current page text area.north west)+(-1,1.7)$) -- ($(current page text area.north east)+(1,1.7)$) -- ($(current page text area.north east)+(1,1.25)$) -- ($(current page text area.north east)+(1.7,1.25)$) -- ($(current page text area.north east)+(1.7,1.7)$) -- ($(current page text area.north east)+(1.25,1.7)$) -- ($(current page text area.north east)+(1.25,1)$) -- ($(current page text area.north east)+(1.7,1)$) -- ($(current page text area.south east)+(1.7,-1)$) -- ($(current page text area.south east)+(1.25,-1)$) -- ($(current page text area.south east)+(1.25,-1.7)$) -- ($(current page text area.south east)+(1.7,-1.7)$) -- ($(current page text area.south east)+(1.7,-1.25)$) -- ($(current page text area.south east)+(1,-1.25)$) -- ($(current page text area.south east)+(1,-1.7)$)  -- ($(current page text area.south west)+(-1,-1.7)$) -- ($(current page text area.south west)+(-1,-1.25)$) -- ($(current page text area.south west)+(-1.7,-1.25)$) -- ($(current page text area.south west)+(-1.7,-1.7)$) -- ($(current page text area.south west)+(-1.25,-1.7)$) -- ($(current page text area.south west)+(-1.25,-1)$) -- ($(current page text area.south west)+(-1.7,-1)$) ;
            \node[draw=BrickRed,line width=5pt,opacity=1,fill=white,circle,inner sep=17.5pt,align=center,text=black,font=\slshape\large] at ($(current page text area.north east)+(1.5,-10.12)$) {\thepage};
\else
            \draw[color=BrickRed,line width=5pt, opacity=1] ($(current page text area.south west)+(-1.5,-1.5)$) rectangle ($(current page text area.north east)+(1.5,1.5)$);
            \draw[black, opacity=1] ($(current page text area.south west)+(-1.7,-1)$) -- ($(current page text area.north west)+(-1.7,1)$) -- ($(current page text area.north west)+(-1.25,1)$) -- ($(current page text area.north west)+(-1.25,1.7)$) -- ($(current page text area.north west)+(-1.7,1.7)$)  -- ($(current page text area.north west)+(-1.7,1.25)$) -- ($(current page text area.north west)+(-1,1.25)$)  -- ($(current page text area.north west)+(-1,1.7)$) -- ($(current page text area.north east)+(1,1.7)$) -- ($(current page text area.north east)+(1,1.25)$) -- ($(current page text area.north east)+(1.7,1.25)$) -- ($(current page text area.north east)+(1.7,1.7)$) -- ($(current page text area.north east)+(1.25,1.7)$) -- ($(current page text area.north east)+(1.25,1)$) -- ($(current page text area.north east)+(1.7,1)$) -- ($(current page text area.south east)+(1.7,-1)$) -- ($(current page text area.south east)+(1.25,-1)$) -- ($(current page text area.south east)+(1.25,-1.7)$) -- ($(current page text area.south east)+(1.7,-1.7)$) -- ($(current page text area.south east)+(1.7,-1.25)$) -- ($(current page text area.south east)+(1,-1.25)$) -- ($(current page text area.south east)+(1,-1.7)$)  -- ($(current page text area.south west)+(-1,-1.7)$) -- ($(current page text area.south west)+(-1,-1.25)$) -- ($(current page text area.south west)+(-1.7,-1.25)$) -- ($(current page text area.south west)+(-1.7,-1.7)$) -- ($(current page text area.south west)+(-1.25,-1.7)$) -- ($(current page text area.south west)+(-1.25,-1)$) -- ($(current page text area.south west)+(-1.7,-1)$) ;
            \node[draw=BrickRed,line width=5pt,opacity=1,fill=white,circle,inner sep=17.5pt,align=center,text=black,font=\slshape\large] at ($(current page text area.north west)+(-1.5,-10.12)$) {\thepage};            
\fi
\end{tikzpicture}
    },
    scale=1,
    angle=0
}

\usepackage{lipsum}



\begin{document}
\lipsum
\addtocounter{page}{+10}
\lipsum
\addtocounter{page}{+100}
\end{document}

在此处输入图片描述

相关内容