\documentclass{article} \usepackage[% margin=4cm %,showframe% to show the page layout ]{geometry} \usepackage[object=vectorian]{pgfornament} \newcommand\om{5mm}% ornament margin \newcommand\ow{5cm}% ornament width \newcommand\ols{5.5mm}% ornament line shift \newcommand\on{63}% ornament number \colorlet{bordercolor}{purple} \tikzset{ ol/.style={line width=1mm,dotted}% style for the lines } % define the border and save it in a box \newsavebox\border \sbox\border{% \tikz[color=bordercolor]{ \useasboundingbox(0,0)rectangle(\paperwidth,-\paperheight); \foreach[count=\i]\a/\p/\s in {% north west/{\om,-\om}/none, north east/{{\paperwidth-\om},-\om}/v, south east/{{\paperwidth-\om},{-\paperheight+\om}}/c,% south west/{\om,{-\paperheight+\om}}/h% }\node[anchor=\a](n\i) at (\p){\pgfornament[width=\ow,symmetry=\s]{\on}}; \begin{scope}[ol] \draw([yshift=-\ols]n1.north east)--([yshift=-\ols]n2.north west); \draw([xshift=-\ols]n2.south east)--([xshift=-\ols]n3.north east); \draw([yshift=\ols]n3.south west)--([yshift=\ols]n4.south east); \draw([xshift=\ols]n4.north west)--([xshift=\ols]n1.south west); \end{scope} }% } \usepackage[manualmark]{scrlayer-scrpage} \clearpairofpagestyles \addtokomafont{pagehead}{\color{blue!50!green!80!black}\large} \chead*{The current page style is \toplevelpagestyle{} \ifstr{\toplevelpagestyle}{\currentpagestyle}{}{as alias for \currentpagestyle}.} \cfoot*{\pagemark} % define a switch to enable and disable the border \newif\ifBorder % define a new layer \DeclareNewLayer[{% background, page, contents={\ifBorder\usebox\border\fi} }]{border.bg} % add the border layer to all layer page styles (scrheadings, plain, empty, ...) ... \AddLayersAtBeginOfPageStyle{@everystyle@}{border.bg} % but no border on empty pages \AddToLayerPageStyleOptions{empty}{oninit=\Borderfalse} \usepackage{blindtext}% dummy text \begin{document} \Bordertrue \Blindtext \clearpage \pagestyle{empty} \Blindtext[10] \clearpage \pagestyle{plain} \Blindtext \end{document}
选自:http://tex.stackexchange.com/questions/245904/create-page-border-using-tikz
发表评论 取消回复