我正在尝试设置一些角落装饰图案包。它可以工作,但是水平位置有些装饰是错误的,我不知道如何正确推动它们。这是我的完整卡牌城堡的精简版 MWE 版本,显示了这个问题:
\documentclass[11pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[nomath]{lmodern}
\usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
\usepackage{microtype}
\usepackage[bottom]{footmisc} % Options : [perpage], [symbol], [multiple]
\usepackage{mathtools}
\usepackage[dvipsnames,table]{xcolor}
\usepackage[pagestyles,medium]{titlesec}
% Main header :
\newpagestyle{principal}{
\sethead[\thepage][][\itshape\small\MakeUppercase{\chaptername\ \thechapter. \chaptertitle}]{\itshape\small\MakeUppercase{\thesection\ \sectiontitle}}{}{\thepage}
\headrule
}
% Add a gray border :
\usepackage{eso-pic}
\definecolor{colorMarge}{RGB}{242,242,245}
\newlength{\distance}
\setlength{\distance}{0.0in} % 0.5in
\newlength{\rulethickness}
\setlength{\rulethickness}{0.5in} % 1pt
\newlength{\ruleheight}
\setlength{\ruleheight}{\paperheight} % Longueur de la ligne
\newlength{\xoffset}
\newlength{\yoffset}
\setlength{\yoffset}{0pt} %{0.5\dimexpr\paperheight-\ruleheight}
\AddToShipoutPicture{%
\setlength\fboxsep{1pt}% no additional frame for \colorbox
\ifodd\value{page}%
\setlength{\xoffset}{\distance}%
\else
\setlength{\xoffset}{\dimexpr\paperwidth-\rulethickness-\distance}%
\fi
\AtPageLowerLeft{%
\put(\LenToUnit{\xoffset},\LenToUnit{\yoffset}){%
\colorbox{colorMarge}{\parbox[b][\ruleheight][c]{\rulethickness}{%
\centering
\ifodd\value{page}%
\rotatebox[origin=cB]{90}{\color{lightgray}{\strut \large{\normalfont\textsc{Name and year}}}}%
\else
\rotatebox[origin=cB]{90}{\color{lightgray}{\strut \huge{\normalfont\textsc{Book Title}}}}%
\fi}}}}%
}
% Add ornementations to corners :
\usepackage[object=vectorian]{pgfornament}
\makeatletter
\AddToShipoutPicture{%
\begingroup
\setlength{\@tempdima}{2mm}%
\setlength{\@tempdimb}{\paperwidth-\@tempdima-0.75in}%
\setlength{\@tempdimc}{\paperheight-\@tempdima}%
\put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimc}){%
\pgfornament[anchor=north west,width=0.75in,color=gray]{41}}
\put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdima}){%
\pgfornament[anchor=south west,width=0.75in,symmetry=h,color=gray]{41}}
\put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdimc}){%
\pgfornament[anchor=north east,width=0.75in,symmetry=v,color=gray]{41}}
\put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdima}){%
\pgfornament[anchor=south east,width=0.75in,symmetry=c,color=gray]{41}}
\endgroup
}
\makeatother
\begin{document}
\mainmatter
\pagestyle{principal}
\chapter{Chapter title}
Some funny line\footnote{Some weird footnote text.}
\newpage
Another line
\end{document}
以下是此代码所做操作的预览(不,它不是在攻击美国中央银行),问题以红色显示:
所以我需要修复两件事:
装饰性图案不应该在垂直灰色区域内,而应该在页边距内,而灰色区域(左页和右页)则保留用于一些书籍信息和页面装订。
所有页面都应使用装饰,但仅限于主要内容部分书的其余部分不应有任何装饰(前页和后记)。
那么我该如何解决这两个问题呢?
答案1
只需按照与灰色边距框相同的方式移动装饰物即可。
\documentclass[11pt,letterpaper,twoside]{book}
\usepackage{graphicx, xcolor, calc}
\usepackage{eso-pic}
\definecolor{colorMarge}{RGB}{242,242,245}
\usepackage[object=vectorian]{pgfornament}
\usepackage{lipsum}
\newlength\mymargin
\setlength\mymargin{0.5in}
\newlength\mysize
\setlength\mysize{1.5in}
\newlength\mysep
\setlength\mysep{6mm}
\newcommand\mybox[2][]{%
\colorbox{colorMarge}{%
\rotatebox[origin=l]{90}{%
\parbox[c][\mymargin][c]{\paperheight}{%
\centering\color{lightgray}\normalfont #1 #2}}}}
\newcommand\leftornament[1]{%
\put(\LenToUnit{#1}, \LenToUnit{\mysep}){%
\pgfornament[anchor=south, width=\mysize, color=gray, symmetry=h]{41}}%
\put(\LenToUnit{#1}, \LenToUnit{\paperheight-\mysep}){%
\pgfornament[anchor=north, width=\mysize, color=gray]{41}}}
\newcommand\rightornament[1]{%
\put(\LenToUnit{#1}, \LenToUnit{\mysep}){%
\pgfornament[anchor=south, width=\mysize, color=gray, symmetry=c]{41}}%
\put(\LenToUnit{#1}, \LenToUnit{\paperheight-\mysep}){%
\pgfornament[anchor=north, width=\mysize, color=gray, symmetry=v]{41}}}
\newcommand\allOrnaments{%
\setlength\fboxsep{0pt}%
\ifodd\value{page}%
\put(0,0){\mybox[\scshape\large]{Name and Year}}%
\leftornament{\mymargin+\mysep}%
\rightornament{\paperwidth-\mysize-\mysep}%
\else
\put(\LenToUnit{\paperwidth-\mymargin},0){\mybox[\scshape\huge]{Book Title}}%
\leftornament{\mysep}%
\rightornament{\paperwidth-\mysize-\mymargin-\mysep}%
\fi
}
\newcommand\startOrnaments{\AddToShipoutPicture{\allOrnaments}}
\newcommand\stopOrnaments{\ClearShipoutPicture}
\begin{document}
\frontmatter
\chapter{Preface}
\lipsum[1-5]
\mainmatter
\startOrnaments
\chapter{Lorem ipsum}
\lipsum[1-20]
\backmatter
\stopOrnaments
\chapter{The End}
\lipsum[1-5]
\end{document}