![拇指索引部分](https://linux22.com/image/288475/%E6%8B%87%E6%8C%87%E7%B4%A2%E5%BC%95%E9%83%A8%E5%88%86.png)
我发现这脚本,但无法调整部分内容。以下是我目前得到的结果:
\documentclass{book}
\usepackage{background}
\usetikzlibrary{calc}
\usepackage{ifthen}
\usepackage{lipsum}
\pagestyle{plain}
% background common settings
\SetBgScale{1}
\SetBgAngle{0}
\SetBgOpacity{1}
\SetBgContents{}
% auxiliary counter
\newcounter{partshift}
\addtocounter{partshift}{-1}
\definecolor{mp}{RGB}{240,240,240}
\let\Oldpart\part
\newcommand{\parttitle}{}
\renewcommand{\part}[1]{\Oldpart{#1}\pf\renewcommand{\parttitle}{#1}}
% the main command; the mandatory argument sets the color of the vertical box
\makeatletter
\newcommand\pf{%
\AddEverypageHook{%
\ifthenelse{\isodd{\thepage}}
{\SetBgContents{%
\begin{tikzpicture}[overlay,remember picture]
\node[fill=mp,inner sep=0pt,rectangle,text width=2cm,
text height=4cm,align=center,anchor=north east]
at ($ (current page.north east) + (-0cm,-2*\thepartshift cm) $)
{\rotatebox{90}{\hspace*{.3cm}\parbox[c][1.5cm][t]{3.4cm}{%
\raggedright\textcolor{black}{\parttitle}}}};
\end{tikzpicture}}%
}
{\SetBgContents{%
\begin{tikzpicture}[overlay,remember picture]
\node[fill=mp,inner sep=0pt,rectangle,text width=2cm,
text height=4cm,align=center,anchor=north west]
at ($ (current page.north west) + (-0cm,-2*\thepartshift cm) $)
{\rotatebox{90}{\hspace*{.3cm}\parbox[c][1.5cm][t]{3.4cm}{%
\raggedright\textcolor{black}{\parttitle}}}};
\end{tikzpicture}}
}
\bg@material}%
\stepcounter{partshift}
}
\makeatother
\begin{document}
\part{A}
\chapter{a1}
\lipsum[1-7]
\part{B}
\chapter{b1}
\lipsum[1-7]
\part{C}
\chapter{c1}
\lipsum[1-7]
\end{document}
答案1
更新
以下代码已更新,以使用新的语法background
。更新后的语法由 Gonzalo Medina 提供,以替换我最初引用的代码这个答案. 查看评论了解历史。
我不确定如何直接修改代码,因为它\part
的工作原理与我理解的有点不同\chapter
。但是,可以将 Gonzalo Medina 的代码的部分内容与修改后的代码结合起来,以book.cls
实现类似的效果:
\documentclass{book}
\usepackage[scale=1,angle=0,opacity=1]{background}
\usetikzlibrary{calc}
\usepackage{ifthen}
\usepackage{lipsum}
\backgroundsetup{contents={}}
\pagestyle{plain}
% auxiliary counter
\newcounter{partshift}
\addtocounter{partshift}{-1}
\definecolor{mp}{RGB}{240,240,240}
\newcommand{\parttitle}{}
\makeatletter
\def\@part[#1]#2{%
\renewcommand\parttitle{#1}%
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
{\pf%
\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\bfseries \partname\nobreakspace\thepart
\par
\vskip 20\p@
\fi
\Huge \bfseries #2\par}%
\@endpart}
\makeatother
% the main command; the mandatory argument sets the color of the vertical box
\newcommand\pf{%
\AddEverypageHook{%
\ifthenelse{\isodd{\value{page}}}
{%
\backgroundsetup{%
contents={%
\begin{tikzpicture}[overlay,remember picture]
\node[
fill=mp,
inner sep=0pt,
outer sep=0pt,
rectangle,
text width=2cm,
minimum height=4cm,
align=center,
anchor=north east,
]
at ( $ (current page.north east) + (0,-2*\thepartshift cm) $ )
{\rotatebox{90}{\parbox[c][1.5cm][t]{3.5cm}{\textcolor{black}{\centering\parttitle}}}};
\end{tikzpicture}%
}%
}%
}
{%
\backgroundsetup{%
contents={%
\begin{tikzpicture}[overlay,remember picture]
\node[
fill=mp,
inner sep=0pt,
outer sep=0pt,
rectangle,
text width=2cm,
minimum height=4cm,
align=center,
anchor=north west,
]
at ($ (current page.north west) + (0,-2*\thepartshift cm) $)
{\rotatebox{90}{\parbox[c][1.5cm][t]{3.5cm}{\textcolor{black}{\centering\parttitle}}}};
\end{tikzpicture}%
}%
}%
}
\BgMaterial}%
\stepcounter{partshift}%
}
\begin{document}
\part{A}
\chapter{a1}
\lipsum[1-7]
\part{B}
\chapter{b1}
\lipsum[1-7]
\part{C}
\chapter{c1}
\lipsum[1-7]
\end{document}