3

I've been looking for a method of having different designs on odd/even pages, and from what I found on Google, background seems to be the package to do it; but in using it, it indiscriminately puts my design on EVERY page, even ones that I specify to be blank.

How might I make it so that completely blank pages don't have this design, nor do the start of chapters?

\documentclass{book}
\let\cleardoublepage\clearpage

\RequirePackage[
  left=2.25in,
  right=0.75in,
  top=1.25in,
  bottom=1.25in,
  marginparwidth=1.75in,
  marginparsep=.25in]{geometry} 
\RequirePackage{graphicx}
\RequirePackage[hidelinks]{hyperref}
\RequirePackage{amsthm, amsfonts, amsmath}
\RequirePackage{thmtools}
\RequirePackage{paralist}
\RequirePackage{tikz}
\RequirePackage[explicit]{titlesec}
\RequirePackage{blindtext, xcolor}
\RequirePackage[T1]{fontenc}
\RequirePackage{mdframed}
\RequirePackage{DejaVuSansCondensed}
\RequirePackage[normalem]{ulem}
\RequirePackage{environ}
\RequirePackage[strict]{changepage}
\RequirePackage{fancyhdr}
\RequirePackage{calc}
\RequirePackage{titletoc}
\RequirePackage{ifthen}
\RequirePackage[contents={}]{background}
\RequirePackage{lipsum}

\setlength{\oddsidemargin}{1in}
\setlength{\evensidemargin}{1.25in}

\renewcommand*\familydefault{\sfdefault} % Set default font

%%% Table of Contents ----------------------------------------------------------
\setcounter{tocdepth}{1} % Show only Chapters and Sections
\makeatletter
\g@addto@macro{\appendix}{%
  \addtocontents{toc}{\protect\renewcommand*{\protect\@chapapp}{\protect\appendixname}}%
}  

%%% Change font/color/layout of TOC

% START OF MODIFIED CODE

\contentsmargin{1.5cm} % global right margin, perhaps also global left

\titlecontents{part}[3cm]
  {\color{cyan}\bfseries\Huge\addvspace{3mm}}
  {\makebox[0cm][r]{\hspace{.5em}\thecontentslabel\hspace{.75cm}}}
  {} %     ^^^ pretendously zero width box puts its contents in the left margin
  {\hfill\makebox[-3cm]{\thecontentspage}}  % 3cm = twice 1.5cm
  [\titleline{\color{cyan}\titlerule[1pt]}]

\titlecontents{chapter}[3cm] % <-- seems to set some specific left margin
  {\color{cyan}\bfseries\LARGE\addvspace{3mm}}
  {\makebox[0cm][r]{\@chapapp\hspace{.5em}\thecontentslabel\hspace{.75cm}}}
  {} %     ^^^ pretendously zero width box puts its contents in the left margin
  {\hfill\makebox[-3cm]{\thecontentspage}}  % 3cm = twice 1.5cm

\titlecontents{section}[3cm] % <-- again this left (additional?) margin
  {\color{cyan}\large\itshape\addvspace{3mm}}
  {\makebox[0cm][r]{\thecontentslabel\hspace{.75cm}}} % box pushed to the left
  {}
  {\hfill\makebox[-3cm]{\thecontentspage}}  % 3cm = twice 1.5cm
  [\addvspace{0mm}]

% END OF MODIFICATIONS

\makeatother

\AddEverypageHook{%
  \ifthenelse{\isodd{\thepage}}%
  {
    \begin{tikzpicture}[remember picture, overlay]
      \fill [cyan!50] (18.25,3) rectangle (19,-26);
    \end{tikzpicture}
  }%
  {
    \begin{tikzpicture}[remember picture, overlay]
      \fill [cyan!50] (-3,3) rectangle (-1.85,-26);
    \end{tikzpicture}
  }%
\BgMaterial}

\titlecontents{section}[5.3em]
{\color{cyan}\large\itshape\addvspace{3mm}}
{\contentslabel{0em}\hspace{3.2em}}
{}
{\hspace{3em}\contentspage}
[\addvspace{0mm}]

%%% Chapter Header ----------------------------------------------------------
\makeatletter
\titleformat{\chapter}
  {\normalfont\sffamily\Huge\scshape}
  {}{0pt}
  {\thispagestyle{empty}    % Remove page number on new chapters
  %\setcounter{definition}{0}
  \begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=cyan!50] (0,-1) rectangle
          (25cm,3cm);
        \draw[fill=cyan!50] (0,-24) rectangle
          (25cm,-25cm);
        \ifttl@label% <---------------------- Added condition on \ifttl@label
          \node[anchor=west,xshift=.21\paperwidth,yshift=-.01\paperheight,rectangle]
              {\color{white}\LARGE \MakeUppercase{\@chapapp} \Huge\thechapter};
        \fi% <------------------------------- end condition on \ifttl@label
       \end{tikzpicture}
      };
   \end{tikzpicture}\endgraf
  \vskip-.7cm
  \color{cyan}\Huge\raggedright\leftskip-1cm
   \noindent\MakeUppercase{#1}\endgraf
  }
\makeatother

\titlespacing*{\chapter}{0pt}{10pt}{0pt}{}

\titleformat{\section}{\color{cyan}\itshape\LARGE}{\llap{\thesection} #1}{1em}{}[\titleline{\color{cyan}\titlerule[1pt]}]
\titleformat{\subsection}{\color{cyan}\normalfont\large}{\; #1}{1em}{}

\begin{document}
  \tableofcontents
  \newpage\mbox{\thispagestyle{empty}}\clearpage
  \chapter{One}
    \lipsum[1-10]
  \chapter{Two}
    \lipsum[2-20]
\end{document}
Mirrana
  • 2,601
  • 5
    Do you really need all the code that you posted to reproduce the behavior? Please reduce it to a minimum, helping you it will be a lot easier then. – krlmlr Feb 04 '13 at 22:24
  • THat is the minimum. I am designing a custom class and I put that in so my style can be seen. – Mirrana Feb 04 '13 at 22:31
  • 2
    Erm, no. What does \RequirePackage{DejaVuSansCondensed} contribute to the problem you are seeing? The \oddsidemargin? The \titlecontents? And so forth... – krlmlr Feb 04 '13 at 22:37

1 Answers1

3

Call also

\usepackage{etoolbox}

and add the code

\newif\ifbluemargin\bluemargintrue
\newcommand{\makeemptypage}{%
  \clearpage\null\thispagestyle{empty}%
  \global\bluemarginfalse\clearpage\global\bluemargintrue}
\preto{\chapter}{\clearpage\global\bluemarginfalse}

at the end of your preamble (at least after having defined the chapter format). Then change your code for the blue bars as

\AddEverypageHook{%
  \ifbluemargin
    \ifthenelse{\isodd{\thepage}}%
    {
      \begin{tikzpicture}[remember picture, overlay]
        \fill [cyan!50] (18.25,3) rectangle (19,-26);
      \end{tikzpicture}
    }%
    {
      \begin{tikzpicture}[remember picture, overlay]
        \fill [cyan!50] (-3,3) rectangle (-1.85,-26);
      \end{tikzpicture}
    }%
  \BgMaterial
\else
  \global\bluemargintrue
\fi}

In order to produce a blank page use \makeemptypage.

But, please, don't do it. This layout is a punch in the eye.

egreg
  • 1,121,712