Consider the following MWE:
\documentclass[12pt,twoside,letterpaper]{report}
\usepackage[text={4.95in,7.5in},centering,bottom=1.5in,showframe]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage{calc}
\usepackage[explicit]{titlesec}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage[demo]{graphicx}
\usepackage{tikz}
\usepackage{amsmath,amssymb}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc,positioning}
\setlength{\oddsidemargin}{-0.25in}
\setlength{\evensidemargin}{1.75in}
\DeclareFixedFont{\chapterfont}{T1}{ppl}{m}{n}{0.365in}
\DeclareFixedFont{\chapternumfont}{T1}{ppl}{m}{n}{1in}
%-------------------------------------------------------------------------
% Chapter Style
%-------------------------------------------------------------------------
\titleformat{\chapter}[display]
{\chapterfont}
{
\ifodd\thepage
\begin{tikzpicture}[overlay, remember picture]
\node[minimum width=2.5in, text width=\marginparwidth+\evensidemargin-2\marginparsep+\oddsidemargin, minimum height=10pt, rectangle, fill=cyan, outer sep=0pt, anchor=north east, align=right] at ($(current page.north east)$) {};
\node[text=cyan](chapnum) at ($(current page.north east)+(-2\marginparwidth+2.85\marginparsep,-1.125in)$) {\chapternumfont\thechapter};
\node[cyan,outer sep=0pt,left=0em of chapnum] (vline) {$\left|\vphantom{\text{\chapternumfont 1}}\right.$};
\end{tikzpicture}%
\else
\begin{tikzpicture}[overlay, remember picture]
\node[minimum width=2.5in, text width=\marginparwidth+\evensidemargin-2\marginparsep+\oddsidemargin, minimum height=10pt, rectangle, fill=magenta, outer sep=0pt, anchor=north west, align=right] at ($(current page.north west)$) {};
\node[text=magenta](chapnum) at ($(current page.north west)+(2\marginparwidth-2.85\marginparsep,-1.125in)$) {\chapternumfont\thechapter};
\node[magenta,outer sep=0pt,right=0em of chapnum,at=(chapnum.east)] (vline) {$\left|\vphantom{\text{\chapternumfont 1}}\right.$};
\end{tikzpicture}%
\fi
}
{-2.125in}
{\parbox{0.85\textwidth}{#1}}
[\vspace*{.35in}]
%-------------------------------------------------------------------------
% Chapter Page Header/Footer
%-------------------------------------------------------------------------
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyhead{} % clear all header fields
\fancyfoot{} % clear all footer fields
\fancyfoot[RO]{\thepage$|$}
\fancyfoot[LE]{$|$\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
%-------------------------------------------------------------------------
% Header/Footer Page Styles
%-------------------------------------------------------------------------
\fancyhead{} % clear all header fields
\fancyfoot{} % clear all footer fields
\fancyfoot[RO]{\thepage$|$}
\fancyfoot[LE]{$|$\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\pagestyle{fancy}
\begin{document}
\chapter{L'Hopitals Rule}
\ifodd\thepage
\begin{tikzpicture}[remember picture, overlay, outer sep=0pt]
\node[anchor=north west] at (current page marginpar area.north west) {\includegraphics[height=\textheight]{figure}};
\end{tikzpicture}
\else
\begin{tikzpicture}[remember picture, overlay, outer sep=0pt]
\node[anchor=north east] at (current page marginpar area.north east) {\includegraphics[height=\textheight]{figure}};
\end{tikzpicture}
\fi
test\footnote{test}
\lipsum[1-2]
\lipsum
\chapter{Descartes Rule of Signs}
\ifodd\thepage
\begin{tikzpicture}[remember picture, overlay, outer sep=0pt]
\node[anchor=north west] at (current page marginpar area.north west) {\includegraphics[height=\textheight]{figure}};
\end{tikzpicture}
\else
\begin{tikzpicture}[remember picture, overlay, outer sep=0pt]
\node[anchor=north east] at (current page marginpar area.north east) {\includegraphics[height=\textheight]{figure}};
\end{tikzpicture}
\fi
\lipsum[1-2]
\chapter{Mean Value Theorem and Intermediate Value Theorem}
\lipsum[1-2]
\end{document}
This yields:
As you can see there are several optimization problems I am facing:
- The chapter style may not be properly defined.
- The vertical line beside the chapter numbering is not properly aligned with the horizontal bar above it.
- The chapter names like L'Hopitals Rule are not properly vertically centered with the vertical bar. This can be obvious in the third image.
- There is a vertical displacement of where the text starts after the chapter name which is clearly obvious in the third image.
- The geometry of the page is not properly defined. I just want a regular lettersize paper with about the same output as the image shows.
Things I am considering defining for this template are:
- To be able to place the horizontal bar in every page that belongs to the chapter. Possibly a vertical bar to the right on odd pages starting at
current page.north east
and going down possible an inch. - To be able to define different colors for every chapter.
- To be able to place different images and different pages by using a macro possibly in the preamble. Something like:
\pagepic{<pagenum>}{pic}
. This needs to be positioned as shown. Note the images will use the space indicated in the demo. One pic per page.
Any suggestions will be highly appreciated. I am doing this just for leisure. Just trying to learn new tricks and optimization techniques.
2.85\marginparsep
,-1.125in
, etc. Could you add more comments to explain where these come from? (If they're just invented by trial-and-error it's no surprise that the various objects don't quite line up!)-2.85\marginparsep
is just a forced dimension that I used to make it seem to be aligned.-1.125in
is just a particular height from the top most of the page. It has no special significance.