重新定义 \part 环境以添加页面边框

重新定义 \part 环境以添加页面边框
  1. 如何在书籍文档类中重新定义 \part 环境以在页边距添加页面边框?

  2. 顺便说一句,这一定是可能的(因为在 LaTeX 中一切皆有可能)获得带有较粗左线和下线的阴影页面边框。

第一个问题对我来说更重要。

答案1

一种可能性是使用TikZ

\documentclass{book}
\usepackage{tikz}

\makeatletter
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{}{}%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\bfseries \partname\nobreakspace\thepart
       \par
       \vskip 20\p@
     \fi
     \Huge \bfseries #2\par
    \noindent
    \begin{tikzpicture}[remember picture,overlay]% 
      \fill [red!20!black]
([xshift=-10pt]current page.south east)
rectangle
(current page.north east);
      \fill [red!20!black]
(current page.north east)
rectangle
([yshift=-10pt]current page.north west);
      \fill [red!20!black]
(current page.south east)
rectangle
([yshift=20pt]current page.south west);
      \fill [red!20!black]
(current page.south west)
rectangle
([xshift=20pt]current page.north west);
    \end{tikzpicture}}%
    \@endpart}
\makeatother

\begin{document}

\part{Test Part}

\end{document}

在此处输入图片描述

使用阴影的变化:

\documentclass{book}
\usepackage{tikz}

\makeatletter
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{}{}%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\bfseries \partname\nobreakspace\thepart
       \par
       \vskip 20\p@
     \fi
     \Huge \bfseries #2\par
    \noindent
\begin{tikzpicture}[remember picture,overlay]% 
\shade [shading=ball,ball color=cyan!80!black]
  (current page.south west) -- ([xshift=20pt]current page.south west) -- ([xshift=20pt,yshift=-10pt]current page.north west) -- ([xshift=-10pt,yshift=-10pt]current page.north east) -- 
([xshift=-10pt,yshift=20pt]current page.south east) --
([xshift=-10pt,yshift=20pt]current page.south west) --
([xshift=-10pt]current page.south west) --
(current page.south east) --
(current page.north east) --
(current page.north west) -- cycle
;
\end{tikzpicture}}%
    \@endpart}
\makeatother

\begin{document}

\part{Test Part}

\end{document}

在此处输入图片描述

注释之后,很明显框架应该围绕文本区域;在本例中,使用tikzpagenodes包,可以对上述解决方案进行简单修改,并使用current page text area节点系列获得所需的结果:

\documentclass{book}
\usepackage[margin=1in]{geometry}
\usepackage{tikzpagenodes}

\makeatletter
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{}{}%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\bfseries \partname\nobreakspace\thepart
       \par
       \vskip 20\p@
     \fi
     \Huge \bfseries #2\par
    \noindent
\begin{tikzpicture}[remember picture,overlay]% 
\shade [shading=ball,ball color=cyan!80!black]
(current page text area.south west) -- 
([xshift=20pt]current page text area.south west) -- 
([xshift=20pt,yshift=-10pt]current page text area.north west) -- 
([xshift=-10pt,yshift=-10pt]current page text area.north east) -- 
([xshift=-10pt,yshift=20pt]current page text area.south east) --
([xshift=10pt,yshift=20pt]current page text area.south west) --
([xshift=10pt]current page text area.south west) --
(current page text area.south east) --
(current page text area.north east) --
(current page text area.north west) -- cycle
;
\end{tikzpicture}}%
    \@endpart}
\makeatother

\begin{document}

\part{Test Part}

\end{document}

在此处输入图片描述

评论中请求了第二个框架;对于第二个框架,有以下一种可能性:

\documentclass{book}
\usepackage[margin=1in]{geometry}
\usepackage{tikzpagenodes}

\makeatletter
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{}{}%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\bfseries \partname\nobreakspace\thepart
       \par
       \vskip 20\p@
     \fi
     \Huge \bfseries #2\par
    \noindent
\begin{tikzpicture}[remember picture,overlay]% 
\shade [shading=ball,ball color=cyan!80!black]
(current page text area.south west) -- 
([xshift=20pt]current page text area.south west) -- 
([xshift=20pt,yshift=-10pt]current page text area.north west) -- 
([xshift=-10pt,yshift=-10pt]current page text area.north east) -- 
([xshift=-10pt,yshift=20pt]current page text area.south east) --
([xshift=10pt,yshift=20pt]current page text area.south west) --
([xshift=10pt]current page text area.south west) --
(current page text area.south east) --
(current page text area.north east) --
(current page text area.north west) -- cycle
;
\shade [shading=ball,ball color=cyan!80!black]
([xshift=24pt,yshift=24pt]current page text area.south west) -- 
([xshift=40pt,yshift=24pt]current page text area.south west) -- 
([xshift=40pt,yshift=-22pt]current page text area.north west) -- 
([xshift=-22pt,yshift=-22pt]current page text area.north east) -- 
([xshift=-22pt,yshift=40pt]current page text area.south east) --
([xshift=30pt,yshift=40pt]current page text area.south west) --
([xshift=24pt,yshift=24pt]current page text area.south west) --
([xshift=-14pt,yshift=24pt]current page text area.south east) --
([xshift=-14pt,yshift=-14pt]current page text area.north east) --
([xshift=24pt,yshift=-14pt]current page text area.north west) -- cycle
;
\end{tikzpicture}}%
    \@endpart}
\makeatother

\begin{document}

\part{Test Part}

\end{document}

在此处输入图片描述

相关内容