加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

LaTeX技巧647:如何让章节与目录互相链接

(2012-11-29 10:51:45)
标签:

latex

超级链接

章节

目录

分类: 小技巧

QQ群:91940767/145316219/141877998/80300084/194770436
淘宝店:http://latexstudio.taobao.com
技巧续篇:http://latexstudio.net/
常见数学公式问题集下载

通常,我们用hyperref来做目录的超级链接,通过目录我们可以跳转到章节所在页,有用户提出能不能再从章节所在页跳转到目录处,于是有了下面这个问题:
搜索了下,已经有了解决方案,http://tex.stackexchange.com/questions/60830/make-chapter-titles-link-to-table-of-contents  思路比较简单,在chapter的地方加一个可以链接到目录的锚点命令即可了。
代码摘录如下:
\documentclass{report}
\usepackage[explicit]{titlesec}
\usepackage{hyperref}

\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}
  {\Huge\hyperlink{chap\thechapter}{#1}}
\titleformat{name=\chapter,numberless}[display]
  {\normalfont\huge\bfseries}{}{-22pt}
  {\Huge#1}

\makeatletter
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
  \refstepcounter{chapter}%
  \typeout{\@chapapp\space\thechapter.}%
  \addcontentsline{toc}{chapter}%
    {\protect\numberline{\thechapter}\string\hypertarget{chap\thechapter}{#1}}%
\else
  \addcontentsline{toc}{chapter}{#1}%
\fi
\chaptermark{#1}%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
\if@twocolumn
  \@topnewpage[\@makechapterhead{#2}]%
\else
  \@makechapterhead{#2}%
  \@afterheading
\fi}
\makeatother

\begin{document}

\tableofcontents
\chapter{Test Chapter One}
\chapter{Test Chapter Two}
\chapter{Test Chapter Three}

\end{document}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有