# How to print section titles like tab-list?

Can I create a user manual with sections at the right like multi-tab?

Like this:

-- I think maybe I can template the page by tikz. (That will be very flexible if possible) so I added the tikz tag.

-

Here's a possible option using the background package to place the border, the tabs and the page number:

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

\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,anchor=south,
draw=gray,thick,rectangle,rounded corners=12pt,rotate=270,
align=center,text height=20pt,
text depth=25pt,inner sep=0pt,fill=gray!20,
yshift=-18pt,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,xshift=(0.5+\valsection)*\mylena]
at (border.north east) (tab-\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{Test Section One}
\lipsum[1-3]
\section{Test Section Two}
\lipsum[1-3]
\section{Test Section Three}
\lipsum[1-3]
\section{Test Section Four}
\lipsum[2]

\end{document}


The document needs to be processed three times.

If the most recent version for the background package is not available, here's the code using the syntax for version 1.0:

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

\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,anchor=south,
draw=gray,thick,rectangle,rounded corners=12pt,rotate=270,
align=center,text height=20pt,
text depth=25pt,inner sep=0pt,fill=gray!20,
yshift=-18pt,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
\SetBgScale{1}
\SetBgColor{black}
\SetBgAngle{0}
\SetBgOpacity{1}
\SetBgContents{
\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,xshift=(0.5+\valsection)*\mylena]
at (border.north east) (tab-\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{Test Section One}
\lipsum[1-3]
\section{Test Section Two}
\lipsum[1-3]
\section{Test Section Three}
\lipsum[1-3]
\section{Test Section Four}
\lipsum[2]

\end{document}

-
I can't compile with latex (or xelatex): ... ABD: EveryShipout initializing macros ! Undefined control sequence. \@begindocumenthook ...}\relax } \backgroundsetup { scale=1, color=black, an... l.47 \begin{document} ?  I'm using TexLive 2012. – Xiè Jìléi Oct 7 '12 at 7:40
@XièJìléi the problem is that your system has not the most recent version of the background package; you can update the package, or use the code with the old syntax that I just added to my answer. Please let me know if this made the code compilable. – Gonzalo Medina Oct 7 '12 at 15:17
It's my mistake: I was run with TeXLive 2010, I have just reinstalled TeXLive 2012, and both versions are okay now. Cheers! – Xiè Jìléi Oct 7 '12 at 17:04
To highlight the current section, I added a selectedtab style, and coded: \node[\ifnum\thesection<\valsection tab\else \ifnum\thesection>\valsection tab\else selectedtab\fi\fi .... though it works, could it be shorter? I'm new to LaTeX programming. – Xiè Jìléi Oct 7 '12 at 17:10
@XièJìléi I think it's OK (although I had to make a little correction to the \valsection counter). I updated my answer with some modifications (including the highlighting for the current section, that I had forgotten about; thank you for reminding me about this). – Gonzalo Medina Oct 7 '12 at 22:18