编辑:我已经编辑了重现异常的代码,但我将在当天晚些时候对代码进行处理以更准确地描述问题。
- 索引中的奇怪间距
- 索引未出现在脚注链接中/未被识别为部分
该代码无法在此页面上正确显示(不知何故 4 个空格不起作用),因此我将其粘贴这里。
我正在尝试创建一个宏来保存姓名上一节和下一节的自动更新,这样我就可以在页脚中重复使用它(带有链接,但这可以通过\hyperlink{page.\getpagerefnumber{<anchor>}}
锚点轻松完成)。
请参阅带有不同附录超链接的 rfoot。
梅威瑟:
\documentclass{article}
\usepackage{marginnote}
\usepackage{pbox}
\usepackage[heightrounded]{geometry}
\usepackage{lastpage}
\usepackage[toc,titletoc,page]{appendix}
% Set some commands that I'll use for all footers
\usepackage{fancyhdr}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{.4pt}
% Command for pageref for page/LastPage in footer
\cfoot{\thepage /\pageref{LastPage}\hyperlink{page.\getpagerefnumber{anchor.lastpage}}{ $\rightarrow$}}
% Global pagestyle commands
\fancypagestyle{contents}{
\lfoot{\textbf{Inhoudsopgave}}
}
\fancypagestyle{document}{
\rfoot{\hyperlink{document.toc}{$\leftarrow$ Naar inhoudsopgave}}
\lfoot{\currentsection}
}
% By declaring the plain pagestyle explicitly, the first page is forced in terms of header and footer settings
% Not declaring this page style will not apply fancyhdr settings to the first page
\fancypagestyle{plain}{
\lhead{}
\chead{}
\rhead{}
\lfoot{\textbf{Inhoudsopgave}}
\cfoot{\thepage /\pageref{LastPage}\hyperlink{page.\getpagerefnumber{anchor.lastpage}}{ $\rightarrow$}}
\rfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.4pt}
}
% header dummies which will be used in appendices - Auto-adjustment for variable page print of appendices
% It's also possible to use \getpagerefnumber and link thereto, but that gets you to the top of the page rather than the top of the appendix
% It's a small difference, but this yields a (slightly) prettier result
\fancypagestyle{a.appendix.headerref}{
\rfoot{\pbox{5cm}{\hyperlink{document.toc}{$\leftarrow$ Naar inhoudsopgave} \\ \hyperlink{appendix.b}{Naar begrippenlijst $\rightarrow$} \\ \hyperlink{appendix.c}{Naar Index $\rightarrow$ }}}%
\lfoot{\currentsection}
\fancyhead[C]{\hypertarget{appendix.a}{}}
}
\fancypagestyle{b.appendix.headerref}{
\rfoot{\pbox{5cm}{\hyperlink{document.toc}{$\leftarrow$ Naar inhoudsopgave} \\ \hyperlink{appendix.a}{$\leftarrow$ Naar \textbf{\textcolor{blue}{R}} commando's} \\ \hyperlink{appendix.c}{Naar Index $\rightarrow$ }}}%
\fancyhead[C]{\hypertarget{appendix.b}{}}
}
\fancypagestyle{c.appendix.headerref}{
\rfoot{\pbox{5cm}{\hyperlink{document.toc}{$\leftarrow$ Naar inhoudsopgave} \\ \hyperlink{appendix.b}{$\leftarrow$ Naar begrippenlijst} \\ \hyperlink{appendix.d}{Naar Nesting $\rightarrow$ }}}%
\fancyhead[C]{\hypertarget{appendix.c}{}}
}
\fancypagestyle{d.appendix.headerref}{
\rfoot{\pbox{5cm}{\hyperlink{document.toc}{$\leftarrow$ Naar inhoudsopgave} \\ \hyperlink{appendix.b}{$\leftarrow$ Naar begrippenlijst } \\ \hyperlink{appendix.c}{$\leftarrow$ Naar Index }}}%
\fancyhead[C]{\hypertarget{appendix.d}{}}
}
\fancypagestyle{a.appendix.sep}{
\rfoot{\pbox{5cm}{\hyperlink{document.toc}{$\leftarrow$ Naar inhoudsopgave} \\ \hyperlink{appendix.b}{Naar begrippenlijst $\rightarrow$} \\ \hyperlink{appendix.c}{Naar Index $\rightarrow$ }}}%
\lfoot{\currentsection}
\fancyhead[C]{} % Reset the header from headerref construction
}
\fancypagestyle{b.appendix.sep}{
\rfoot{\pbox{5cm}{\hyperlink{document.toc}{$\leftarrow$ Naar inhoudsopgave} \\ \hyperlink{appendix.a}{$\leftarrow$ Naar \textbf{\textcolor{blue}{R}} commando's} \\ \hyperlink{appendix.c}{Naar Index $\rightarrow$ }}}%
\lfoot{\currentsection}
\fancyhead[C]{}
}
\fancypagestyle{c.appendix.sep}{
\rfoot{\pbox{5cm}{\hyperlink{document.toc}{$\leftarrow$ Naar inhoudsopgave} \\ \hyperlink{appendix.b}{$\leftarrow$ Naar begrippenlijst} \\ \hyperlink{appendix.d}{Naar Nesting $\rightarrow$ }}}%
\lfoot{\currentsection}
\fancyhead[C]{}
}
\fancypagestyle{d.appendix.sep}{
\rfoot{\pbox{5cm}{\hyperlink{document.toc}{$\leftarrow$ Naar inhoudsopgave} \\ \hyperlink{appendix.b}{$\leftarrow$ Naar begrippenlijst } \\ \hyperlink{appendix.c}{$\leftarrow$ Naar Index }}}%
\lfoot{\currentsection}
\fancyhead[C]{}
}
% Cross-references
\usepackage[pageanchor]{hyperref}
\hypersetup{colorlinks=true,
linkcolor=red,
hypertexnames=false,
pdfhighlight=/N,
pdfstartview={XYZ null null 1.00}
}
\title{}
\author{}
\date{}
\begin{document}
\pagestyle{contents}
\hypertarget{document.toc}{}
\maketitle
\tableofcontents
% Footer section name - Declare after ToC to keep section numbering intact
\newcommand{\currentsection}{}
\let\oldsection\section
\renewcommand{\section}[1]{\oldsection{#1}\renewcommand{\currentsection}{#1}}
\newpage
\pagestyle{document}
\section{Week 1 - Intro \textcolor{blue}{\textbf{R}}}
\subsection{Objecten}
\subsubsection{Objecten met \'e\'en getal}
\newpage
% Clearpage to move floats as well, use newpage if you don't have floats on the last page
\clearpage
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
\begin{appendices}
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
% I am using hypertargets from the preamble to make sure hyperref takes you to the top of the page and not the middle of it
% I've already explained why I picked this solution over \getpagerefnumber
\pagestyle{a.appendix.headerref}
\section{\textbf{\textcolor{blue}{R} commando's}}
text
\newpage
\section{\textbf{Begrippenlijst}}
\pagestyle{b.appendix.headerref}
\newpage
\pagestyle{c.appendix.headerref}
\section{\textbf{Index}}
text
\newpage
\section{\textbf{Nesting}}
text
\end{appendices}
% Because the footer is printed last and there is a space between the appendices environment and the end of the document, we have to force this value or define set a manual environment. Setting a new environment would be the more tedious solution
\rfoot{\pbox{5cm}{\hyperlink{document.toc}{$\leftarrow$ Naar inhoudsopgave} \\ \hyperlink{appendix.b}{$\leftarrow$ Naar begrippenlijst } \\ \hyperlink{appendix.c}{$\leftarrow$ Naar Index }}}%
\lfoot{\textbf{Nesting}} % This will have to be set manually to circumvent cross-environment anomalies with fancyhdr
\lhead{}
\fancyhead[C]{\hypertarget{appendix.d}{}}
% Anchor on last page
\label{anchor.lastpage}
\end{document}
答案1
改良版
我做了一些修改,重新定义了\section
命令,并引入了将上一节和下一节标题名称作为超链接引用的可能性。标题会自动插入。
\documentclass[paper=a4,12pt,onesided]{scrartcl}
\usepackage{blindtext}
\usepackage{everypage}
\usepackage{lastpage}%
\usepackage{xcolor}%
\usepackage{imakeidx}%
\usepackage[heightrounded]{geometry}%
\usepackage[toc,titletoc,page]{appendix}%
\usepackage{etoolbox}
\usepackage{bbding}
\usepackage[pageanchor]{hyperref}%
\newrobustcmd{\ProvideBool}[2][false]{%
\newbool{#2}%
\setbool{#2}{#1}%
}%
\ProvideBool[true]{DocumentSectionAutoClearpage}%
\newrobustcmd{\EnableSectionAutoClearpage}{%
\setbool{DocumentSectionAutoClearpage}{true}%
}%
\newrobustcmd{\DisableSectionAutoClearpage}{%
\setbool{DocumentSectionAutoClearpage}{false}%
}%
\definecolor{DocumentHyperLinkColor}{RGB}{255,0,0}%
\hypersetup{colorlinks=true,
linkcolor=DocumentHyperLinkColor,
hypertexnames=false,
pdfhighlight=/N,
pdfstartview={XYZ null null 1.00}
}
\AtBeginDocument{%
\setcounter{PrintIndexSectionCounter}{\number\value{IndexSectionCounterValue}}
\EnableSectionAutoClearpage%
}%
\makeatletter
\let\LaTeXStandardSection\section
% Providing section command with no optional argument
\newrobustcmd{\improvedstarredsection}[1]{%
% No name reference to unnumbered sections
%\BeforeSectionStarts{#1}%
\LaTeXStandardSection*{#1}%
}%
\newrobustcmd{\improvedsection@noopt}[1]{%
\BeforeSectionStarts{#1}%
\LaTeXStandardSection{#1}%
}%
% Providing section command with an optional argument
\newrobustcmd{\improvedsection@opt}[2][]{%
\BeforeSectionStarts{#1}%
\LaTeXStandardSection[#1]{#2}%
}%
% "True" section command
\newrobustcmd{\improvedsection}{%
\ifboolexpr{bool{DocumentSectionAutoClearpage}}{\clearpage}{}
\@ifnextchar[{\improvedsection@opt}{\improvedsection@noopt}
}%
%%%%%% Use the 'improved' section commands with forward/backward links
\renewcommand{\section}{%
\@ifstar{\improvedstarredsection}{\improvedsection}%
}
\makeatother
\makeatletter
\renewenvironment{theindex}{%
\if@twocolumn
\@restonecolfalse
\else
\@restonecoltrue
\fi
\phantomsection%
\section{\indexname}%
\setcounter{PrintIndexSectionCounter}{\number\value{CurrentSectionCounter}}%
\@mkboth{\MakeUppercase\indexname}%
{\MakeUppercase\indexname}%
\parindent\z@
% \thispagestyle{plain}\parindent\z@
\parskip\z@ \@plus .3\p@\relax
\columnseprule \z@
\columnsep 35\p@
\let\item\@idxitem}
{\if@restonecol\onecolumn\else\clearpage\fi}%
\makeatother
\makeatletter
\newrobustcmd{\LastSectionInFile}{%
\immediate\write\@auxout{\string
\setcounter{LastSectionValue}{\number\value{CurrentSectionCounter}}%
}%
}
\newrobustcmd{\IndexSectionInFile}{%
\immediate\write\@auxout{\string
\setcounter{IndexSectionCounterValue}{\number\value{PrintIndexSectionCounter}}%
}%
}%
\makeatother
\AtEndDocument{%
\LastSectionInFile%
\IndexSectionInFile%
}%
\newrobustcmd{\PreviousSectionName}{\refcommand{CurrentSection::Title::\number\value{PreviousSectionCounter}}}%
\newrobustcmd{\CurrentSectionName}{\refcommand{CurrentSection::Title::\number\value{CurrentSectionCounter}}}%
\newrobustcmd{\NextSectionName}{\refcommand{CurrentSection::Title::\number\value{NextSectionCounter}}}%
\newrobustcmd{\NextSectionHyperLinkFormat}[1]{#1}%
\newrobustcmd{\PreviousSectionHyperLinkFormat}[1]{#1}%
\newrobustcmd{\GenerateNextSectionHyperlink}[3]{%
\DoIfNumInequal{\number\value{#1}}{\number\value{#3}}{%
\DoIfNumNotZero{\number\value{PrintIndexSectionCounter}}{%
% Only set a link of the next section is not the index section%
\ifnumequal{\number\value{#1}+1}{\number\value{PrintIndexSectionCounter}}{%
\setcounter{InternalTitleCounter}{\number\value{#2}}%
\addtocounter{InternalTitleCounter}{1}%
\hyperlink{CurrentSection::\number\value{InternalTitleCounter}}{\NextSectionHyperLinkFormat{\refcommand{CurrentSection::Title::\number\value{InternalTitleCounter}}}}%
}{
\hyperlink{CurrentSection::\number\value{#2}}{\NextSectionHyperLinkFormat{\refcommand{CurrentSection::Title::\number\value{#2}}}}%
}}%
{%
\hyperlink{CurrentSection::\number\value{#2}}{\NextSectionHyperLinkFormat{\refcommand{CurrentSection::Title::\number\value{#2}}}}%
}%
}% End of inner \DoIfNumInEqual
}%
\newrobustcmd{\GeneratePreviousSectionHyperlink}[3]{%
\DoIfNumInequal{\number\value{#1}}{1}{%
\DoIfNumNotZero{\number\value{PrintIndexSectionCounter}}{%
\ifnumequal{\number\value{#1}-1}{\number\value{PrintIndexSectionCounter}}{%
\setcounter{InternalTitleCounter}{\number\value{#2}}%
\addtocounter{InternalTitleCounter}{-1}%
\hyperlink{CurrentSection::\number\value{InternalTitleCounter}}{\PreviousSectionHyperLinkFormat{\refcommand{CurrentSection::Title::\number\value{InternalTitleCounter}}}}%
}{
% \DoIfNumInequal{\number\value{#1}-1}{\number\value{PrintIndexSectionCounter}}{%
\hyperlink{CurrentSection::\number\value{#2}}{\PreviousSectionHyperLinkFormat{\refcommand{CurrentSection::Title::\number\value{#2}}}}%
}%
}{%
% Insert link in any case, since there is no bottom `Index` link
\hyperlink{CurrentSection::\number\value{#2}}{\PreviousSectionHyperLinkFormat{\refcommand{CurrentSection::Title::\number\value{#2}}}}%
}%
}% End of outer \DoIfNumInequal
}% End of command
\newrobustcmd{\GenerateArrowHyperlinkToNextSection}[3]{%
\DoIfNumInequal{\number\value{#1}}{\number\value{#3}}{%
\DoIfNumNotZero{\number\value{PrintIndexSectionCounter}}{%
\ifnumequal{\number\value{#1}+1}{\number\value{PrintIndexSectionCounter}}{%
\setcounter{InternalTitleCounter}{\number\value{#2}}%
\addtocounter{InternalTitleCounter}{1}% Look ahead
\hyperlink{CurrentSection::\number\value{InternalTitleCounter}}{\ToNextSectionSymbol}%
}{%
\hyperlink{CurrentSection::\number\value{#2}}{\ToNextSectionSymbol}%
}%%
}{%
\hyperlink{CurrentSection::\number\value{#2}}{\ToNextSectionSymbol}%
}%
}% End of outer \DoIfNumInEqual
}%
\newrobustcmd{\GenerateArrowHyperlinkToPreviousSection}[3]{%
\DoIfNumInequal{\number\value{#1}}{1}{%
% But do nothing if the section number is equal to the total section counter value
\DoIfNumNotZero{\number\value{#1}}{%
\ifnumequal{\number\value{#1}-1}{\number\value{PrintIndexSectionCounter}}{%
\setcounter{InternalTitleCounter}{\number\value{#1}}%
\addtocounter{InternalTitleCounter}{-2}% Look ahead
\hyperlink{CurrentSection::\number\value{InternalTitleCounter}}{\ToPreviousSectionSymbol}%
}{%
\hyperlink{CurrentSection::\number\value{#2}}{\ToPreviousSectionSymbol}%
}%
}{%
\hyperlink{CurrentSection::\number\value{#2}}{\ToPreviousSectionSymbol}%
}%
}% End of outer \DoIfNumInequal
}% End of command
\renewcommand{\indexname}{Index}
\renewcommand{\contentsname}{Inhoudsopgave}
\newcommand{\LinkToContentsName}{\contentsname}
\newcommand{\LinkToIndexName}{Index}
\newrobustcmd{\DoIfNumNotZero}[3]{%
\ifnumequal{#1}{0}{#3}{#2}%
}%
\newrobustcmd{\DoIfNumInequal}[3]{%
\ifnumequal{#1}{#2}{}{#3}%
}%
\newrobustcmd{\IfNumInequal}[4]{%
\ifnumequal{#1}{#2}{#3}{#4}%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%Additional counters%%%%
\newcounter{LastDocumentPageCounter}%
\setcounter{LastDocumentPageCounter}{1}
\newcounter{IndexSectionCounterValue}%
\newcounter{PrintIndexSectionCounter}%
\newcounter{PreviousSectionCounter}% No resetting%%%
\setcounter{PreviousSectionCounter}{0}%
\newcounter{NextSectionCounter}% No resetting%%%
\setcounter{NextSectionCounter}{0}
\newcounter{CurrentSectionCounter}% No resetting%%%
\setcounter{CurrentSectionCounter}{0}
\newcounter{LastSectionValue}
\newcounter{InternalTitleCounter}
\newrobustcmd{\refcommand}[1]{%
\nameref*{#1}%
}%
\newrobustcmd{\CurrentSectionSymbol}{\textbf{\textcolor{blue}{\HandRight}}~}
\newrobustcmd{\ToNextSectionSymbol}{\textbf{\textcolor{DocumentHyperLinkColor}{\HandRight}}~}
\newrobustcmd{\ToPreviousSectionSymbol}{\textbf{\textcolor{DocumentHyperLinkColor}{\HandLeft}}~}
\makeatletter
\newrobustcmd{\WriteUniqueTextLabelContent}[2]{%
\immediate\write\@auxout{%
\string\newlabel{#1}{{\thesection}{\thepage}{\unexpanded{#2}}{}}%
}%
}%
\newrobustcmd{\BeforeSectionStarts}[1]{%
\stepcounter{CurrentSectionCounter}%
%%%%% Check first whether there is already a previous section
\ifnumequal{\number\value{CurrentSectionCounter}}{1}{% Yes, section number is zero
\setcounter{PreviousSectionCounter}{1}%
}{%
\setcounter{PreviousSectionCounter}{\number\value{CurrentSectionCounter}}
\addtocounter{PreviousSectionCounter}{-1}
}
% CurrentSectionCounter > 1
% Set Target to current section
\phantomsection
\hypertarget{CurrentSection::\number\value{CurrentSectionCounter}}{}%
\WriteUniqueTextLabelContent{CurrentSection::Title::\number\value{CurrentSectionCounter}}{#1}%
% Set correct numbers
\setcounter{NextSectionCounter}{\number\value{CurrentSectionCounter}}
\ifnumequal{\number\value{CurrentSectionCounter}}{\number\value{LastSectionValue}}{}{%
\addtocounter{NextSectionCounter}{1}%
}%
\phantomsection
}%
\newrobustcmd{\InsertToIndexSymbol}[4]{%
% #1: Number of IndexSection
% #2: Number of CurrentSection
% #3: Text for link to previous section (normally left hand?)
% #4: Text for link to next section (normally right hand?)
\ifnumequal{\number\value{#1}}{0}{%
% Do nothing, since there is no Index section (value of #1)!
}{%
\ifnumless{\number\value{#1}}{\number\value{#2}}{%
\hyperlink{CurrentSection::\number\value{#1}}{#3}%
}{% Not lesser, check greater then....
\ifnumgreater{\number\value{#1}}{\number\value{#2}}{%
\hyperlink{CurrentSection::\number\value{#1}}{#4}%
}{%
% Do nothing, since both counters are equal!!!!
}%
}% End of \ifnumless is not true, i.e. other branch >= value of #2
}%
}%
\makeatother
\usepackage{fancyhdr}
\fancyhf{}%
\renewcommand{\headrulewidth}{0pt}%
\renewcommand{\footrulewidth}{.4pt}%
\fancypagestyle{contents}{%
\lfoot{\begin{tabular}{l}%
\CurrentSectionSymbol\textbf{\contentsname} \tabularnewline
\tabularnewline%
\tabularnewline%
\tabularnewline%
\end{tabular}
}%
\cfoot{}%
\rfoot{}%
}
\fancypagestyle{normalpages}{%
\lfoot{\begin{tabular}{l}%
\CurrentSectionSymbol\textbf{\contentsname} \tabularnewline
\tabularnewline%
\tabularnewline%
\tabularnewline%
\end{tabular}
}%
\cfoot{}%
\rfoot{}%
}
\fancypagestyle{FootLinks}{%
\lfoot{\begin{tabular}{l}%
\CurrentSectionSymbol\CurrentSectionName \tabularnewline
\tabularnewline%
\tabularnewline%
\tabularnewline%
\end{tabular}
}%
\cfoot{\begin{tabular}{c}%
\thepage /\pageref{LastPage}\hyperlink{page.\getpagerefnumber{anchor.lastpage}}{~\ToNextSectionSymbol} \tabularnewline
\tabularnewline%
\tabularnewline%
\tabularnewline%
\end{tabular}
}%
\rfoot{\begin{tabular}{@{}rl}
\hyperlink{document.toc}{\ToPreviousSectionSymbol} & \hyperlink{document.toc}{\LinkToContentsName} \tabularnewline %
\GenerateArrowHyperlinkToPreviousSection{CurrentSectionCounter}{NextSectionCounter}{1} & \GeneratePreviousSectionHyperlink{CurrentSectionCounter}{PreviousSectionCounter}{1} \tabularnewline%
\GenerateArrowHyperlinkToNextSection{CurrentSectionCounter}{NextSectionCounter}{LastSectionValue} & \GenerateNextSectionHyperlink{CurrentSectionCounter}{NextSectionCounter}{LastSectionValue} \tabularnewline%
% \DoIfIndexSection{PrintIndexSectionCounter}{CurrentSectionCounter}{\ToPreviousSectionSymbol}{\ToNextSectionSymbol} &
\InsertToIndexSymbol{PrintIndexSectionCounter}{CurrentSectionCounter}{\ToPreviousSectionSymbol}{\ToNextSectionSymbol} &
\hyperlink{CurrentSection::\number\value{PrintIndexSectionCounter}}{\InsertToIndexSymbol{PrintIndexSectionCounter}{CurrentSectionCounter}{\refcommand{CurrentSection::Title::\number\value{PrintIndexSectionCounter}}}{\refcommand{CurrentSection::Title::\number\value{PrintIndexSectionCounter}}}} \tabularnewline%
\end{tabular}%
}%
\fancyhead[C]{} % Reset the header from headerref construction
}%
\makeindex
\begin{document}
\phantomsection
\hypertarget{document.toc}{}%
\pagestyle{contents}
\tableofcontents
\clearpage
\pagestyle{normalpages}
\section{First Section}
\blindtext[2]
\index{Schr\"odinger}
\section{Another section}
\blindtext[3]
\section[Short Section Title]{Another section with a not so short title}
\section{The three witches}
\index{Shakespeare}
\index{Macbeth}
\clearpage %
\clearpage
\begin{appendices}
\clearpage
\pagestyle{FootLinks}
%\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\section{\textbf{\textcolor{blue}{R} commando's}}
\blindtext%
\section*{And I am a completely unnumbered section and do not appear in the foot links ;-)}
\section{Begrippenlijst}
\blindtext%
\printindex% Note: \printindex behavious like an extra section
\section{\textbf{$E = mc^2$}}
\blindtext%
\section{Dummy 1}
\section{Dummy 2}
\blindtext%
\clearpage
\end{appendices}
\end{document}
评论将很快添加!
特征:
如果索引部分的标准链接仅位于前一节或前一节,则省略指向下一节和上一节的脚注链接。然后,链接指向前一节 +- 2 节
\printindex
现在表现得像一个部分条目,带有目录项- 如果没有
\printindex
,则不插入底部索引链接。.aux
在这种情况下,请手动删除文件!