在下面给出的放置章节缩略图的代码中,我想修改简单的矩形框以将其作为新的章节缩略图:
这是我目前拥有的代码:
代码
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{geometry}
\usepackage{atveryend}%%%% <--- !
\usepackage{etoolbox,fancyhdr}
\usepackage{fourier}
\usetikzlibrary{calc}
\definecolor{ultramarine}{RGB}{0,45,97}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{line}{RGB}{70,160,216}
\definecolor{fillh}{RGB}{225,233,251}
\renewcommand{\headrulewidth}{0pt}
\newcommand\hdheight{1in}
%======================================================================================
% CHAPTER THUMB
%======================================================================================
\def\subsectiontitle{}
\renewcommand{\sectionmark}[1]{\markright{\sffamily\normalsize#1}{}}
\renewcommand{\subsectionmark}[1]{\def\subsectiontitle{#1}}
\usetikzlibrary{tikzmark,calc,arrows,shapes,decorations.pathreplacing,pgfplots.groupplots, matrix}
\tikzset{every picture/.style={remember picture}}
\pagestyle{plain}
% auxiliary counter
\newcounter{chapshift}
\addtocounter{chapshift}{-1}
% the list of colors to be used (add more if needed)
\newcommand\BoxColor{%
%\ifcase\thechapshift blue!30\or red!30\or olive!30\or magenta!30\else yellow!30\fi}
ultramarine}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhf{}
\fancyhead[E]{%
\begin{tikzpicture}[overlay, remember picture]%
\fill[fillh] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
\draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
\node[anchor=south west, font=\sffamily, text width=1cm] (evenpagenum) at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\thepage};
\node[anchor=south west, text width=1.5cm, text=white, font=\fontsize{2cm}{5.5cm}\selectfont] (chapter) at (evenpagenum.south east) {\thechapter};
\node[anchor=south west] at (chapter.south east) {\leftmark};
\node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
text height=4cm,align=center,anchor=north east]
at ($ (current page.north east) + (-0cm,-2*\thechapshift cm) $)
{\rotatebox{90}{\parbox{4cm}{%
\centering\textcolor{white}{\bfseries\scshape\rightmark \\ \sffamily\subsectiontitle}}}};
\end{tikzpicture}
}%
\fancyhead[O]{%
\begin{tikzpicture}[overlay, remember picture]%
\fill[fillh] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
\draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
\node[align=right, anchor=south east, font=\sffamily, text width=1cm] (evenpagenum) at ($(current page.north east)+(-.5\hdheight,-\hdheight)$) {\thepage};
\node[align=right, anchor=south east, text width=1.5cm, text=white, font=\fontsize{2cm}{5.5cm}\selectfont] (chapter) at (evenpagenum.south west) {\thechapter};
\node[align=right, anchor=south east] at (chapter.south west) {\leftmark};
\node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
text height=4cm,align=center,anchor=north west]
at ($ (current page.north west) + (-0cm,-2*\thechapshift cm) $)
{\rotatebox{90}{\parbox{4cm}{%
\centering\textcolor{white}{\bfseries\scshape\rightmark \\ \sffamily\subsectiontitle}}}};
\end{tikzpicture}
}
\fancyfoot[CE]{}
\fancyfoot[CO]{}
\setlength{\headheight}{12pt}
\usepackage[height={2cm},distance={2mm},topthumbmargin={auto},bottomthumbmargin={auto}]{thumbs}%%%% <--- !
\begin{document}
\pagenumbering{arabic}%%%% <--- !
\chapter{Problems}
\addthumb{\thechapter}{\Large{\thechapter}}{white}{mybluei}%%%% <--- !
\section{Problem 1}
\subsection{Problem 1}
\lipsum[1]
\subsection{Solution 1}
\lipsum[1-7]
\cleardoublepage
\appendix
\chapter{Appendix \thechapter}
\addthumb{\thechapter}{\Large{\thechapter}}{white}{mybluei}%%%% <--- !
\lipsum[1-20]
\end{document}
答案1
以下是使用该软件包的解决方案(已编辑)thumbs
,如评论中所要求。我删除了旧的解决方案,因为我认为该thumbs
软件包的高级行为本质上总是更可取。
抱歉,我从零开始,因为我不确定您的 MWE 中实际上需要什么。
概述
- 为了获得图形,我们使用from覆盖
\rule
within命令\th@mbprint
\patchcmd
etoolbox
- 我们使用包装
\th@mbposyA
的长度来确定线的长度thumbs
\paperheight
- 我们附加到
\chaptermark
以存储章节标题\chap@title
,然后将其轮换到受保护的组中\chaptitle
- 我们还使用
\apptocmd
from在每个之后etoolbox
调用\addthumb
\chapter
平均能量损失
\documentclass{book}
\usepackage[a6paper]{geometry} % demo only
\usepackage{lipsum} % demo only
% <solution>
\usepackage[width=1cm,height=3cm,distance=2mm]{thumbs} % for thumbs
\usepackage{etoolbox} % fot patching
\usepackage{tikz} % for drawing
\usetikzlibrary{arrows} % for "-o"
\definecolor{mybluei}{RGB}{0,173,239}
\makeatletter
\newcommand{\fancyrule}[2]{%
% \rule{#1}{#2} % DEBUG: original thumbs behaviour
\ifodd\c@CurrentPage\def\sign{+}\else\def\sign{-}\fi % flip stuff
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle ++ (#1,#2); % same placement
\fill[\th@mbbackgroundcolourA] % color block
(#1,#2) rectangle
(0,0) --
++ (+0.5#1,-0.5#1) --
++ (+0.5#1,+0.5#1);
\draw[\th@mbbackgroundcolourA,ultra thick,-o] % middle line
(0.5#1,#2) --
++ (0,\th@mbposyA-#2-\paperheight+2#1) --
++ (\sign1.5#1,-1.5#1);
\draw[\th@mbbackgroundcolourA,ultra thick,-o] % inner line
(0.5#1\sign0.5#1,#2) --
++ (0,\th@mbposyA-#2-\paperheight+2.212#1) --
++ (\sign1.0#1,-1.0#1);
% \draw[red,dashed] (0,0) rectangle (#1,#2); % DEBUG: same as original
\end{tikzpicture}
}
\patchcmd{\th@mbprint}{\rule}{\fancyrule}{}{} % patch the "rule"
\newcommand{\chaptitle}{% for rotating the thumbs content
\ifodd\c@CurrentPage\def\sign{-}\else\def\sign{+}\fi
\rotatebox{\sign90}{\chap@title}
}
\let\ochaptermark\chaptermark % for storing the chapter title
\def\chaptermark#1{\def\chap@title{#1}\ochaptermark{#1}}
\apptocmd{\@chapter}{% add thumb after every chapter command
\addthumb{\thechapter}{\sffamily \protect\chaptitle}{white}{mybluei}
}{}{}
\makeatother
% </solution>
\begin{document}
\pagenumbering{arabic}
\chapter{Problems}
\lipsum[1-2]
\section{Hard Ones}
\lipsum[3-4]
\cleardoublepage
\chapter{Solutions}
\lipsum[1-2]
\appendix
\chapter{Miscellaneous}
\lipsum[1-2]
\end{document}
输出
(a6paper
非常小,所以我们可以看到多个页面)
答案2
这是扩展版本,可以移动并环绕。它基于 @jessexknight 的示例。
\documentclass{book}
\usepackage{lipsum}
\usepackage{atbegshi}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{math}
\makeatletter
\newlength\ctw % half width
\newlength\cth % height
\newlength\ctx % x-offset
\newlength\ctf
\newlength\cttopmargin % top margin of first thumb
\newlength\ct@top % current top
\setlength\ct@top{\paperheight}
\newcommand\my@thumb{}
\newcommand\thumb[1]{%
\def\my@thumb{\sffamily\normalsize\bfseries #1}%
\addtolength\ct@top{\cth}% old \cth
\settowidth\cth{\my@thumb}% new \cth
\addtolength\cth{20pt}% label margin
\ifdim \dimexpr\ct@top+\cth\relax > \dimexpr\paperheight-6\ctw\relax
\setlength\ct@top\cttopmargin
\fi
}
\newcommand\nothumbs{\def\my@thumb{}}
\nothumbs
\AtBeginShipout{%
\AtBeginShipoutUpperLeft{%
\ifodd\c@page
\setlength\ctx{\paperwidth}%
\setlength\ctf{+1\ctw}%
\else
\setlength\ctx{0in}%
\setlength\ctf{-1\ctw}%
\fi
\ifx\@empty\my@thumb\else
\begin{tikzpicture}[overlay,xshift=\ctx]
\tikzmath{%
\ct@top@ = \ct@top / -1cm;
\ct@ht = \cth / 1cm;
\ct@label = \ct@top@ - \ct@ht / 2;
}%
\fill[thumb] (0,\ct@top@) rectangle
++ (-2\ctf,-1\cth)
-- ++ (+1\ctf,-1\ctw)
-- ++ (+1\ctf,+1\ctw);
\draw[thumb,ultra thick,-o] (-1\ctf,\ct@top@)
-- (-1\ctf,-\paperheight+4\ctw)
-- ++ (-3\ctf,-3\ctw);
\draw[thumb,ultra thick,-o] (-2\ctf,\ct@top@)
-- (-2\ctf,-\paperheight+4.414\ctw)
-- ++ (-2\ctf,-2\ctw);
\node[white] at (-\ctf,\ct@label) {\rotatebox{90}{\my@thumb}};
\end{tikzpicture}%
\fi
}}
\makeatother
%
% user interface
%
\setlength\ctw{0.2in}% half width of thumb
\setlength\cttopmargin{20mm}% top margin of first thumb
\definecolor{thumb}{RGB}{0,173,239}% color of thumb
% set thumb with: \thumb{foobar}
% stop thumbs with: \nothumbs
\begin{document}
\chapter{No thumbs here}\lipsum[1-6]
\chapter{XXX 1}\thumb{Lorem ipsum}\lipsum[1-6]
\chapter{XXX 2}\thumb{Dolor}\lipsum[1-6]
\chapter{XXX 3}\thumb{Sit a met consectetuer}\lipsum[1-6]
\chapter{XXX 4}\thumb{Adipiscing elit}\lipsum[1-6]
\chapter{XXX 5}\thumb{Ut purus elit vestibulum ut}\lipsum[1-6]
\chapter{XXX 6}\thumb{Nunc eleifend consequat lorem}\lipsum[1-6]
\chapter{XXX 7}\thumb{Molestie vitae placerat}\lipsum[1-6]
\chapter{XXX 8}\thumb{Tortor gravida sapien}\lipsum[1-6]
\appendix
\chapter{AAA 1}\thumb{Phasellus eu tellu}\lipsum[1-6]
\chapter{AAA 2}\thumb{Praesent eget sem vel leo}\lipsum[1-6]
\chapter{Again no thumbs}\nothumbs\lipsum[1-6]
\end{document}