我真的很难使用自定义目录titletoc
:错误链接hyperref
由于错误而导致的软件包(这个已经被贝索斯注意到了,的创建者titletoc
)。
给出以下简单的代码:
\documentclass{book}
\usepackage{lipsum}
\usepackage{titletoc}
\usepackage{hyperref}
\titlecontents{chapter}%
[0em]% left
{\bigskip}% above
{\bf\large\contentslabel[\thecontentslabel.]{2em}\hspace{0em}}%
{\hspace*{-2em}}%
{\hfill\bf\contentspage}%
[\smallskip]%
%
\titlecontents{section}%
[1.5em]%
{\small\contentsmargin{1.5em}}%
{\bf\thecontentslabel\hspace{7pt}}%
{\hspace*{-2em}}%
{\enspace\titlerule*[0.5pc]{.}~\contentspage}%
%
\titlecontents*{subsection}%
[3em]%
{\footnotesize\contentsmargin{0em}}%
{\thecontentslabel\space}%
{}%
{}%
[ -- ]%
\begin{document}
\tableofcontents
\chapter{Title}
\lipsum
\section{Title}
\subsection{Title}
\subsection{Title}
\subsection{Title}
\lipsum
\subsection{Title}
\subsection{Title}
\lipsum
\chapter{Title}
\chapter{Title}
\end{document}
人们会突然注意到(见下图)“第 2 章”的超链接指向“第 1.1 小节”,这真的很烦人。
我在 tex.SE 上搜索了很久,但同样的问题的解决方案却无法治愈病理这个布局我需要保留它。我也感到惊讶,因为带星号的版本中唯一的区别似乎是段落数的间距
\newcommand\titlecontents{%
\@ifstar{\ttl@contents{\z@}}% \z@ = zero paragraph?
{\ttl@contents{\@ne}}}% \@ne = zero paragraph?
但我无法继续下去,因为嵌套函数得到定义,代码无法访问。最后我注意到问题只是由子节之后的第一个章节给出的(它不会发生在子节之间、子节和节之间、节和章节之间、章节和章节之间,那么如果可以添加一个真实的 \phantomsection
,也就是说它不会显示在目录中。
编辑:Log_FILE
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=pdflatex 2019.12.14) 14 DEC 2019 16:42 entering extended mode \write18 enabled. file:line:error style messages enabled. %&-line parsing enabled. **Untitled.tex (./Untitled.tex LaTeX2e <2018-12-01> (/usr/local/texlive/2019/texmf-dist/tex/latex/base/book.cls Document Class: book 2018/09/03 v1.4i Standard LaTeX document class (/usr/local/texlive/2019/texmf-dist/tex/latex/base/bk10.clo File: bk10.clo 2018/09/03 v1.4i Standard LaTeX file (size option) ) \c@part=\count80 \c@chapter=\count81 \c@section=\count82 \c@subsection=\count83 \c@subsubsection=\count84 \c@paragraph=\count85 \c@subparagraph=\count86 \c@figure=\count87 \c@table=\count88 \abovecaptionskip=\skip41 \belowcaptionskip=\skip42 \bibindent=\dimen102 ) (/usr/local/texlive/2019/texmf-dist/tex/latex/lipsum/lipsum.sty (/usr/local/texlive/2019/texmf-dist/tex/latex/l3kernel/expl3.sty Package: expl3 2019-05-07 L3 programming layer (loader) (/usr/local/texlive/2019/texmf-dist/tex/latex/l3kernel/expl3-code.tex Package: expl3 2019-05-07 L3 programming layer (code) \c_max_int=\count89 \l_tmpa_int=\count90 \l_tmpb_int=\count91 \g_tmpa_int=\count92 \g_tmpb_int=\count93 \g__kernel_prg_map_int=\count94 \c__ior_term_ior=\count95 \c_log_iow=\count96 \l_iow_line_count_int=\count97 \l__iow_line_target_int=\count98 \l__iow_one_indent_int=\count99 \l__iow_indent_int=\count100 \c_zero_dim=\dimen103 \c_max_dim=\dimen104 \l_tmpa_dim=\dimen105 \l_tmpb_dim=\dimen106 \g_tmpa_dim=\dimen107 \g_tmpb_dim=\dimen108 \c_zero_skip=\skip43 \c_max_skip=\skip44 \l_tmpa_skip=\skip45 \l_tmpb_skip=\skip46 \g_tmpa_skip=\skip47 \g_tmpb_skip=\skip48 \c_zero_muskip=\muskip10 \c_max_muskip=\muskip11 \l_tmpa_muskip=\muskip12 \l_tmpb_muskip=\muskip13 \g_tmpa_muskip=\muskip14 \g_tmpb_muskip=\muskip15 \l_keys_choice_int=\count101 \l__intarray_loop_int=\count102 \c__intarray_sp_dim=\dimen109 \g__intarray_font_int=\count103 \c__fp_leading_shift_int=\count104 \c__fp_middle_shift_int=\count105 \c__fp_trailing_shift_int=\count106 \c__fp_big_leading_shift_int=\count107 \c__fp_big_middle_shift_int=\count108 \c__fp_big_trailing_shift_int=\count109 \c__fp_Bigg_leading_shift_int=\count110 \c__fp_Bigg_middle_shift_int=\count111 \c__fp_Bigg_trailing_shift_int=\count112 \c__kernel_randint_max_int=\count113 \g__fp_array_int=\count114 \l__fp_array_loop_int=\count115 \l__sort_length_int=\count116 \l__sort_min_int=\count117 \l__sort_top_int=\count118 \l__sort_max_int=\count119 \l__sort_true_max_int=\count120 \l__sort_block_int=\count121 \l__sort_begin_int=\count122 \l__sort_end_int=\count123 \l__sort_A_int=\count124 \l__sort_B_int=\count125 \l__sort_C_int=\count126 \l__tl_analysis_normal_int=\count127 \l__tl_analysis_index_int=\count128 \l__tl_analysis_nesting_int=\count129 \l__tl_analysis_type_int=\count130 \l__regex_internal_a_int=\count131 \l__regex_internal_b_int=\count132 \l__regex_internal_c_int=\count133 \l__regex_balance_int=\count134 \l__regex_group_level_int=\count135 \l__regex_mode_int=\count136 \c__regex_cs_in_class_mode_int=\count137 \c__regex_cs_mode_int=\count138 \l__regex_catcodes_int=\count139 \l__regex_default_catcodes_int=\count140 \c__regex_catcode_D_int=\count141 \c__regex_catcode_S_int=\count142 \c__regex_catcode_L_int=\count143 \c__regex_catcode_O_int=\count144 \c__regex_catcode_A_int=\count145 \c__regex_all_catcodes_int=\count146 \l__regex_show_lines_int=\count147 \l__regex_min_state_int=\count148 \l__regex_max_state_int=\count149 \l__regex_left_state_int=\count150 \l__regex_right_state_int=\count151 \l__regex_capturing_group_int=\count152 \l__regex_min_pos_int=\count153 \l__regex_max_pos_int=\count154 \l__regex_curr_pos_int=\count155 \l__regex_start_pos_int=\count156 \l__regex_success_pos_int=\count157 \l__regex_curr_char_int=\count158 \l__regex_curr_catcode_int=\count159 \l__regex_last_char_int=\count160 \l__regex_case_changed_char_int=\count161 \l__regex_curr_state_int=\count162 \l__regex_step_int=\count163 \l__regex_min_active_int=\count164 \l__regex_max_active_int=\count165 \l__regex_replacement_csnames_int=\count166 \l__regex_match_count_int=\count167 \l__regex_min_submatch_int=\count168 \l__regex_submatch_int=\count169 \l__regex_zeroth_submatch_int=\count170 \g__regex_trace_regex_int=\count171 \c_empty_box=\box27 \l_tmpa_box=\box28 \l_tmpb_box=\box29 \g_tmpa_box=\box30 \g_tmpb_box=\box31 \l__box_top_dim=\dimen110 \l__box_bottom_dim=\dimen111 \l__box_left_dim=\dimen112 \l__box_right_dim=\dimen113 \l__box_top_new_dim=\dimen114 \l__box_bottom_new_dim=\dimen115 \l__box_left_new_dim=\dimen116 \l__box_right_new_dim=\dimen117 \l__box_internal_box=\box32 \l__coffin_internal_box=\box33 \l__coffin_internal_dim=\dimen118 \l__coffin_offset_x_dim=\dimen119 \l__coffin_offset_y_dim=\dimen120 \l__coffin_x_dim=\dimen121 \l__coffin_y_dim=\dimen122 \l__coffin_x_prime_dim=\dimen123 \l__coffin_y_prime_dim=\dimen124 \c_empty_coffin=\box34 \l__coffin_aligned_coffin=\box35 \l__coffin_aligned_internal_coffin=\box36 \l_tmpa_coffin=\box37 \l_tmpb_coffin=\box38 \g_tmpa_coffin=\box39 \g_tmpb_coffin=\box40 \l__coffin_bounding_shift_dim=\dimen125 \l__coffin_left_corner_dim=\dimen126 \l__coffin_right_corner_dim=\dimen127 \l__coffin_bottom_corner_dim=\dimen128 \l__coffin_top_corner_dim=\dimen129 \l__coffin_scaled_total_height_dim=\dimen130 \l__coffin_scaled_width_dim=\dimen131 \c__coffin_empty_coffin=\box41 \l__coffin_display_coffin=\box42 \l__coffin_display_coord_coffin=\box43 \l__coffin_display_pole_coffin=\box44 \l__coffin_display_offset_dim=\dimen132 \l__coffin_display_x_dim=\dimen133 \l__coffin_display_y_dim=\dimen134 \g__file_internal_ior=\read1 \l__seq_internal_a_int=\count172 \l__seq_internal_b_int=\count173 \c__deprecation_minus_one=\count174 ) (/usr/local/texlive/2019/texmf-dist/tex/latex/l3kernel/l3pdfmode.def File: l3pdfmode.def 2019-04-06 v L3 Experimental driver: PDF mode \l__driver_color_stack_int=\count175 \l__driver_pdf_tmp_box=\box45 )) (/usr/local/texlive/2019/texmf-dist/tex/latex/l3packages/xparse/xparse.sty Package: xparse 2019-05-03 L3 Experimental document command parser \l__xparse_current_arg_int=\count176 \g__xparse_grabber_int=\count177 \l__xparse_m_args_int=\count178 \l__xparse_v_nesting_int=\count179 ) Package: lipsum 2019/01/02 v2.2 150 paragraphs of Lorem Ipsum dummy text (/usr/local/texlive/2019/texmf-dist/tex/latex/lipsum/lipsum.ltd.tex File: lipsum.ltd.tex 2019/01/02 v2.2 The Lorem ipsum dummy text )) (/usr/local/texlive/2019/texmf-dist/tex/latex/titlesec/titletoc.sty Package: titletoc 2011/12/15 v1.6 TOC entries \ttl@leftsep=\dimen135 ) (/usr/local/texlive/2019/texmf-dist/tex/latex/hyperref/hyperref.sty Package: hyperref 2018/11/30 v6.88e Hypertext links for LaTeX (/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty Package: hobsub-hyperref 2016/05/16 v1.14 Bundle oberdiek, subset hyperref (HO) (/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty Package: hobsub-generic 2016/05/16 v1.14 Bundle oberdiek, subset generic (HO) Package: hobsub 2016/05/16 v1.14 Construct package bundles (HO) Package: infwarerr 2016/05/16 v1.4 Providing info/warning/error messages (HO) Package: ltxcmds 2016/05/16 v1.23 LaTeX kernel commands for general use (HO) Package: ifluatex 2016/05/16 v1.4 Provides the ifluatex switch (HO) Package ifluatex Info: LuaTeX not detected. Package: ifvtex 2016/05/16 v1.6 Detect VTeX and its facilities (HO) Package ifvtex Info: VTeX not detected. Package: intcalc 2016/05/16 v1.2 Expandable calculations with integers (HO) Package: ifpdf 2018/09/07 v3.3 Provides the ifpdf switch Package: etexcmds 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO) Package: kvsetkeys 2016/05/16 v1.17 Key value parser (HO) Package: kvdefinekeys 2016/05/16 v1.4 Define keys (HO) Package: pdftexcmds 2018/09/10 v0.29 Utility functions of pdfTeX for LuaTeX (HO ) Package pdftexcmds Info: LuaTeX not detected. Package pdftexcmds Info: \pdf@primitive is available. Package pdftexcmds Info: \pdf@ifprimitive is available. Package pdftexcmds Info: \pdfdraftmode found. Package: pdfescape 2016/05/16 v1.14 Implements pdfTeX's escape features (HO) Package: bigintcalc 2016/05/16 v1.4 Expandable calculations on big integers (HO ) Package: bitset 2016/05/16 v1.2 Handle bit-vector datatype (HO) Package: uniquecounter 2016/05/16 v1.3 Provide unlimited unique counter (HO) ) Package hobsub Info: Skipping package `hobsub' (already loaded). Package: letltxmacro 2016/05/16 v1.5 Let assignment for LaTeX macros (HO) Package: hopatch 2016/05/16 v1.3 Wrapper for package hooks (HO) Package: xcolor-patch 2016/05/16 xcolor patch Package: atveryend 2016/05/16 v1.9 Hooks at the very end of document (HO) Package atveryend Info: \enddocument detected (standard20110627). Package: atbegshi 2016/06/09 v1.18 At begin shipout hook (HO) Package: refcount 2016/05/16 v3.5 Data extraction from label references (HO) Package: hycolor 2016/05/16 v1.8 Color options for hyperref/bookmark (HO) ) (/usr/local/texlive/2019/texmf-dist/tex/latex/graphics/keyval.sty Package: keyval 2014/10/28 v1.15 key=value parser (DPC) \KV@toks@=\toks14 ) (/usr/local/texlive/2019/texmf-dist/tex/generic/ifxetex/ifxetex.sty Package: ifxetex 2010/09/12 v0.6 Provides ifxetex conditional ) (/usr/local/texlive/2019/texmf-dist/tex/latex/oberdiek/auxhook.sty Package: auxhook 2016/05/16 v1.4 Hooks for auxiliary files (HO) ) (/usr/local/texlive/2019/texmf-dist/tex/latex/oberdiek/kvoptions.sty Package: kvoptions 2016/05/16 v3.12 Key value format for package options (HO) ) \@linkdim=\dimen136 \Hy@linkcounter=\count180 \Hy@pagecounter=\count181 (/usr/local/texlive/2019/texmf-dist/tex/latex/hyperref/pd1enc.def File: pd1enc.def 2018/11/30 v6.88e Hyperref: PDFDocEncoding definition (HO) Now handling font encoding PD1 ... ... no UTF-8 mapping file for font encoding PD1 ) \Hy@SavedSpaceFactor=\count182 (/usr/local/texlive/2019/texmf-dist/tex/latex/latexconfig/hyperref.cfg File: hyperref.cfg 2002/06/06 v1.2 hyperref configuration of TeXLive ) Package hyperref Info: Hyper figures OFF on input line 4519. Package hyperref Info: Link nesting OFF on input line 4524. Package hyperref Info: Hyper index ON on input line 4527. Package hyperref Info: Plain pages OFF on input line 4534. Package hyperref Info: Backreferencing OFF on input line 4539. Package hyperref Info: Implicit mode ON; LaTeX internals redefined. Package hyperref Info: Bookmarks ON on input line 4772. \c@Hy@tempcnt=\count183 (/usr/local/texlive/2019/texmf-dist/tex/latex/url/url.sty \Urlmuskip=\muskip16 Package: url 2013/09/16 ver 3.4 Verb mode for urls, etc. ) LaTeX Info: Redefining \url on input line 5125. \XeTeXLinkMargin=\dimen137 \Fld@menulength=\count184 \Field@Width=\dimen138 \Fld@charsize=\dimen139 Package hyperref Info: Hyper figures OFF on input line 6380. Package hyperref Info: Link nesting OFF on input line 6385. Package hyperref Info: Hyper index ON on input line 6388. Package hyperref Info: backreferencing OFF on input line 6395. Package hyperref Info: Link coloring OFF on input line 6400. Package hyperref Info: Link coloring with OCG OFF on input line 6405. Package hyperref Info: PDF/A mode OFF on input line 6410. LaTeX Info: Redefining \ref on input line 6450. LaTeX Info: Redefining \pageref on input line 6454. \Hy@abspage=\count185 \c@Item=\count186 \c@Hfootnote=\count187 ) Package hyperref Info: Driver (autodetected): hpdftex. (/usr/local/texlive/2019/texmf-dist/tex/latex/hyperref/hpdftex.def File: hpdftex.def 2018/11/30 v6.88e Hyperref driver for pdfTeX \Fld@listcount=\count188 \c@bookmark@seq@number=\count189 (/usr/local/texlive/2019/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty Package: rerunfilecheck 2016/05/16 v1.8 Rerun checks for auxiliary files (HO) Package uniquecounter Info: New unique counter `rerunfilecheck' on input line 2 82. ) \Hy@SectionHShift=\skip49 ) (./Untitled.aux) \openout1 = `Untitled.aux'. LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 30. LaTeX Font Info: ... okay on input line 30. LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 30. LaTeX Font Info: ... okay on input line 30. LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 30. LaTeX Font Info: ... okay on input line 30. LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 30. LaTeX Font Info: ... okay on input line 30. LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 30. LaTeX Font Info: ... okay on input line 30. LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 30. LaTeX Font Info: ... okay on input line 30. LaTeX Font Info: Checking defaults for PD1/pdf/m/n on input line 30. LaTeX Font Info: ... okay on input line 30. \AtBeginShipoutBox=\box46 Package hyperref Info: Link coloring OFF on input line 30. (/usr/local/texlive/2019/texmf-dist/tex/latex/hyperref/nameref.sty Package: nameref 2016/05/21 v2.44 Cross-referencing by name of section (/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/gettitlestring.sty Package: gettitlestring 2016/05/16 v1.5 Cleanup title references (HO) ) \c@section@level=\count190 ) LaTeX Info: Redefining \ref on input line 30. LaTeX Info: Redefining \pageref on input line 30. LaTeX Info: Redefining \nameref on input line 30. (./Untitled.out) (./Untitled.out) \@outlinefile=\write3 \openout3 = `Untitled.out'. (./Untitled.toc) \tf@toc=\write4 \openout4 = `Untitled.toc'. [1 {/usr/local/texlive/2019/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] [2 ] Chapter 1. [3] [4] [5] [6] [7] [8 ] Chapter 2. [9] [10 ] Chapter 3. Package atveryend Info: Empty hook `BeforeClearDocument' on input line 44. [11] Package atveryend Info: Empty hook `AfterLastShipout' on input line 44. (./Untitled.aux) Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 44. Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 44. Package rerunfilecheck Info: File `Untitled.out' has not changed. (rerunfilecheck) Checksum: EFA5D490BF925B77535D7D7DA27CE7E0;461. Package atveryend Info: Empty hook `AtVeryVeryEnd' on input line 44. ) Here is how much of TeX's memory you used: 14100 strings out of 492616 259219 string characters out of 6129480 571398 words of memory out of 5000000 17991 multiletter control sequences out of 15000+600000 536327 words of font info for 37 fonts, out of 8000000 for 9000 1141 hyphenation exceptions out of 8191 40i,5n,63p,227b,351s stack positions out of 5000i,500n,10000p,200000b,80000s </usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb ></usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb> </usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx9.pfb></ usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb></us r/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmr8.pfb></usr/l ocal/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmr9.pfb></usr/loca l/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmsl10.pfb> Output written on Untitled.pdf (11 pages, 89265 bytes). PDF statistics: 144 PDF objects out of 1000 (max. 8388607) 113 compressed objects within 2 object streams 22 named destinations out of 1000 (max. 500000) 73 words of extra memory for PDF output out of 10000 (max. 10000000)
答案1
这个问题的解决方案是(正如 Ulrike Fisher 所建议的)只需更新titletoc.sty
最早的版本(2019),因为在之前的版本中似乎有这个错误由贝佐斯调整二月里。
我添加了一个关于 Mac OS 上唯一软件包更新的简要指南,因为在重新安装整个 MacTeX 发行版时,我没有获得该软件包的较新版本(感谢 Ulrike Fisher 让我注意到这一点)。通过使用 shell 命令行,在 Mac 上安装的locate
路径titletoc.sty
$ locate titletoc.sty
%should give /usr/local/texlive/2019/texmf-dist/tex/latex/titlesec/titletoc.sty
然后从下载更新版本的软件包这里(在 CTAN 上)并直接在文件夹内进行替换。这样就解决了问题。