28

Is it possible with pdfLaTeX to create a clickable "table of contents" on the right side of each page as you could see here (it is a screenshot of a PDF):

enter image description here

1
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
    – user31729
    May 29, 2014 at 15:00

3 Answers 3

27

One possibility:

enter image description here

The code:

\documentclass{article}
\usepackage[a5paper,vmargin=2cm]{geometry}
\usepackage{background}
\usepackage{etoolbox}
\usepackage{graphicx}
\usepackage{totcount}
\usepackage{lipsum}
\usepackage{hyperref}

% to have access to the total number of sections
\regtotcounter{section}

% every section starts on a new page
\pretocmd{\section}{\clearpage}{}{}

% auxiliary lengths for the height of the frame and the width of each tab
\newlength\mylen
\newlength\mylena

% style for the section tabs
\tikzset{
tab/.style={
  text width=\mylena,
  draw=gray,
  thick,
  rectangle,
  rounded corners=12pt,
  align=center,
  text width=53pt,
  inner sep=0pt,
  fill=gray!20,
  font=\sffamily\LARGE
  }
}
% style for the current section tab
\tikzset{selectedtab/.style={tab,color=white,fill=gray!90}}

% the page number is showed in the background material
\pagestyle{empty}

\AtBeginDocument{
% calculation of the width for each tab
\setlength\mylen{\dimexpr\textheight+2cm\relax}
\ifnum\totvalue{section}>0
\setlength\mylena{\dimexpr\mylen/\totvalue{section}\relax}
\fi

% the main part; as background material we place the border, 
% the section (current and other) tabs and the page number 
\backgroundsetup{
scale=1,
color=black,
angle=0,
opacity=1,
contents= {
  \begin{tikzpicture}[remember picture, overlay]
  \node[
    inner sep=0pt,
    text width=\the\dimexpr\textwidth+1.5cm\relax
  ] 
    at (current page.center) (border) {\rule{0pt}{\dimexpr\textheight+2cm\relax}};
  \foreach \valsection in {0,...,\numexpr\totvalue{section}-1\relax}
  {
    \node[
      \ifnum\thesection<\numexpr\valsection+1\relax 
        tab%
      \else 
      \ifnum\thesection>\numexpr\valsection+1\relax 
        tab%
      \else selectedtab%
      \fi\fi,
      minimum height=\mylena
      ] 
      at ([yshift=-(0.5+\valsection)*\mylena]border.north east) 
      (tab-\valsection) 
      {\hspace*{25pt}\rotatebox{-90}{%
        \hyperlink{sec:\valsection}{Section \the\numexpr\valsection+1\relax}%
        }
      };
  }
  \node[
    draw=gray,
    line width=2pt,
    rectangle,
    rounded corners=10pt,
    inner sep=0pt,
    text width=\the\dimexpr\textwidth+1.5cm\relax,
    fill=white
  ] 
    at (current page.center) 
    {\rule{0pt}{\dimexpr\textheight+2cm\relax}};
  \node[font=\LARGE\sffamily,fill=white] 
    at (border.south) 
    {\makebox[3em][c]{\thepage}};
\end{tikzpicture}}
  }
}

\begin{document}

\section{Section One}
\hypertarget{sec:0}{}
\lipsum[1-3]
\section{Test Section Two}
\hypertarget{sec:1}{}
\lipsum[1-3]
\section{Test Section Three}
\hypertarget{sec:2}{}
\lipsum[1-3]
\section{Test Section Four}
\hypertarget{sec:3}{}
\lipsum[2]

\end{document}

Basically I reused some code from my answer to How to print section titles like tab-list? but introducing some \hypertarget, \hyperlink commands to make the tabs hyperlinked to the corresponding section.

9
  • This is a very awesome solution. I have two questions: 1. Do you want to make the dummy space \phantom{aaa} to be clickable (as hyperlink) or is that 2nd } around \phantom{aaa} accidental and should rather be at the end of \relax?. 2nd. Does the \hyperlink need to be an overlay again, since they are somehow shifted? I am not an tikz expert, so I thought I ask...
    – user31729
    May 29, 2014 at 17:48
  • @Gonzola Medina: Thanks a lot, this is exactly what I was looking for
    – Harald
    May 29, 2014 at 17:51
  • @ChristianHupfer Thanks. The clickable area should be "Section #", so the } should be at the end of \relax and the \phantom is not really supposed to be there; however, as I mentioned, the links are shifted. I discovered the cause of the problem now, but don't have the time to attempt the solution right now; I'll do it later. May 29, 2014 at 17:51
  • 2
    @ChristianHupfer I updated the answer. The problem was thet \hyperlink doesn't behave well when a node and its content are rotated using the rotate key, so I had to do the rotation of the content with a \rotatebox from graphicx and introducing some modifications to the original tab and selectedtab styles. May 30, 2014 at 0:12
  • 2
    @Harald I updated my answer introducing some improvements; in particular, now the clickable areas (the hyperlinks for the lateral tabs) are in the appropriate location. May 30, 2014 at 0:13
4

An example with the package TColorBox.

When viewing a PDF document as reading a paper book, one can consider positioning tabs on the left side on even pages and on the right side on odd pages.

\documentclass[twoside]{book}

\usepackage[margin=1in]{geometry}
\usepackage[]{hyperref}
\usepackage[all]{tcolorbox}
\usepackage{eso-pic}
\usepackage{nameref}
\usepackage{changepage}
\usepackage{lipsum}


% Tabs dimensions
\def\RightTabsNumberOf{5}
\newlength\RightTabVerticalLength  
\setlength\RightTabVerticalLength{\dimexpr(\paperheight/\RightTabsNumberOf*97/100)\relax} 
\newlength\RightTabVerticalDistance  
\setlength\RightTabVerticalDistance{\dimexpr(\paperheight/\RightTabsNumberOf-(1mm/\RightTabsNumberOf))\relax} 


\newcommand{\ClickableTcolorBox}[2]{
 \begin{tcolorbox}[enhanced,size=normal,center upper,fontupper={\Large\bfseries}, colback={#2!50},width=\RightTabVerticalLength,arc=3mm,
 if odd page={rounded corners=north}{rounded corners=south},
 if odd page={sharp corners=south}{sharp corners=north},
 if odd page={bottomrule=0mm}{toprule=0mm},
 hyperref=#1
]
\nameref{#1}
\end{tcolorbox}
}


\newcommand{\RightTabs}{
\begin{tikzpicture}[overlay, remember picture]
\node (Tab1) [above left,xshift=1mm,rotate=90] at 
(current page.north east){
\ClickableTcolorBox{LinkToChapterOne}{violet}};
\node (Tab2) [above left,xshift=1mm,
yshift=-\RightTabVerticalDistance,rotate=90] at 
(current page.north east){
\ClickableTcolorBox{LinkToChapterTwo}{blue}};
\node (Tab3) [above left,xshift=1mm,
yshift=-2*\RightTabVerticalDistance,rotate=90] at
(current page.north east){
\ClickableTcolorBox{LinkToChapterThree}{green}};
\node (Tab4) [above left,xshift=1mm,
yshift=-3*\RightTabVerticalDistance,rotate=90] at 
(current page.north east){
\ClickableTcolorBox{LinkToChapterFour}{yellow}};
\node (Tab5) [above left,xshift=1mm,
yshift=-4*\RightTabVerticalDistance,rotate=90] at 
(current page.north east){
\ClickableTcolorBox{LinkToChapterFive}{red}};
\end{tikzpicture}
}



\newcommand{\LeftTabs}{
\begin{tikzpicture}[overlay, remember picture]
\node (LeftTab1) [below left,xshift=-1mm,rotate=90] at 
(current page.north west){
\ClickableTcolorBox{LinkToChapterOne}{violet}};
\node (LeftTab2) [below left,xshift=-1mm,
yshift=-\RightTabVerticalDistance,rotate=90] at 
(current page.north west){
\ClickableTcolorBox{LinkToChapterTwo}{blue}};
\node (LeftTab3) [below left,xshift=-1mm,
yshift=-2*\RightTabVerticalDistance,rotate=90] at
(current page.north west){
\ClickableTcolorBox{LinkToChapterThree}{green}};
\node (LeftTab4) [below left,xshift=-1mm,
yshift=-3*\RightTabVerticalDistance,rotate=90] at 
(current page.north west){
\ClickableTcolorBox{LinkToChapterFour}{yellow}};
\node (LeftTab5) [below left,xshift=-1mm,
yshift=-4*\RightTabVerticalDistance,rotate=90] at 
(current page.north west){
\ClickableTcolorBox{LinkToChapterFive}{red}};
\end{tikzpicture}
}


\strictpagecheck
\AddToShipoutPicture{
\checkoddpage
\ifoddpage
\RightTabs
\else
\LeftTabs
\fi
}


\begin{document}

\cleardoublepage
\chapter{Chapter One\label{LinkToChapterOne}}
\lipsum

\cleardoublepage
\chapter{Chapter Two\label{LinkToChapterTwo}}
\lipsum

\cleardoublepage
\chapter{Chapter Three\label{LinkToChapterThree}}
\lipsum

\cleardoublepage
\chapter{Chapter Four\label{LinkToChapterFour}}
\lipsum

\cleardoublepage
\chapter{Chapter Five\label{LinkToChapterFive}}
\lipsum

\end{document}

enter image description here enter image description here

2

A variant of my answer of How to make hyperlinked tabs with specific colors?

\documentclass[]{book}
\usepackage[rmargin=3cm]{geometry}
\usepackage[pageanchor=true]{hyperref}
\usepackage{tikz}
\usetikzlibrary{positioning}  
\usetikzlibrary{shapes}
\usepackage{eso-pic}
\usepackage{lipsum}


\def\TabThickness{8mm}

% RIGHT SIDE TABS

% Right side tabs dimensions
\def\RightTabsNumberOf{8}
\newlength\RightTabVerticalLength  
\setlength\RightTabVerticalLength{\dimexpr\paperheight/\RightTabsNumberOf\relax} 
\newlength\RightTabThickness
\setlength\RightTabThickness{\TabThickness}

% Right side tabs positioning
\newlength\xRightTab  
\setlength\xRightTab{\dimexpr\paperwidth-(\RightTabThickness)+1pt\relax}
\newlength\xRightTabText   
\setlength\xRightTabText{\dimexpr\RightTabThickness/2+1pt\relax}

\newlength\yRightTabOne
\newlength\yRightTabTwo
\newlength\yRightTabThree
\newlength\yRightTabFour
\newlength\yRightTabFive
\newlength\yRightTabSix
\newlength\yRightTabSeven
\newlength\yRightTabEight

\setlength\yRightTabOne{\dimexpr\paperheight-(\RightTabVerticalLength*1/2)\relax}
\setlength\yRightTabTwo{\dimexpr\paperheight-(\RightTabVerticalLength*3/2)\relax}
\setlength\yRightTabThree{\dimexpr\paperheight-(\RightTabVerticalLength*5/2)\relax}
\setlength\yRightTabFour{\dimexpr\paperheight-(\RightTabVerticalLength*7/2)\relax}
\setlength\yRightTabFive{\dimexpr\paperheight-(\RightTabVerticalLength*9/2)\relax}
\setlength\yRightTabSix{\dimexpr\paperheight-(\RightTabVerticalLength*11/2)\relax}
\setlength\yRightTabSeven{\dimexpr\paperheight-(\RightTabVerticalLength*13/2)\relax}
\setlength\yRightTabEight{\dimexpr\paperheight-(\RightTabVerticalLength*15/2)\relax}

% Right side tabs style
\tikzset{RightTabStyle/.style={align=center,
text=red!80!black,font=\scshape\bfseries,
text width=\RightTabVerticalLength,
text height=\RightTabThickness, 
text depth=\xRightTabText,
inner sep=0pt,thick,rectangle,rounded corners=5pt,rotate=270,
draw=blue,fill=yellow!80}}  %


\newcommand{\TheRightSideTabs}{%
\begin{tikzpicture}[remember picture,overlay]  
    \coordinate (CoordinatesRightTabOne) at (\xRightTab,\yRightTabOne) ;
    \coordinate (CoordinatesRightTabTwo) at (\xRightTab,\yRightTabTwo) ; 
    \coordinate (CoordinatesRightTabThree) at (\xRightTab,\yRightTabThree) ; 
    \coordinate (CoordinatesRightTabFour) at (\xRightTab,\yRightTabFour) ; 
    \coordinate (CoordinatesRightTabFive) at (\xRightTab,\yRightTabFive) ; 
    \coordinate (CoordinatesRightTabSix) at (\xRightTab,\yRightTabSix) ; 
    \coordinate (CoordinatesRightTabSeven) at (\xRightTab,\yRightTabSeven) ; 
    \coordinate (CoordinatesRightTabEight) at (\xRightTab,\yRightTabEight) ; 

\node (NodeRightTabOne)   at (CoordinatesRightTabOne) {\hyperlink{LinkToChapterOne}{\tikz\node[RightTabStyle]{Chapter 1};}}; 

\node (NodeRightTabTwo)   at (CoordinatesRightTabTwo) {\hyperlink{LinkToChapterTwo}{\tikz\node[RightTabStyle]{Chapter 2};}}; 

\node (NodeRightTabThree)   at (CoordinatesRightTabThree) {\hyperlink{LinkToChapterThree}{\tikz\node[RightTabStyle]{Chapter 3};}}; 

\node (NodeRightTabFour)   at (CoordinatesRightTabFour) {\hyperlink{LinkToChapterFour}{\tikz\node[RightTabStyle,text=green!80!black,fill=red!20!white]{Chapter 4};}}; 

\node (NodeRightTabFive)   at (CoordinatesRightTabFive) {\hyperlink{LinkToChapterFive}{\tikz\node[RightTabStyle]{Chapter 5};}}; 

\node (NodeRightTabSix)   at (CoordinatesRightTabSix) {\hyperlink{LinkToChapterSix}{\tikz\node[RightTabStyle]{Chapter 6};}}; 

\node (NodeRightTabSeven)   at (CoordinatesRightTabSeven) {\hyperlink{LinkToChapterSeven}{\tikz\node[RightTabStyle]{Chapter 7};}}; 

\node (NodeRightTabEight)   at (CoordinatesRightTabEight) {\hyperlink{LinkToChapterEight}{\tikz\node[RightTabStyle]{Chapter 8};}}; 

\end{tikzpicture}
}    


\AddToShipoutPicture{
\TheRightSideTabs
 }

\begin{document}
\mainmatter


\cleardoublepage
\hypertarget{LinkToChapterOne}{\chapter{Chapter One}}
\lipsum

\cleardoublepage
\hypertarget{LinkToChapterTwo}{\chapter{Chapter Two}}
\lipsum

\cleardoublepage
\hypertarget{LinkToChapterThree}{\chapter{Chapter Three}}
\lipsum

\cleardoublepage
\hypertarget{LinkToChapterFour}{\chapter{Chapter Four}}
\lipsum

\cleardoublepage
\hypertarget{LinkToChapterFive}{\chapter{Chapter Five}}
\lipsum

\cleardoublepage
\hypertarget{LinkToChapterSix}{\chapter{Chapter Six}}
\lipsum

\cleardoublepage
\hypertarget{LinkToChapterSeven}{\chapter{Chapter Seven}}
\lipsum

\cleardoublepage
\hypertarget{LinkToChapterEight}{\chapter{Chapter Eight}}
\lipsum


\end{document}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .