如何使侧边标签链接到文档内的特定位置(例如:每章的开头)?
答案1
一个可能的答案是:
\documentclass[]{book}
\usepackage[vmargin=3cm,hmargin=3cm,lmargin=3cm,rmargin=3cm,hoffset=0mm,voffset=0mm]{geometry}
\usepackage[colorlinks=true,pageanchor=true]{hyperref}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes}
\usepackage{eso-pic}
\usepackage{totcount}
\usepackage{changepage}
\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}
}
% LEFT SIDE TABS
% Left side tabs dimensions
\def\LeftTabsNumberOf{2}
\newlength\LeftTabVerticalLength
\setlength\LeftTabVerticalLength{\dimexpr\paperheight/\LeftTabsNumberOf\relax}
\newlength\LeftTabThickness
\setlength\LeftTabThickness{\TabThickness}
% Left side tabs positioning
\newlength\xLeftTab
\setlength\xLeftTab{\dimexpr(\LeftTabThickness)\relax}
\newlength\xLeftTabText
\setlength\xLeftTabText{\dimexpr(\LeftTabThickness*1/2)\relax}
\newlength\yLeftTabOne
\newlength\yLeftTabTwo
\setlength\yLeftTabOne{\dimexpr\paperheight-(\LeftTabVerticalLength*1/2)\relax}
\setlength\yLeftTabTwo{\dimexpr\paperheight-(\LeftTabVerticalLength*3/2)\relax}
% Left side tabs style
\tikzset{LeftTabStyle/.style={align=center,
text=pink!80!black,font=\scshape\bfseries,
text width=\LeftTabVerticalLength,
text height=\xLeftTab,
text depth=\xLeftTabText,
inner sep=0pt,thick,rectangle,rounded corners=5pt,rotate=90,
draw=red,fill=blue!5}} %
\newcommand{\TheLeftSideTabs}{%
\begin{tikzpicture}[remember picture,overlay]
\coordinate (CoordinatesLeftTabOne) at (\xLeftTab,\yLeftTabOne) ;
\coordinate (CoordinatesLeftTabTwo) at (\xLeftTab,\yLeftTabTwo) ;
\node (NodeLeftTabOne) at (CoordinatesLeftTabOne) {\hyperlink{LinkToChapterOne}{\tikz\node[LeftTabStyle]{Chapter 1};}};
\node (NodeLeftTabTwo) at (CoordinatesLeftTabTwo) {\hyperlink{LinkToChapterTwo}{\tikz\node[LeftTabStyle]{Chapter 2};}};
\end{tikzpicture}
}
% UP SIDE TABS
% Up side tabs dimensions
\def\UpTabsNumberOf{2}
\newlength\UpTabThickness
\setlength\UpTabThickness{\TabThickness}
\newlength\UpTabLength
\setlength\UpTabLength{\dimexpr((\paperwidth-5cm)/\UpTabsNumberOf)\relax}
% Up side tabs positioning
\newlength\xUpTabOne
\setlength\xUpTabOne{\dimexpr(\UpTabLength*1/2+2.5cm)\relax}
\newlength\xUpTabTwo
\setlength\xUpTabTwo{\dimexpr(\UpTabLength*3/2+2.5cm)\relax}
\newlength\yUpTab
\setlength\yUpTab{\dimexpr((\paperheight-\UpTabThickness)*2)\relax}
\newlength\yUpTabText
\setlength\yUpTabText{\dimexpr(\UpTabThickness*1/2)\relax}
% Up side tabs style
\tikzset{UpTabStyle/.style={align=center,
text=blue!80!black,font=\scshape\bfseries,
text width=\UpTabLength,
text height=\yUpTab,
text depth=\yUpTabText,
inner sep=0pt,thick,rectangle,rounded corners=5pt,rotate=0,
draw=orange!80!black,fill=orange!5}} %
\newcommand{\TheUpSideTabs}{%
\begin{tikzpicture}[remember picture,overlay]
\coordinate (CoordinatesUpTabOne) at (\xUpTabOne,\yUpTab) ;
\coordinate (CoordinatesUpTabTwo) at (\xUpTabTwo,\yUpTab) ;
\node (NodeUpTabOne) at (CoordinatesUpTabOne) {\hyperlink{LinkToChapterOne}{\tikz\node[UpTabStyle]{Chapter 1};}};
\node (NodeUpTabTwo) at (CoordinatesUpTabTwo) {\hyperlink{LinkToChapterTwo}{\tikz\node[UpTabStyle]{Chapter 2};}};
\end{tikzpicture}
}
% DOWN SIDE TABS
% Down side tabs dimensions
\def\DownTabsNumberOf{2}
\newlength\DownTabThickness
\setlength\DownTabThickness{\TabThickness}
\newlength\DownTabLength
\setlength\DownTabLength{\dimexpr((\paperwidth-5cm)/\DownTabsNumberOf)\relax}
% Down side tabs positioning
\newlength\xDownTabOne
\setlength\xDownTabOne{\dimexpr(\UpTabLength*1/2+2.5cm)\relax}
\newlength\xDownTabTwo
\setlength\xDownTabTwo{\dimexpr(\UpTabLength*3/2+2.5cm)\relax}
\newlength\yDownTab
\setlength\yDownTab{\dimexpr(\DownTabThickness)\relax}
\newlength\yDownTabText
\setlength\yDownTabText{\dimexpr(\DownTabThickness*1/2)\relax}
% Down side tabs style
\tikzset{DownTabStyle/.style={align=center,
text=pink!80!black,font=\scshape\bfseries,
text width=\DownTabLength,
text height=\yDownTab,
text depth=\yDownTabText,
inner sep=0pt,thick,rectangle,rounded corners=5pt,rotate=0,
draw=green!80!black,fill=green!5}} %
\newcommand{\TheDownSideTabs}{%
\begin{tikzpicture}[remember picture,overlay]
\coordinate (CoordinatesDownTabOne) at (\xDownTabOne,\yDownTab) ;
\coordinate (CoordinatesDownTabTwo) at (\xUpTabTwo,\yDownTab) ;
\node (NodeDownTabOne) at (CoordinatesDownTabOne) {\hyperlink{LinkToChapterOne}{\tikz\node[DownTabStyle]{Chapter 1};}};
\node (NodeDownTabTwo) at (CoordinatesDownTabTwo) {\hyperlink{LinkToChapterTwo}{\tikz\node[DownTabStyle]{Chapter 2};}};
\end{tikzpicture}
}
\AddToShipoutPicture{
\TheRightSideTabs
\TheLeftSideTabs
\TheUpSideTabs
\TheDownSideTabs
}
\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}
答案2
使用包TColorBox。
如果是奇数页,则垂直标签在右侧;如果是偶数页,则垂直标签在左侧。
\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}
\tcbset{enhanced,size=normal,center upper,fontupper={\Large\bfseries},arc=3mm,width=\RightTabVerticalLength}
\newcommand{\LeftRightClickableTcolorBox}[2]{
\begin{tcolorbox}[colback={#2!50},
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{\UpClickableTcolorBox}[2]{
\begin{tcolorbox}[colback={#2!50},rounded corners=south,
sharp corners=north,toprule=0mm,
hyperref=#1
]
\nameref{#1}
\end{tcolorbox}
}
\newcommand{\DownClickableTcolorBox}[2]{
\begin{tcolorbox}[colback={#2!50},
sharp corners=south, rounded corners=north, bottomrule=0mm,
hyperref=#1
]
\nameref{#1}
\end{tcolorbox}
}
\newcommand{\RightTabs}{
\begin{tikzpicture}[overlay, remember picture]
\node (RightTab1) [above left,xshift=1mm,rotate=90] at
(current page.north east){
\LeftRightClickableTcolorBox{LinkToChapterOne}{violet}};
\node (RightTab2) [above left,xshift=1mm,
yshift=-\RightTabVerticalDistance,rotate=90] at
(current page.north east){
\LeftRightClickableTcolorBox{LinkToChapterTwo}{blue}};
\node (RightTab3) [above left,xshift=1mm,
yshift=-2*\RightTabVerticalDistance,rotate=90] at
(current page.north east){
\LeftRightClickableTcolorBox{LinkToChapterThree}{green}};
\node (RightTab4) [above left,xshift=1mm,
yshift=-3*\RightTabVerticalDistance,rotate=90] at
(current page.north east){
\LeftRightClickableTcolorBox{LinkToChapterFour}{yellow}};
\node (RightTab5) [above left,xshift=1mm,
yshift=-4*\RightTabVerticalDistance,rotate=90] at
(current page.north east){
\LeftRightClickableTcolorBox{LinkToChapterFive}{red}};
\end{tikzpicture}
}
\newcommand{\LeftTabs}{
\begin{tikzpicture}[overlay, remember picture]
\node (LeftTab1) [below left,xshift=-1mm,rotate=90] at
(current page.north west){
\LeftRightClickableTcolorBox{LinkToChapterOne}{violet}};
\node (LeftTab2) [below left,xshift=-1mm,
yshift=-\RightTabVerticalDistance,rotate=90] at
(current page.north west){
\LeftRightClickableTcolorBox{LinkToChapterTwo}{blue}};
\node (LeftTab3) [below left,xshift=-1mm,
yshift=-2*\RightTabVerticalDistance,rotate=90] at
(current page.north west){
\LeftRightClickableTcolorBox{LinkToChapterThree}{green}};
\node (LeftTab4) [below left,xshift=-1mm,
yshift=-3*\RightTabVerticalDistance,rotate=90] at
(current page.north west){
\LeftRightClickableTcolorBox{LinkToChapterFour}{yellow}};
\node (LeftTab5) [below left,xshift=-1mm,
yshift=-4*\RightTabVerticalDistance,rotate=90] at
(current page.north west){
\LeftRightClickableTcolorBox{LinkToChapterFive}{red}};
\end{tikzpicture}
}
\newcommand{\UpTabs}{
\begin{tikzpicture}[overlay, remember picture]
\node (UpTab1) [below,xshift=-0.5*\RightTabVerticalDistance,yshift=0mm,rotate=0] at (current page.north){
\UpClickableTcolorBox{LinkToChapterOne}{orange}};
\node (UpTab2) [below,xshift=0.5*\RightTabVerticalDistance,yshift=0mm,rotate=0] at
(current page.north){
\UpClickableTcolorBox{LinkToChapterTwo}{pink}};
\end{tikzpicture}
}
\newcommand{\DownTabs}{
\begin{tikzpicture}[overlay, remember picture]
\node (DownTab1) [above,xshift=-\RightTabVerticalDistance,yshift=0mm,rotate=0] at (current page.south){
\DownClickableTcolorBox{LinkToChapterOne}{cyan}};
\node (DownTab2) [above,xshift=0mm,yshift=0mm,rotate=0] at
(current page.south){
\DownClickableTcolorBox{LinkToChapterTwo}{magenta}};
\node (DownTab3) [above,xshift=\RightTabVerticalDistance,
yshift=0mm,rotate=0] at
(current page.south){
\DownClickableTcolorBox{LinkToChapterThree}{teal}};
\end{tikzpicture}
}
\strictpagecheck
\AddToShipoutPicture{
\UpTabs
\DownTabs
\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}