我正在使用下面的代码,它是作为另一个问题的答案提供的这里。
问题是:在用 声明页面样式的那一刻\DeclarePageStyleByLayers{firstpage}{topbox}
,页码就消失了。如果 的行\DeclarePageStyleByLayers...
被标记(=取出=没有框架),则页码会出现。
我其实奥尔尼使用提供给我的这段代码,我只理解了表面。我原本以为 Tex 会放置页码,然后覆盖框架,但显然事实并非如此。
我想在框架内显示页码。如何实现?
\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}
答案1
页码消失是因为页面样式已被替换。要恢复页码,只需添加另一个包含页码的图层,以及页脚中所需的任何其他内容,并添加适当的额外距离以扩展框架。
此版本将页码置于中央,并且不进行任何格式化。如果您想要更酷炫的功能(例如奇偶页更改),则需要对其进行修改。
\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}
答案2
您可以加载包scrlayer-scrpage
并将所有页面样式层添加scrheadings
到新的页面样式中。然后您可以使用\cfoot
或\ofoot
等来设置页码。
\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}
或者你可以使用
\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}
如果页码应该在框中,则添加\footskip
并可能添加\dp\strutbox
到所有框的高度并删除图层的更改高度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}
答案3
我现在使用了 Karl 的版本并添加了一层页码 最后一页允许包含最后一个页码进入框架。另外,我摆弄了框架最后一页稍长一点以提供页码的空间。现在它看起来是这样的:
\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}