使用 pgfornament

使用 pgfornament

我使用pgfornamentpackage 將裝飾品放在角落,如下 MWE 所示:

\documentclass[10pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{fontspec}
\usepackage{lipsum}

\usepackage{pgfornament}
\usepackage{eso-pic}


\newcommand\AtPageUpperRight[1]{\AtPageUpperLeft{%
 \put(\LenToUnit{\paperwidth},\LenToUnit{0\paperheight}){#1}%
 }}%
\newcommand\AtPageLowerRight[1]{\AtPageLowerLeft{%
 \put(\LenToUnit{\paperwidth},\LenToUnit{0\paperheight}){#1}%
 }}%

\AddToShipoutPictureBG{%
   \AtPageUpperLeft{\put(0,-25){\pgfornament[width=1.75cm]{61}}}
   \AtPageUpperRight{\put(-50,-25){\pgfornament[width=1.75cm,symmetry=v]{61}}}
   \AtPageLowerLeft{\put(0,25){\pgfornament[width=1.75cm,symmetry=h]{61}}}
   \AtPageLowerRight{\put(-50,25){\pgfornament[width=1.75cm,symmetry=c]{61}}}
   }

\begin{document}
\title{Magnificent title}
\maketitle 
\frontmatter
\tableofcontents
\mainmatter

\chapter{New chapter}
\lipsum[5]
\chapter{Another chapter}
\lipsum[4]

\end{document} 

角落如花

但我只想從特定頁面開始放置這些裝飾,比如說從第 1 章開始。我該如何修改上面的程式碼,最好不添加新套餐?

答案1

只需將程式碼放在後面\mainmatter(或任何您想要的位置)

.
.
\mainmatter
\AddToShipoutPictureBG{%
   \AtPageUpperLeft{\put(0,-25){\pgfornament[width=1.75cm]{61}}}
   \AtPageUpperRight{\put(-50,-25){\pgfornament[width=1.75cm,symmetry=v]{61}}}
   \AtPageLowerLeft{\put(0,25){\pgfornament[width=1.75cm,symmetry=h]{61}}}
   \AtPageLowerRight{\put(-50,25){\pgfornament[width=1.75cm,symmetry=c]{61}}}
   }

\chapter{New chapter}
.
.

在此輸入影像描述

您也可以定義巨集來為多個頁面放置裝飾物:

 \newcommand{\beautify}{%
 \AddToShipoutPictureBG{%
   \AtPageUpperLeft{\put(0,-25){\pgfornament[width=1.75cm]{61}}}
   \AtPageUpperRight{\put(-50,-25){\pgfornament[width=1.75cm,symmetry=v]{61}}}
   \AtPageLowerLeft{\put(0,25){\pgfornament[width=1.75cm,symmetry=h]{61}}}
   \AtPageLowerRight{\put(-50,25){\pgfornament[width=1.75cm,symmetry=c]{61}}}
   }
   }

 \newcommand{\simplify}{%
 \cleardoublepage\ClearShipoutPictureBG
 }

並像這樣使用它

\documentclass[10pt,a4paper]{book}
\usepackage[utf8]{inputenc}
%\usepackage{fontspec}
\usepackage{lipsum}

\usepackage{pgfornament}
\usepackage{eso-pic}


\newcommand\AtPageUpperRight[1]{\AtPageUpperLeft{%
 \put(\LenToUnit{\paperwidth},\LenToUnit{0\paperheight}){#1}%
 }}%
\newcommand\AtPageLowerRight[1]{\AtPageLowerLeft{%
 \put(\LenToUnit{\paperwidth},\LenToUnit{0\paperheight}){#1}%
 }}%

 \newcommand{\beautify}{%
 \AddToShipoutPictureBG{%
   \AtPageUpperLeft{\put(0,-25){\pgfornament[width=1.75cm]{61}}}
   \AtPageUpperRight{\put(-50,-25){\pgfornament[width=1.75cm,symmetry=v]{61}}}
   \AtPageLowerLeft{\put(0,25){\pgfornament[width=1.75cm,symmetry=h]{61}}}
   \AtPageLowerRight{\put(-50,25){\pgfornament[width=1.75cm,symmetry=c]{61}}}
   }
   }

 \newcommand{\simplify}{%
 \cleardoublepage\ClearShipoutPictureBG
 }


\begin{document}
\title{Magnificent title}
\maketitle
\frontmatter
\tableofcontents
\mainmatter

\beautify
\chapter{New chapter}
\lipsum[5]
\simplify
\chapter{Another chapter}
\lipsum[4]

\end{document}

在此輸入影像描述

相關內容