2

I know that this should be possible, but I'm not sure how to go about it.

I would like to have a small rectangle appear on each page (outside edge), which runs right up to the edge of the page, and for it to be in the same place for each page - so that when the book is printed, the colour is visible on the outside edge of the page.

My current thinking is that i could maybe include something in my fancychap which did it for me, but I really don't know a huge amount about latex, so where to go from here has me a little lost...

Doing somthing like this gets be someway there:

%................"Fancy Headers" - Nice page headings
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{calc}
\fancyheadoffset[LE,RO]{7mm}
\fancyheadoffset[LO,RE]{5mm}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhf{}

\fancyhead[LE]{\colorbox{cyan}{\parbox[l][10mm][c]{10mm}{\hspace*{50pt}}} \thepage}
\fancyhead[RO]{\thepage \colorbox{cyan}{\parbox[l][10mm][c]{10mm}{\hspace*{50pt}}}}

\fancyhead[LO]{\rightmark}
\fancyhead[RE]{\leftmark}
\fancypagestyle{plain}{%
\fancyhead{} % get rid of headers
\renewcommand{\headrulewidth}{0pt} % and the line
}

But all that does is put the colorbox in the corner, outside of the page number. I'd rather it was a few inches down the page (i.e. outside of the header).

This gives this: enter image description here

which isn't all the way there. The last time i tried something like this it took me hours, and this is a little worse than the previous thing i tried. Can any of you think of a simple(ish) way i could go about this?

I already have this for my titles:

\usepackage[strict]{changepage}

%.................Custom chapter headings
\makeatletter

\usepackage[explicit]{titlesec}
\titleformat
{\chapter} % command
[display] % shape
{\fontsize{76}{80}\usefont{OT1}{pzc}{m}{n}\selectfont}% format
{\vspace*{-135pt}%
\begin{adjustwidth}{-20mm}{-20mm}%
\ifodd \c@page \raggedleft \else \raggedright \fi \colorbox{cyan}{\parbox[l][25mm][c]{100mm}{\ifodd \c@page \raggedleft \thechapter \hspace*{20mm} \else \raggedright \hspace*{20mm} \thechapter \fi}}% title code
\end{adjustwidth}%
}% label
{-136pt}% sep
{\bfseries\Huge \ifodd \c@page \raggedleft \else \raggedright \fi%
\begin{adjustwidth}{-20mm}{-20mm}%
\ifodd \c@page \raggedleft \else \raggedright \fi  \colorbox{cyan}{\parbox[l][15mm][c]{100mm}{\ifodd \c@page \hspace*{7mm} \raggedright #1 \else \raggedleft #1 \hspace*{7mm} \fi}}%
\end{adjustwidth}%
}

%\titlespacing*{\chapter}{-20mm}{0.5ex}{0.5ex}[-20mm]


\makeatother

which places coloured boxes around the titles and their numbers which extend off the edge of the page. Ideally, the swatches on the other pages would line up with these ones. The bonus of using the header to do it would be that you wouldn't have to add in any special logic to deal with the pages that don't have headers (like the title page, contents, and other pages where the chapter starts and stuff).

4

Here is another suggestion using scrlayer-scrpage for the header.

\documentclass[oneside]{book}
\usepackage{xcolor}
\usepackage{blindtext}

\usepackage[
  automark,
  autooneside=false,
  markcase=noupper,
  headsepline,
  headwidth=\the\textwidth+12mm:-5mm,
]{scrlayer-scrpage}
\clearpairofpagestyles
\rehead{\leftmark}
\lohead{\rightmark}
\ohead{\pagemark}
\renewcommand\chaptermarkformat{}% no chapternumber in header
\setkomafont{pageheadfoot}{\normalfont}

% define new layers
\DeclareNewLayer[
  background,
  oddpage,
  align=tr,
  hoffset=\paperwidth,
  voffset=0pt,%distance from top
  width=1cm,% width of the swatch
  height=\dimexpr\voffset+1in+\topmargin+\headheight\relax,% height of the swatch
  contents={\textcolor{swatchcolor}{\rule{\layerwidth}{\layerheight}}}
  ]{swatch.odd}
\DeclareNewLayer[
  clone=swatch.odd,
  evenpage,
  align=l,
  hoffset=0pt
  ]{swatch.even}

% add layers to every pagestyle
\AddLayersToPageStyle{@everystyle@}{swatch.odd,swatch.even}

\newcommand\swatchcolor[1]{\colorlet{swatchcolor}{#1}}
\swatchcolor{white}

\begin{document}
\tableofcontents
\chapter{First chapter}\swatchcolor{orange}
\section{First section}
\Blindtext[20]
\chapter{Second chapter}\swatchcolor{purple}
\section{First section}
\Blindtext[20]
\chapter{Third chapter}\swatchcolor{blue!80!black}
\section{First section}
\Blindtext[20]
\end{document}

enter image description here

It works also if you use an oneside layout. Then the swatch is on every page at the right (=outer) margin automatically.

\documentclass[oneside]{book}

enter image description here

2

This uses \atxy{This page x}{alt page x}{y}{content} to place something at alternating locations on even/odd pages, and \updateText{content} to change the content. In this case, my content is a .5in x .5in colored box, which I change part-way through the document.

Because my paper is 8.5 in wide, my this page x is 8in, while my alt page x is 0 in (for a 1/2 in box). Likewise, the y value is .5 in.

\documentclass[letter]{article}
\usepackage{everypage}
\usepackage{lipsum,xcolor}
% THESE ARE LaTeX DEFAULTS; CAN CHANGE IF NEEDED.
\def\PageTopMargin{1in}
\def\PageLeftMargin{1in}
\def\localX{0in}
\def\ThisX{0in}
\def\AltX{0in}
% SYNTAX \atxy{This page X}{Alt page X}{y}{content}
\newcommand\atxy[4]{%
  \def\XYtext{#4}
  \gdef\ThisX{#1}\gdef\AltX{#2}%
 \AddEverypageHook{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+\localX\relax}%
  \raisebox{\dimexpr\PageTopMargin+\voffset-#3\relax}{\XYtext}}}}
\AddEverypageHook{\ifdim\localX=\ThisX\gdef\localX{\AltX}\else\gdef\localX{\ThisX}\fi}
\newcommand\updateText[1]{\gdef\XYtext{#1}}
\begin{document}
\atxy{8in}{0in}{0.5in}{\textcolor{red}{\rule{.5in}{.5in}}}
\lipsum[1-12]
\updateText{\textcolor{blue}{\rule{.5in}{.5in}}}
\lipsum[13-35]
\end{document}

enter image description here

My answer was based on my answer at How can (easily) superimpose different text over odd/even pages of an included PDF file?, except in that case, the content was text, not a color swatch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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