2

I have created a nice frame (well... nice for my standards) in tikz. Taking inspiration from another question (namely Getting a particular kind of page border using background package ), I used tikzpagenodes so that changing in the margins wouldn't affect the border.

I also decided to put page numbers in the margins of the page, using directly code I found here on stackexchange as well (Page number in outer margin affects vertical ruler).

Here's a sample code:

\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}

As you can see, the page number in the margin is not centered inside the circle (I enlarged the font in order to better show the effect); this is because the page number isn't centered horizontally as the digits are added.

Is there a way to make the page number centered horizontally, so that the number remains centered on a point, regardless of the number of digits?

Bonus question: is there a way to draw the circle in that same point, so that I don't have to position it manually?

Thanks.

  • Do you want this page style for every page in your document? – Gonzalo Medina Mar 07 '15 at 16:28
  • My idea would be to have it on every page where there is a page number. Possible exception would be the title page, which I think I'll typeset separately and add at the end with \includepdf{*}. – greymatter0 Mar 07 '15 at 16:33

1 Answers1

4

Here's one possibility: instead of \drawing the circle and placing the page number using scrheadings, use a circular \node to place the page number directly:

\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}

enter image description here

Gonzalo Medina
  • 505,128