为了在章节周围添加边框,我根据此处的答案改编了以下代码:单个章节的每一页中都有垂直矩形。
\AddEverypageHook{%
\ifthenelse{\thechapter=7}{
\tikz[remember picture,overlay] {%
\draw [titlegrey]($(current page.north west) + (1cm,-1cm)$) -- ($(current page.north east)+ (-1cm,-1cm)$) -- ($(current page.south east)+ (-1cm,+1cm)$) -- ($(current page.south west)+ (+1cm,+1cm)$) -- ($(current page.north west) + (1cm,-1cm)$) ;
}
%\fi
}{}
}
上述代码为第 7 章添加了边框。
但是,如何为未编号的章节添加边框 - 在这种情况下,我将其标记为:\chapter*{Unnumbered chapter with border}\label{chapborder}
?
答案1
您还可以创建一个条件,例如\ifchapterborder
,您可以将其设置为特定情况下的真值\chapter*
。请注意book
,在\chapter
s 问题下\cleardoublepage
。
\documentclass{book}
\usepackage{lipsum}
\usepackage[contents={},scale=1,opacity=1,color=black,angle=0]{background}
\usetikzlibrary{calc}
\newcommand{\insertborder}{%
\tikz[remember picture,overlay] {%
\draw ($(current page.north west) + (1cm,-1cm)$) -- ($(current page.north east)+ (-1cm,-1cm)$) -- ($(current page.south east)+ (-1cm,+1cm)$) -- ($(current page.south west)+ (+1cm,+1cm)$) -- ($(current page.north west) + (1cm,-1cm)$) ;
}
}
\newif\ifchapterborder
\AddEverypageHook{%
\ifnum\value{chapter}=7
\insertborder
\else\ifchapterborder
\insertborder
\fi\fi
}
\begin{document}
\chapter{A chapter}\lipsum[1-20]% Chapter 1
\setcounter{chapter}{6}%
\chapter{A chapter}\lipsum[1-20]% Chapter 7
\chapter{A chapter}\lipsum[1-20]% Chapter 8
\cleardoublepage
\chapterbordertrue
\chapter*{Unnumbered chapter}\lipsum[1-20]
\cleardoublepage
\chapterborderfalse
\chapter{A chapter}\lipsum[1-20]% Chapter 9
\end{document}