Following the great idea of Gonzalo Medina presented in Clickable Chapters on the right side of each page, I wanted to extend this also for two sided books. What I am doing wrong? It seems that this code doesn't care if the page is even or odd...
Here is the code:
\documentclass[11pt,BCOR8mm,final,linktocpage,twoside,headsepline,a4paper]{scrbook}
\usepackage{background}
\usepackage{etoolbox}
\usepackage{graphicx}
\usepackage{totcount}
\usepackage{lipsum}
\usepackage{truncate}
\usepackage{changepage}
\usepackage{ifthen}
\usepackage[hidelinks]{hyperref}
\usepackage{scrextend}
\usepackage{ifoddpage}
\strictpagecheck
\def\striptext to#1 #2{\def\striptextout{}\def\tmp{#1}\striptextA #2\relax\end}
\def\striptextA{\futurelet\next\striptextB}
\def\striptextB{\ifx\next\relax \expandafter \skiptoend
\else \ifx\next\spacetoken
\edef\striptextoutA{\striptextout\space}%
\def\next{\afterassignment\striptextD \let\next= }%
\else \def\next{\striptextC}%
\fi \fi
\next
}
\def\striptextC#1{\edef\striptextoutA{\striptextout#1}\striptextD}
\def\striptextD{\setbox0=\hbox{\striptextoutA}%
\ifdim\wd0>\tmp\relax \expandafter \skiptoend
\else \let\striptextout=\striptextoutA \expandafter \striptextA
\fi
}
\def\skiptoend#1\end{}
\edef\tmp{\let\noexpand\spacetoken= \space}\tmp
% to have access to the total number of sections
\regtotcounter{chapter}
% every section starts on a new page
\pretocmd{\chapter}{\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=2pt, % 12pt
align=center,
text width=23pt,
inner sep=0pt,
fill=gray!20,
font=\sffamily\scriptsize
}
}
% 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}
% the main part; as background material we place the border,
% the section (current and other) tabs and the page number
\AtBeginDocument{
% calculation of the width for each tab
\setlength\mylen{\dimexpr\textheight+2cm\relax}
\ifnum\totvalue{chapter}>0
\setlength\mylena{\dimexpr\mylen/\totvalue{chapter}\relax}
\fi
\checkoddpage\ifoddpage%
\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 \valchapter in {0,...,\numexpr\totvalue{chapter}-1\relax}
{
\node[
\ifnum\thechapter<\numexpr\valchapter+1\relax
tab%
\else
\ifnum\thechapter>\numexpr\valchapter+1\relax
tab%
\else selectedtab%
\fi\fi,
minimum height=\mylena
]
at ([yshift=-(0.5+\valchapter)*\mylena]border.north east)
(tab-\valchapter)
{\hspace*{10pt}\rotatebox{+90}{%
\hyperlink{sec:\valchapter}{{ \scriptext {\nameref{sec:\the\numexpr\valchapter }} \striptextout \ldots }\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=\small\sffamily,fill=white] %
at (border.south)
{\makebox[3em][c]{\thepage}};
\end{tikzpicture}}
}
%}
\else
\egroup
\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 ([xshift=-20.3cm] current page.center) (border) {\rule{0pt}{\dimexpr\textheight+2cm\relax}};
\foreach \valchapter in {0,...,\numexpr\totvalue{chapter}-1\relax}
{
\node[
\ifnum\thechapter<\numexpr\valchapter+1\relax
tab%
\else
\ifnum\thechapter>\numexpr\valchapter+1\relax
tab%
\else selectedtab%
\fi\fi,
minimum height=\mylena
]
at ([yshift=-(0.5+\valchapter)*\mylena]border.north east)
(tab-\valchapter)
{\hspace*{0pt}\rotatebox{-90}{%
\hyperlink{sec:\valchapter}{{ \scriptext {\nameref{sec:\the\numexpr\valchapter }} \striptextout \ldots }\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=\small\sffamily,fill=white] %
at (border.south)
{\makebox[3em][c]{\thepage}};
\end{tikzpicture}}
}
\fi}
%%%%%
\begin{document}
\chapter{Introduction}
\label{sec:0}
\hypertarget{sec:0}{}
\lipsum[1-3]
\chapter{Idea No 1}
\label{sec:1}
\hypertarget{sec:1}{}
\lipsum[1-3]
\chapter{Idea No 2}
\label{sec:2}
\hypertarget{sec:2}{}
\lipsum[1-3]
\chapter{Idea No 3}
\label{sec:3}
\hypertarget{sec:3}{}
\lipsum[1-3]
\chapter{Idea No 4}
\label{sec:4}
\hypertarget{sec:4}{}
\lipsum[1-3]
\chapter{TIdea No 5}
\label{sec:5}
\hypertarget{sec:5}{}
\lipsum[1-3]
\end{document}

\scriptext. Could you please fix this? Anyway. Do you want the positions of the tabs to be always in the outer margin? – Gonzalo Medina Feb 25 '15 at 17:36