1

I'm using the below code which was supplied as an answer to another question here.

Problem is: In the very moment the pagestyles are declared with \DeclarePageStyleByLayers{firstpage}{topbox}, the pagenumber disappears. If the lines of \DeclarePageStyleByLayers... are marked (=taken out=without frame) then the pagenumber appears.

I'm actually olny using this code which was given to me, and I'm only understanding this on the surface. I would have expected that Tex puts the pagenumber and then would overlay the frame, but obviously that's not what happenes.

I would like to have the pagenumber within the frame. How to achieve that?

\documentclass{article}
\usepackage{scrlayer}
\usepackage{multicol}
\usepackage[savepos]{zref}
\usepackage{lipsum}

\newlength{\marginpadding}
\setlength{\marginpadding}{4pt}

\DeclareNewLayer[textarea,background,mode=picture,
  addheight=2\marginpadding,
  addwidth=2\marginpadding,
  addhoffset=-\marginpadding,
  addvoffset=-\marginpadding,
  contents={%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUR{\line(-1,0){\LenToUnit{\layerwidth}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{topbox}
\DeclareNewLayer[clone=topbox,
  contents={%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{midbox}
\DeclareNewLayer[clone=topbox,
  height={\pdfpageheight-\zposy{textbottom}sp-\layeryoffset-\baselineskip+\marginpadding},
  contents={%
  \putLL{\line(1,0){\LenToUnit{\layerwidth}}}%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{bottombox}
\DeclarePageStyleByLayers{firstpage}{topbox}   % delete the whole line to see the pagenumber to appear
\DeclarePageStyleByLayers{midpage}{midbox}     % delete the whole line to see the pagenumber to appear
\DeclarePageStyleByLayers{lastpage}{bottombox} % delete the whole line to see the pagenumber to appear
\pagestyle{midpage}
\begin{document}
\thispagestyle{firstpage}
\begin{multicols}{2}
  \lipsum[1-10]       
\end{multicols}

\lipsum[1-2]

\begin{multicols}{2}
  \lipsum[1-10]
\end{multicols}
\zsaveposy{textbottom}
\thispagestyle{lastpage}
\end{document}

3 Answers 3

3

The page number disappears because that's part of the pagestyle that has been replaced. To get it back, you just need to add another layer that contains the page number, along with anything else you want in the footer, and add the appropriate extra distance to extend the frame.

This version puts the page number centered and doesn't do any formatting with it. It will require modification if you want anything fancier, such as odd-even page changes.

\documentclass{article}
\usepackage{scrlayer}
\usepackage{multicol}
\usepackage[savepos]{zref}
\usepackage{lipsum}

\newlength{\marginpadding}
\setlength{\marginpadding}{4pt}

\DeclareNewLayer[foot,contents={\parbox{\layerwidth}{\centering\thepage}}]{pagenum}
\DeclareNewLayer[textarea,background,mode=picture,
  addheight=2\marginpadding+\footskip,
  addwidth=2\marginpadding,
  addhoffset=-\marginpadding,
  addvoffset=-\marginpadding,
  contents={%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUR{\line(-1,0){\LenToUnit{\layerwidth}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{topbox}
\DeclareNewLayer[clone=topbox,
  contents={%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{midbox}
\DeclareNewLayer[clone=topbox,
  height={\pdfpageheight-\zposy{textbottom}sp-\layeryoffset-\baselineskip+ \marginpadding},
  contents={%
  \putLL{\line(1,0){\LenToUnit{\layerwidth}}}%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{bottombox}
\DeclarePageStyleByLayers{firstpage}{topbox,pagenum}
\DeclarePageStyleByLayers{midpage}{midbox,pagenum}
\DeclarePageStyleByLayers{lastpage}{bottombox,pagenum}
\pagestyle{midpage}
\begin{document}
\thispagestyle{firstpage}
\begin{multicols}{2}
  \lipsum[1-10]       
\end{multicols}

\lipsum[1-2]

\begin{multicols}{2}
  \lipsum[1-10]
\end{multicols}
\zsaveposy{textbottom}
\thispagestyle{lastpage}
\end{document}
1
  • Based on this code I produced what you will find in 'my anwer'. It includes the pagenum into the frame on the last page.
    – Simon
    Sep 17, 2020 at 10:42
3

You could load package scrlayer-scrpage and add all layers of page style scrheadings to the new pagestyles. Then you can use \cfoot or \ofoot etc. for the page number.

\documentclass{article}
\usepackage[manualmark]{scrlayer-scrpage}
\usepackage{multicol}
\usepackage[savepos]{zref}
\usepackage{lipsum}

\newlength{\marginpadding}
\setlength{\marginpadding}{4pt}

\DeclareNewLayer[textarea,background,mode=picture,
  addheight=2\marginpadding,
  addwidth=2\marginpadding,
  addhoffset=-\marginpadding,
  addvoffset=-\marginpadding,
  contents={%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUR{\line(-1,0){\LenToUnit{\layerwidth}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{topbox}
\DeclareNewLayer[clone=topbox,
  contents={%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{midbox}
\DeclareNewLayer[clone=topbox,
  height={\pdfpageheight-\zposy{textbottom}sp-\layeryoffset-\baselineskip+\marginpadding},
  contents={%
  \putLL{\line(1,0){\LenToUnit{\layerwidth}}}%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{bottombox}
\DeclarePageStyleByLayers{firstpage}{topbox}
\DeclarePageStyleByLayers{midpage}{midbox}
\DeclarePageStyleByLayers{lastpage}{bottombox}

\ForEachLayerOfPageStyle*{scrheadings}{%
    \AddLayersToPageStyle{firstpage}{#1}%
    \AddLayersToPageStyle{midpage}{#1}%
    \AddLayersToPageStyle{lastpage}{#1}%
}
\clearpairofpagestyles
\cfoot*{\pagemark}


\pagestyle{midpage}
\begin{document}
\thispagestyle{firstpage}
\begin{multicols}{2}
  \lipsum[1-10]       
\end{multicols}

\lipsum[1-2]

\begin{multicols}{2}
  \lipsum[1-10]
\end{multicols}
\zsaveposy{textbottom}
\thispagestyle{lastpage}
\end{document}

or you could use

\documentclass[twoside]{article}
\usepackage{scrlayer-scrpage}
\usepackage{multicol}
\usepackage[savepos]{zref}
\usepackage{lipsum}

\newlength{\marginpadding}
\setlength{\marginpadding}{4pt}

\DeclareNewLayer[textarea,background,mode=picture,
  addheight=2\marginpadding,
  addwidth=2\marginpadding,
  addhoffset=-\marginpadding,
  addvoffset=-\marginpadding,
  contents={%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUR{\line(-1,0){\LenToUnit{\layerwidth}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{topbox}
\DeclareNewLayer[clone=topbox,
  contents={%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{midbox}
\DeclareNewLayer[clone=topbox,
  height={\pdfpageheight-\zposy{textbottom}sp-\layeryoffset-\baselineskip+\marginpadding},
  contents={%
  \putLL{\line(1,0){\LenToUnit{\layerwidth}}}%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{bottombox}

\newpairofpagestyles{firstpage}{\cfoot{\pagemark}}
\newpairofpagestyles{midpage}{\cfoot{\pagemark}}
\newpairofpagestyles{lastpage}{\cfoot{\pagemark}}

\AddLayersToPageStyle{firstpage}{topbox}
\AddLayersToPageStyle{midpage}{midbox}
\AddLayersToPageStyle{lastpage}{bottombox}


\pagestyle{midpage}
\begin{document}
\thispagestyle{firstpage}
\begin{multicols}{2}
  \lipsum[1-10]       
\end{multicols}

\lipsum[1-2]

\begin{multicols}{2}
  \lipsum[1-10]
\end{multicols}
\zsaveposy{textbottom}
\thispagestyle{lastpage}
\end{document}

If the page number should be in the boxes then add \footskip and maybe \dp\strutbox to the height of all boxes and remove the changed height for the layer bottombox:

\documentclass[twoside]{article}
\usepackage{scrlayer-scrpage}
\usepackage{multicol}
%\usepackage[savepos]{zref}
\usepackage{lipsum}

\newlength{\marginpadding}
\setlength{\marginpadding}{4pt}

\DeclareNewLayer[textarea,background,mode=picture,
  addheight=2\marginpadding+\footskip+\dp\strutbox,% changed
  addwidth=2\marginpadding,
  addhoffset=-\marginpadding,
  addvoffset=-\marginpadding,
  contents={%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUR{\line(-1,0){\LenToUnit{\layerwidth}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{topbox}
\DeclareNewLayer[clone=topbox,
  contents={%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{midbox}
\DeclareNewLayer[clone=topbox,
  %height={\pdfpageheight-\zposy{textbottom}sp-\layeryoffset-\baselineskip+\marginpadding},% removed
  contents={%
  \putLL{\line(1,0){\LenToUnit{\layerwidth}}}%
  \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
  \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{bottombox}

\newpairofpagestyles{firstpage}{\cfoot{\pagemark}}
\newpairofpagestyles{midpage}{\cfoot{\pagemark}}
\newpairofpagestyles{lastpage}{\cfoot{\pagemark}}

\AddLayersToPageStyle{firstpage}{topbox}
\AddLayersToPageStyle{midpage}{midbox}
\AddLayersToPageStyle{lastpage}{bottombox}


\pagestyle{midpage}
\begin{document}
\thispagestyle{firstpage}
\begin{multicols}{2}
  \lipsum[1-10]       
\end{multicols}

\lipsum[1-2]

\begin{multicols}{2}
  \lipsum[1-10]
\end{multicols}
\zsaveposy{textbottom}
\thispagestyle{lastpage}
\end{document}
0

I now used the version of Karl and added a layer pagenum lastpage that enables the inclusion of the last pagenumber into the frame. Additionaly I fiddled the frame of lastpage a bit longer to provide the space for the pagenumber. Here's what it looks like for me now:

\documentclass[fontsize=9pt]{scrartcl}

\usepackage{scrlayer}
\usepackage{multicol}
\usepackage[savepos]{zref}
\usepackage{lipsum}
\usepackage{lastpage}

%   PAGESPACES
\usepackage[a4paper, left=2.5cm, right=0.7cm, top=0.7cm, bottom=0.2cm, includefoot,heightrounded]{geometry}
% PAGE BODY
\setlength{\textheight}{780pt}  
% TOP SPACES
\setlength{\voffset}{-1in}                          
\setlength{\topmargin}{0.7cm}           
\setlength{\headheight}{0cm}            
\setlength{\headsep}{0cm}               
% RIGHT SPACES
\setlength{\marginparwidth}{0cm}
% BOTTOM SPACES
\setlength{\footskip}{4ex}      
\setlength{\footheight}{0ex}        

% MARGIN
\newlength{\marginpadding}
\setlength{\marginpadding}{8pt}

% PAGENUM 
\DeclareNewLayer[foot, contents={\parbox{\layerwidth}{\centering  \textsl{Seite \thepage \hspace{0.5pt} von \pageref{LastPage}}}}]{pagenum}
% PAGENUM LASTPAGE
\DeclareNewLayer[foot,%
    addvoffset=-\zposy{textbottom}sp+\topmargin+\footskip+\marginpadding,
    contents={\parbox{\layerwidth}{\centering  \textsl{Seite \thepage \hspace{0.5pt} von \pageref{LastPage}}}}]{pagenumLastPage}

% TOPOBOX
\DeclareNewLayer[textarea,background,mode=picture,
height={ \textheight+0.5\footskip},
addheight=2\marginpadding+\footskip,
addwidth=2\marginpadding,
addhoffset=-\marginpadding,
addvoffset=-\marginpadding,
contents={%
    \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
    \putUR{\line(-1,0){\LenToUnit{\layerwidth}}}%
    \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{topbox}

% MIDBOX
\DeclareNewLayer[textarea,background,mode=picture,
height={ \textheight+0.5\footskip},
addheight=2\marginpadding+\footskip,
addwidth=2\marginpadding,
addhoffset=-\marginpadding,
addvoffset=-\marginpadding,
contents={%
    \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
    \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{midbox}

% BOTTOMBOX
\DeclareNewLayer[textarea,background,mode=picture,
height={\textheight-\zposy{textbottom}sp+\topmargin+\footskip+2\marginpadding},
addheight=2\marginpadding+\footskip,
addwidth=2\marginpadding,
addhoffset=-\marginpadding,
addvoffset=-\marginpadding,
contents={%
    \putLL{\line(1,0){\LenToUnit{\layerwidth}}}%
    \putLR{\line(0,1){\LenToUnit{\layerheight}}}%
    \putUL{\line(0,-1){\LenToUnit{\layerheight}}}%
}]{bottombox}

\DeclarePageStyleByLayers{firstpage}{topbox, pagenum}
\DeclarePageStyleByLayers{midpage}{midbox, pagenum}
\DeclarePageStyleByLayers{lastpage}{bottombox, pagenumLastPage}
\pagestyle{midpage}

\begin{document}
    
    \thispagestyle{firstpage}
    \begin{multicols}{2}
        \lipsum[1-10]       
    \end{multicols}
    
    \lipsum[1-2]
    
    \begin{multicols}{2}
        \lipsum[1-10]
    \end{multicols}
    \zsaveposy{textbottom}
    \thispagestyle{lastpage}
    
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .