This is a follow-up question to How to print section titles like tab-list?.
I want to insert section titles somewhere in the background in every pages. (It could be chapter titles, well)
I've searched around but did'nt find anything other then the current section title.
MWE-1:
\documentclass{article}
\usepackage{lipsum}
\begin{document}
\section{The first section}
\lipsum[1-3]
\section{The second section}
\lipsum[1-3]
\section{The third section}
\lipsum[1-3]
\section{The fourth section}
Hi, I'm the 4th.
The title of the 2nd section is... ?? Huh??
\section{The fifth section}
\lipsum[1-3]
\section{The sixth section}
\lipsum[1-3]
\section{The seventh section}
\lipsum[1-3]
\end{document}
MWE-2:
In practice, I need to typeset actual section titles in the following tab buttons:
\documentclass{article}
\usepackage[a5paper,vmargin=2cm]{geometry}
\usepackage{background}
\usepackage{etoolbox}
\usepackage{totcount}
\usepackage{lipsum}
% 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\frameheight
\newlength\avgtabwidth
% style for the section tabs
\tikzset{tab/.style={
text width=\avgtabwidth,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\frameheight{\dimexpr\textheight+2cm\relax}
\ifnum\totvalue{section}>0
\setlength\avgtabwidth{\dimexpr\frameheight/\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]
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 tab\relax
\else \ifnum\thesection>\numexpr\valsection+1 tab\relax
\else selectedtab\fi\fi,
xshift=(0.5+\valsection)*\avgtabwidth]
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}
\pagestyle{headings}
) or a way to retrieve the section title in cross-referencing (like with thenameref
)?nameref
. See Get the title instead of number of a referenced chapter? Is that what you're after? If so, this question would be considered a duplicate.background
package. Please see the example in my previous question tex.stackexchange.com/questions/75637/….\label
, the section number is auto calculated, (e.g., in a \for loop) It's just like to implement a simple table of contents, or navigator bar myself. But\nameref
could work if sections and chapters are automatically labelled. (what's the auto ref name? Maybesec:1
orchap:2
? can I\for\chapindex... \nameref{chap:\chapindex}
?)