XeTeXColour coded Page Tabs

Information and discussion about XeTeX, an alternative for pdfTeX based on e-Tex
Post Reply
paulsp
Posts: 2
Joined: Wed Jun 26, 2013 12:24 pm

Colour coded Page Tabs

Post by paulsp »

Hello,

could someone please offer some help? I'm trying to create colour coded page tabs in a report, so that when it is printed there will be different colour rectangles along the edge of each page. Different colours for each section. The name of the section will also appear in the tabs.

Here is the code I have so far. It almost works, but there are tabs appearing on blank pages. Also it does not seem to pick up the name of the section until a page or two after the section has started. Any Ideas anyone?

Code: Select all

\documentclass[10pt,x11names,svgnames,twoside]{book}
\usetikzlibrary{calc}
\usepackage{lipsum}
\usepackage[
  a4paper,
  left=1.2in,
  right=1in,
  top=1in,
  bottom=1in,
  headheight=\baselineskip,
  headsep=9mm,
  footskip=13mm,
  showframe
]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes.misc}

\newcommand\MyColor{%
  \ifcase\thesection
    blue!30\or red!30\or olive!30\or magenta!30%
  \else
    green!30%
  \fi%
}

\fancypagestyle{plain}{%
%% Clear all headers and footers
\fancyhf{}

%% Left headers on odd pages
\fancyhead[LO]{%
  \rotatebox{90}{%
    \begin{tikzpicture}[overlay,remember picture]
      \node[
        fill=\MyColor,
        text=white,
        font=\small,
        inner ysep=2pt,
        inner xsep=2pt,
        outer sep=0,						
        rectangle,
        anchor=west,
        xshift=-70mm,
        yshift=5mm,
        text width= 5.75cm,
        text height=0.75cm,
        minimum height=1cm,
        maximum height=1cm,
        minimum width=6cm,
        maximum width=6cm,
      ] at ($ (current page.north west) + (1cm,0cm) + (-1*\thesection cm,0cm) $)
      {\sffamily\itshape\small\nouppercase{\leftmark}};
    \end{tikzpicture}%
  }%
}

%% Right headers on even pages
\fancyhead[RE]{%
  \rotatebox{90}{%
    \begin{tikzpicture}[overlay,remember picture]
      \node[
        fill=\MyColor,
        text=white,
        font=\small,
        inner ysep=2pt,
        inner xsep=2pt,
        outer sep=0,			
        rectangle,
        anchor=east,
        xshift=-51mm,
        yshift=-26mm,
        text width= 5.75cm,
        text height=0.75cm,
        minimum height=1cm,
        maximum height=1cm,
        minimum width=6cm,
        maximum width=6cm,
      ] at ($ (current page.north east) + (1cm,0cm) + (-1*\thesection cm,0cm) $)
      {\sffamily\itshape\small\nouppercase{\leftmark}};
    \end{tikzpicture}%
  }%
}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyfoot[R]{\thepage}

\pagestyle{plain}
\renewcommand\sectionmark[1]{\markboth{\thesection.~#1}{}} 

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Post Reply