Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
  1. How can I redefine the \part environment, in a book documentclass, to add a page border at the page margins?

  2. By the way, it must be possible (since everything is possible in LaTeX) to get a shaded page border with thicker left and lower lines.

The first question is more important to me.

share|improve this question

1 Answer 1

up vote 8 down vote accepted

One possibility using 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}

enter image description here

A variation using a shading:

\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}

enter image description here

After a comment, it's clear that the frame should go around the text area; in this case, using the tikzpagenodes package, one can make a simple modification to the solutions above and get the desires result by using the current page text area family of nodes:

\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}

enter image description here

A second frame has been requested in a comment; here's one possibility for this second frame:

\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}

enter image description here

share|improve this answer
    
Thank you very much @Gonzalo Medina. –  rasha Nov 21 '12 at 7:57
    
Thank you very much @Gonzalo Medina. The desired page border (or page frame) is at the margins, not at the borders of the paper. I have about 2.54cm (1 in) of page margins at each side (standard margins of the book document class). –  rasha Nov 21 '12 at 8:04
    
@rasha the idea is still the same and the tikzpagenodes package facilitates this job. Please see the last example in my updated answer. –  Gonzalo Medina Nov 21 '12 at 13:19
    
your last example answers perfectly my question. Thank you very much. I have a last question regarding this subject. How to set up two nested frames (like the last frame) distant from one another by a couple of millimeters? I do not see in the LaTeX code you proposed how to set the position of an additional frame (I'm not used to handle such codes, sorry). –  rasha Nov 22 '12 at 14:03
    
@rasha No problem; please see my updated answer. –  Gonzalo Medina Nov 22 '12 at 15:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.