idea在目录中前添加目录_[LaTeX Beamer] 为目录项添加页码
本文已加入專(zhuān)欄文章目錄,歸入「進(jìn)階使用」文章系列。
本文介紹了為 beamer 文檔類(lèi)的目錄條目添加頁(yè)碼的方法,該方法可用于一般情況下的 beamer 目錄條目?jī)?nèi)容(不包含樣式的定制)修改需求。
beamer 的目錄,默認(rèn)不顯示各條目的頁(yè)碼。
下面我們嘗試把頁(yè)碼加上。
先搜一搜
- Beamer: tableofcontents with page numbers
- Latex beamer: slide numbers for subsubsections
第二個(gè)鏈接里的改法很簡(jiǎn)單,試一試。
makeatletter defbeamer@endinputifotherversion#1{} defbeamer@sectionintoc#1#2#3#4#5{{huge #2 hfill page #3 par}} defbeamer@subsectionintoc#1#2#3#4#5#6{{normalsize #3 hfill page #4 par}} defbeamer@subsubsectionintoc#1#2#3#4#5#6#7{{tiny #4 hfill page #5 par}} makeatother有效果,但是很粗糙。根據(jù)第二個(gè)鏈接里的說(shuō)法,信息在 toc 文件里都有。我們來(lái)看看 toc 文件,順便再看一看命令 beamer@sectionintoc 的定義。
$ cat beamer-test.toc #為了讓下方內(nèi)容正確高亮,此處加一個(gè) $ 符號(hào),下同 beamer@sectionintoc {1}{what}{2}{0}{1} beamer@subsectionintoc {1}{1}{why}{3}{0}{1} beamer@subsubsectionintoc {1}{1}{1}{blah}{4}{0}{1} beamer@sectionintoc {2}{what2}{5}{0}{2}$ latexdef -c beamer -s beamer@sectionintoc #$ % beamerbasetoc.sty, line 108: defbeamer@sectionintoc#1#2#3#4#5{%ifnumc@tocdepth>0%ifnum#4=beamer@showpartnumber%{beamer@saveanother%gdefbeamer@todo{}%beamer@slideinframe=#1relax%expandafteronlybeamer@tocsections{gdefbeamer@todo{%beamer@tempcount=#5relax%advancebeamer@tempcount bybeamer@sectionadjust%ifnumbeamer@tempcount>0edefinserttocsectionnumber{thebeamer@tempcount}%elsedefinserttocsectionnumber{}%fi%definserttocsection{hyperlink{Navigation#3}{#2}}%beamer@tocifnothide{ifnumc@section=#1beamer@toc@cselsebeamer@toc@osfi}%{%ifbeamer@pausesectionspausefi%ifxbeamer@toc@oossbeamer@hidetextvskip1.5emelsevfillfi{%hbox{vbox{%defbeamer@breakhere{}%beamer@tocact{ifnumc@section=#1beamer@toc@cselsebeamer@toc@osfi}{section in toc}}}%par%}%}%}%}%beamer@restoreanother%}beamer@todo%fifi% }仔細(xì)觀察,發(fā)現(xiàn)關(guān)鍵在 beamer@sectionintoc 定義的
definserttocsection{hyperlink{Navigation#3}{#2}}%這一行。原始定義很長(zhǎng),我們用 xpatch 的功能來(lái)完成重定義
% usepackage{xpatch}makeatletter xpatchcmd{beamer@sectionintoc}{hyperlink{Navigation#3}{#2}}{hyperlink{Navigation#3}{#2hfill#3}}{}{ddt}xpatchcmd{beamer@subsectionintoc}{hyperlink{Navigation#4}{#3}}{hyperlink{Navigation#4}{#3hfill#4}}{}{ddt}xpatchcmd{beamer@subsubsectionintoc}{hyperlink{Navigation#5}{#4}}{hyperlink{Navigation#5}{#4hfill#5}}{}{ddt} makeatother看看效果,事情就這么成了。
再回過(guò)去看第一個(gè)鏈接里的,修改 beamer@section 定義的做法,發(fā)現(xiàn)它的關(guān)鍵在這一處修改
longdefbeamer@section[#1]#2{% ... ... % before % addtocontents{toc}{protectbeamer@sectionintoc{thec@section}{#2}{thec@page}{thec@part}% % after addtocontents{toc}{protectbeamer@sectionintoc{thec@section}{#2hfillthec@page}{thec@page}{thec@part}% ... ... }這樣就能理解了,第一個(gè)鏈接里的做法是,使得往 toc 文件寫(xiě)入的是
beamer@sectionintoc {1}{whathfill2}{2}{0}{1}這樣,beamer@sectionintoc 接受的第二個(gè)參數(shù),就直接包含了需要輸出的所有內(nèi)容(whathfill2)。從定制 beamer 樣式的角度,這種改法更好。同樣使用 xpatch,對(duì)應(yīng)的修改是
makeatletter xpatchcmd{beamer@section}{{#2}{thec@page}}{{#2hfillthec@page}{thec@page}}{}{ddt}xpatchcmd{beamer@subsection}{{#2}{thec@page}}{{#2hfillthec@page}{thec@page}}{}{ddt}xpatchcmd{beamer@subsubsection}{{#2}{thec@page}}{{#2hfillthec@page}{thec@page}}{}{ddt} makeatother最后附上用于生成本文配圖的 LaTeX 源碼
documentclass{beamer} usepackage{xpatch}% 重定義 % ... ...begin{document} begin{frame}tableofcontents end{frame}section{what} begin{frame} content end{frame}subsection{why} begin{frame} content end{frame}subsubsection{blah} begin{frame} content end{frame}section{what2} begin{frame} content end{frame} end{document}總結(jié)
以上是生活随笔為你收集整理的idea在目录中前添加目录_[LaTeX Beamer] 为目录项添加页码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 训练好的神经网络 如何预测_显存不够,如
- 下一篇: codeblocks全屏模式怎么退出_I