免費論壇 繁體 | 簡體
Sclub交友聊天~加入聊天室當版主
分享
返回列表 发帖

请教怎么在目录里显示“第一章”,和附录里不显示点

本帖最后由 abababa 于 2019-7-3 21:23 编辑
  1. \documentclass{report}
  2. \usepackage[toc,page,titletoc,title]{appendix}% 附录
  3. \usepackage{sectsty}
  4. \usepackage[slantfont,boldfont]{xeCJK}
  5. \usepackage[top=43mm,bottom=41mm,left=34mm,right=34mm]{geometry}
  6. \usepackage[small,center,pagestyles]{titlesec}
  7. \usepackage[xetex,bookmarksnumbered,bookmarksopen,colorlinks,citecolor=black,linkcolor=black]{hyperref}
  8. \titleformat{\chapter}[hang]{\normalfont\centering}{\chaptername}{15pt}{}
  9. \renewcommand{\chaptername}[1]{第 \thechapter 章 #1}
  10. \begin{document}

  11. \tableofcontents
  12. \chapter{第一个章节}
  13. \chapter{第二个章节}
  14. \begin{appendices}
  15. \section{附录1}
  16. \section{附录2}
  17. \end{appendices}
  18. \end{document}
复制代码
就是上面那段代码,下面几个问题,我查了两周,还是没做好。

现在目录里只显示1,2这样的,想让目录里也显示“第1章 第一个章节”,和章节标题完全一样,请问这个要怎么做?
还有附录里,附录1,附录2之前,都显示了一个.1,.2,查了一下说是已经脱离了章节,所以没有名字,但我想去掉这些,请教这个要怎么做?
另外就是附录的名字,显示为Appendices,请教怎么变成中文的“附录”?
还有一个页眉的问题,我用了
  1. \fancyhf{}
  2. \fancyhead[OC]{\leftmark}
  3. \fancyhead[EC]{\rightmark}
复制代码
但是章节后面,总是多一个数字,比如第2章,页眉里就显示 “第 2 章 2. 第二个章节”。我想要的是“第 2 章. 第二个章节”这样的,是不是我前面章节那里又弄错了?
分享到: QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友

本帖最后由 abababa 于 2019-7-3 22:29 编辑

回复 1# abababa

中间那个,附录里不显示.1,.2的解决了,是用了
\section*{附录1}
来做附录,然后\addcontentsline{toc}{section}{附录1}
这样显示出来是正确的,不过目录链接没有了。
附录那个也解决了,用了
\chapter*{附录}
来模拟,这样就没问题了。

又多了一个问题,添加到顶楼了。

TOP

对这类东西没怎么研究过,只会最简单的一个:附录的名字变成附录,因为你所用的 appendix 宏包就有讲,用
\renewcommand{\appendixtocname}{附录}
\renewcommand{\appendixpagename}{附录}
即可

TOP

鼓捣了一下午,搞成这样子了:
  1. \documentclass{report}
  2. \usepackage{lipsum}
  3. \usepackage[toc,page,titletoc,title]{appendix}% 附录
  4. %\usepackage{sectsty}%啥用嘀?
  5. \usepackage[slantfont,boldfont]{xeCJK}
  6. \usepackage[top=43mm,bottom=41mm,left=34mm,right=34mm]{geometry}
  7. \usepackage[small,center,pagestyles]{titlesec}
  8. \usepackage{titletoc}
  9. \usepackage{fancyhdr}
  10. \usepackage[xetex,bookmarksnumbered,bookmarksopen,colorlinks,citecolor=black,linkcolor=black]{hyperref}

  11. \renewcommand\thechapter{第\arabic{chapter}章}
  12. \renewcommand\thesection{第\arabic{section}节}

  13. \titleformat{\chapter}[hang]{\bfseries\LARGE\centering}{\thechapter}{15pt}{}
  14. \titleformat{\section}[hang]{\bfseries\large}{\thesection}{15pt}{}

  15. \titlecontents{chapter}[4.5em]
  16. {\addvspace{0.5\baselineskip}\bfseries}
  17. {\contentslabel{4.5em}}
  18. {}
  19. {\hfill\contentspage}

  20. \titlecontents{section}[5.5em]
  21. {}
  22. {\contentslabel{4.5em}}
  23. {}
  24. {\hfill\contentspage}

  25. \renewcommand{\contentsname}{目录}
  26. \renewcommand{\appendixtocname}{附录}
  27. \renewcommand{\appendixpagename}{附录}

  28. \pagestyle{fancy}
  29. \fancyhf{}
  30. %\fancyhead[OC]{\leftmark}
  31. %\fancyhead[EC]{\rightmark}
  32. %report类不分左右页,直接设[C]的即可
  33. \fancyhead[C]{\leftmark}
  34. \fancyfoot[C]{\thepage}
  35. \renewcommand{\chaptermark}[1]{\markboth{\thechapter. #1}{}}

  36. \begin{document}

  37. \tableofcontents
  38. \chapter{第一个章}
  39. \section{第一个节}
  40. \lipsum[1-11]
  41. \section{第二个节}
  42. \lipsum[1-11]

  43. \chapter{第二个章}
  44. \section{第一个节}
  45. \lipsum[1-11]
  46. \section{第二个节}
  47. \lipsum[1-11]

  48. \renewcommand\thesection{}
  49. \titleformat{\section}[hang]{\bfseries\large}{}{0pt}{}
  50. \fancyhead[C]{\rightmark}
  51. \renewcommand{\sectionmark}[1]{\markright{#1}}

  52. \begin{appendices}
  53. \section{附录1}
  54. \lipsum[1-11]
  55. \section{附录2}
  56. \lipsum[1-11]
  57. \end{appendices}
  58. \end{document}
复制代码
副作用未知
$\href{https://kuingggg.github.io/}{\text{About Me}}$

TOP

回复 3# kuing
谢谢,这个也想到和 chapter 一样,是 renewcommand 某个东西,但没猜到是哪个,后来因为附录的标题总是对不上,总是前面多个点,就没心思再考虑这个了。

TOP

回复 4# kuing

谢谢,这个就很好了。以前一直都不弄这些,就知道写内容,突然想做个像样点的文档,才发现自己还有这么多基础东西不懂。

TOP

回复 6# abababa

这方面我也没研究,你看我的撸题集的目录、页眉这些都是默认的样式,只改了标题。

上面的代码都是现学现卖,有些内容还是似懂非懂……

TOP

回复 4# kuing

这里面是\renewcommand\thechapter,这样后面那些 section,前面就自动带上第几章了,如果不想在section前带这些,是不是要\renewcommand{\chaptername}这样,不过这个就像我之前说的,总会在页眉那里带上红色部分:第 2 章 2. 第二个章节

TOP

回复 8# abababa

嗯,改 \thechapter 不好,很多东西会跟着变,上面的还是扔掉好了……

还是用回 \section* 和 \addcontentsline 吧……:
  1. \documentclass{report}
  2. \usepackage{lipsum}
  3. \usepackage[toc,page,titletoc,title]{appendix}% 附录
  4. %\usepackage{sectsty}%啥用嘀?
  5. \usepackage[slantfont,boldfont]{xeCJK}
  6. \usepackage[top=43mm,bottom=41mm,left=34mm,right=34mm]{geometry}
  7. \usepackage[small,center,pagestyles]{titlesec}
  8. \usepackage{titletoc}
  9. \usepackage{fancyhdr}
  10. \usepackage[xetex,bookmarksnumbered,bookmarksopen,colorlinks,citecolor=black,linkcolor=black]{hyperref}

  11. \titleformat{\chapter}[hang]{\bfseries\LARGE\centering}{第\thechapter 章}{15pt}{}
  12. \titleformat{\section}[hang]{\bfseries\large}{第\thesection 节}{15pt}{}

  13. \titlecontents{chapter}[4.5em]
  14. {\addvspace{0.5\baselineskip}\bfseries}
  15. {\contentslabel[第\thecontentslabel 章]{4.5em}}
  16. {}
  17. {\hfill\contentspage}

  18. \titlecontents{section}[6em]
  19. {}
  20. {\contentslabel[第\thecontentslabel 节]{5em}}
  21. {}
  22. {\hfill\contentspage}

  23. \renewcommand{\contentsname}{目录}
  24. \renewcommand{\appendixtocname}{附录}
  25. \renewcommand{\appendixpagename}{附录}

  26. \pagestyle{fancy}
  27. \fancyhf{}
  28. %\fancyhead[OC]{\leftmark}
  29. %\fancyhead[EC]{\rightmark}
  30. %report类不分左右页,直接设[C]的即可
  31. \fancyhead[C]{\leftmark}
  32. \fancyfoot[C]{\thepage}
  33. \renewcommand{\chaptermark}[1]{\markboth{第\thechapter 章. #1}{}}

  34. \newcommand\flsection[1]{\phantomsection%不加它链接定位会不准确,不知为什么
  35. \addcontentsline{toc}{section}{#1}\section*{#1}}

  36. \begin{document}

  37. \tableofcontents
  38. \chapter{第一个章}
  39. \section{第一个节}
  40. \lipsum[1-11]
  41. \section{第二个节}
  42. \lipsum[1-11]

  43. \chapter{第二个章}
  44. \section{第一个节}
  45. \lipsum[1-11]
  46. \section{第二个节}
  47. \lipsum[1-11]

  48. \clearpage
  49. \fancyhead[C]{附录}
  50. \begin{appendices}
  51. \flsection{附录1}
  52. \lipsum[1-11]
  53. \flsection{附录2}
  54. \lipsum[1-11]
  55. \end{appendices}
  56. \end{document}
复制代码

TOP

回复 2# abababa

其实用 \chapter*{附录} 来模拟也挺好的,用单独一页来放“附录”两个字似乎也没啥必要……

TOP

回复 9# kuing

谢谢,这个挺好的。不过那个链接的问题,如果是用 chapter* 来模拟,目录里的页码还是链接不准确,不管哪一个都定位到第一个附录,是不是我又哪里弄错了?

还有个新问题,我用
\renewcommand{\contentsname}{\fontsize{21pt}{\baselineskip}\selectfont \textbf{目录}}
来给目录设定了字号和加粗,但这样一来,当目录页超过2页时,就会生成页眉,页眉里显示的是“目录”,不过字号却和fancy设定的字号不同,我又试着加了字体,字体到是和fancy设定的一样,这个要怎么解决?

TOP

本帖最后由 abababa 于 2019-7-5 19:18 编辑

回复 11# abababa

啊,我明白了,原来那个fancy要分别设置才行,
先设这个目录页的页眉,不要页脚:
\thispagestyle{empty}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{\kai\fontsize{10pt}{\baselineskip}\selectfont 目录}
\cfoot{}
% 做目录
\tableofcontents
然后下面是正文的页眉页脚,再设一次:
\pagebreak
\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{\hei\fontsize{11pt}{\baselineskip}\selectfont\rightmark}
\cfoot{~\thepage~}
%这里还能改页码,让正文从第一页开始:
\setcounter{page}{1}
%然后正文开始:
\chapter{这是第一章}

TOP

又试了一下页眉的样式,改成双线的:
  1. \newcommand{\makeheadrule}{%
  2.         \makebox[0pt][l]{\rule[0.55\baselineskip]{\headwidth}{0.4pt}}%
  3.         \rule[0.7\baselineskip]{\headwidth}{0.4pt}}
  4.         \renewcommand{\headrule}{%
  5.         {\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
  6.         \makeheadrule}
  7. }
复制代码
但是如果到了附录部分,我又不想让它显示页眉了,同时这个双线也想去掉,这要怎么做呢?

TOP

回复 13# abababa

把你目前的相关代码整理一下发上来,以便测试和修改

TOP

回复 14# kuing
  1. \documentclass[12pt,a4paper]{report}
  2. % AMS的数学宏包
  3. \usepackage{amssymb}
  4. \usepackage{amsmath}
  5. \usepackage[inline]{enumitem}
  6. \usepackage{lipsum}
  7. % 插入图片
  8. \usepackage{graphicx}
  9. \usepackage{float}
  10. \usepackage{sectsty}
  11. % XeTeX相应宏包
  12. \ProvidesPackage{zhfontcfg}
  13. \usepackage{xltxtra,fontspec,xunicode}
  14. \defaultfontfeatures{Mapping=tex-text}
  15. % 允许斜体和粗体
  16. \usepackage[slantfont,boldfont]{xeCJK}
  17. % 页边距设置
  18. \usepackage[top=43mm,bottom=41mm,left=34mm,right=34mm]{geometry}
  19. % 表格颜色
  20. \usepackage{colortbl}
  21. % 交叉引用链接
  22. \usepackage[xetex,bookmarksnumbered,bookmarksopen,colorlinks,citecolor=black,linkcolor=blue]{hyperref}
  23. \usepackage{listings}
  24. \setCJKmainfont{SimSun}
  25. \setCJKfamilyfont{hei}{SimHei}
  26. \setCJKfamilyfont{kai}{KaiTi}
  27. \newcommand {\hei}{\CJKfamily{hei}}
  28. \newcommand {\kai}{\CJKfamily{kai}}
  29. % 英文衬线字体
  30. \setmainfont{DejaVu Serif}
  31. % 英文等宽字体
  32. \setmonofont{DejaVu Sans Mono}
  33. % 英文无衬线字体
  34. \setsansfont{DejaVu Sans}
  35. % 中文方式断行
  36. \XeTeXlinebreaklocale "zh"
  37. \XeTeXlinebreakskip = 0pt plus 1pt
  38. % 设置缩进量
  39. \usepackage{indentfirst}
  40. \setlength{\parindent}{2.0em}
  41. % 设置行距
  42. \linespread{1.5}
  43. % 目录字体、样式
  44. \usepackage{caption}
  45. \usepackage{subcaption}
  46. \usepackage{titletoc}
  47. \titlecontents{chapter}[0pt]
  48.         {\normalfont\bf\fontsize{14pt}{\baselineskip}\selectfont}
  49.         {第 \thecontentslabel 章\quad}{}
  50.         {\titlerule*[10pt]{$\cdot$}\contentspage}

  51. \titlecontents{section}[0pt]
  52.         {\fontsize{12pt}{\baselineskip}\selectfont}
  53.         {\hspace*{3em}\contentslabel{2em}\ }{}
  54.         {\titlerule*[0.5pc]{$\cdot$}\contentspage\
  55. }

  56. \titlecontents{subsection}[1cm]
  57.         {\fontsize{12pt}{\baselineskip}\selectfont}
  58.         {\hspace*{3em}\contentslabel{2em}\ }{}
  59.         {\titlerule*[0.5pc]{$\cdot$}\contentspage
  60. }
  61. % 目录字体结束

  62. %章节、子章节的标题样式
  63. \usepackage[small,center,pagestyles]{titlesec}
  64. \titlespacing{\chapter}{0pt}{5pt}{10pt}
  65. \renewcommand{\chaptername}[1]{第 \thechapter 章 #1}
  66. \titleformat{\chapter}[hang]{\bfseries\centering\fontsize{20pt}{\baselineskip}\selectfont}{\chaptername}{20pt}{}
  67. \renewcommand{\contentsname}{\bfseries\fontsize{20pt}{\baselineskip}\selectfont \textbf{目 录}}
  68. \titleformat{\section}{\bfseries\hei\fontsize{15pt}{\baselineskip}\selectfont}{\thesection}{1em}{}
  69. \titleformat{\subsection}{\bfseries\hei\fontsize{15pt}{\baselineskip}\selectfont}{\thesubsection}{1em}{}
  70. % 图片样式
  71. \renewcommand{\figurename}{图}
  72. \renewcommand {\thefigure} {\thechapter{}-\arabic{figure}}
  73. \captionsetup{labelformat=default,labelsep=space}
  74. % 图片样式结束

  75. \usepackage[toc,page,titletoc,title]{appendix}% 附录
  76. % 修改目录标题和附录标题为中文
  77. \renewcommand{\appendixtocname}{附录}
  78. \renewcommand{\appendixpagename}{附录}
  79. % 页眉页脚
  80. \usepackage{fancyhdr}

  81. \makeatletter
  82. % 双线页眉
  83. \newcommand{\makeheadrule}{%
  84.         \makebox[0pt][l]{\rule[0.55\baselineskip]{\headwidth}{0.4pt}}%
  85.         \rule[0.7\baselineskip]{\headwidth}{0.4pt}}
  86.         \renewcommand{\headrule}{%
  87.         {\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
  88.         \makeheadrule}
  89. }
  90. \makeatother
  91. \begin{document}
  92. % 目录页的页眉页脚设置
  93. \pagestyle{fancy}
  94. \fancyhf{}
  95. \fancyhead[C]{\kai\fontsize{10.5pt}{\baselineskip}\selectfont 目录}
  96. \cfoot{}
  97. % 生成目录
  98. \tableofcontents
  99. % 插入分页符
  100. \pagebreak
  101. % 正文的页眉页脚
  102. \pagestyle{fancy}
  103. \fancyhf{}
  104. \fancyhead[C]{\kai\fontsize{10.5pt}{\baselineskip}\selectfont\rightmark}
  105. \cfoot{~\thepage~}
  106. % 重置正文为第 1 页
  107. \setcounter{page}{1}

  108. \chapter{第一章}
  109. \section{第一节}
  110. \lipsum[1-11]
  111. \section{第二节}
  112. \subsection{第2.1子节}
  113. \lipsum[1-11]
  114. \subsection{第2.2子节}
  115. \lipsum[1-11]
  116. \chapter{第二章}
  117. \section{第一节}
  118. \section{第二节}
  119. \clearpage
  120. \fancyhead[C]{\kai\fontsize{10.5pt}{\baselineskip}\selectfont 附录}
  121. \newcommand\flsection[1]{
  122.         \phantomsection%不加它链接定位会不准确,不知为什么
  123.         \addcontentsline{toc}{section}{#1}\section*{#1}
  124. }
  125. \begin{appendices}
  126. \flsection{附录1}
  127. \pagebreak
  128. \flsection{附录2}
  129. \end{appendices}
  130. \clearpage
  131. \newpage
  132. \thispagestyle{empty}
  133. \pagestyle{fancy}
  134. \fancyhf{}
  135. \chead{}
  136. \cfoot{}
  137. \renewcommand{\headrulewidth}{0pt}
  138. \renewcommand{\footrulewidth}{0pt}
  139. \fontsize{10pt}{\baselineskip}\selectfont
  140. 追加页,无内容,无页眉页脚,无章节标题
  141. \end{document}
复制代码
目前的代码如上。现在想在附录页里清掉页眉和页脚,还没来得及试验。觉得最后一页的追加内容没有页眉之类的,是不是因为它没有chapter等等啊。

TOP

回复 15# abababa

“现在想在附录页里清掉页眉和页脚”——附录页是指“附录”二字的单独那页,还是包括其后的所有附录内容的页?
“觉得最后一页的追加内容没有页眉之类的,是不是因为它没有chapter等等啊。”——那是你自己给清空的啊

另外,你有没有发现,自正文第3页起,正文比之前的要下沉一些?(比较页码与PDF底部之间距离即知)

TOP

回复 16# kuing

包括“附录”两个字的单独那页,都想去掉页眉页脚。我把后面那个追加页之前的代码移到\begin{appendices}之前,虽然能去掉页眉和页脚的标题和页码,但无法去掉那个双横线。而最后的追加页里是没有双横线的。我猜是不是这个跟chapter、section之类的有关。

最后那个距离的我没发现,也不知道要如何通过工具来测量这个距离,觉得眼睛看的分辨不出来。

TOP

回复 17# abababa

那个距离不用测量,你在阅读器切换到单页模式,来回切换 2、3 页就知道了。

现在来说那双线,你所用的双线设置把 \headrule 改变了,所以 \renewcommand{\headrulewidth}{0pt} 起不了作用,大概是酱紫。
而当时为何就最后一页没有?是因为在附录之后你写了个 \thispagestyle{empty} 啊!去掉这句那双线马上回来。
如果是想让后面无线,那只需在附录前 \renewcommand{\headrule}{} 即可,又或者改变双线的设置,比如将那两个 0.4pt 换成 \headrulewidth,这样刚才所说的就能起作用了。

其实你的要求就是从附录起啥都不要是吧,那在附录前用 \pagestyle{empty}(没有 this)就几乎满足你的要求了,就是除了“附录”二字那页始终有个页码,这是因为 \chapter 那一页的 pagestyle 被定死为 plain,所以要么重定义 \chapter,要么重定义 plain 这个 style,这里可以试试后者,呃,或许还有其他更好的方式,但就目前的情况来看,改 plain 就好,而且只需很简单的一句:\fancypagestyle{plain}{\fancyhf{}} 。
综上:
  1. ............
  2. 附录前的内容
  3. ............
  4. \clearpage
  5. \renewcommand{\headrule}{}
  6. \pagestyle{empty}
  7. \fancypagestyle{plain}{\fancyhf{}}
  8. \newcommand\flsection[1]{
  9.         \phantomsection%不加它链接定位会不准确,不知为什么
  10.         \addcontentsline{toc}{section}{#1}\section*{#1}
  11. }
  12. \begin{appendices}
  13. \flsection{附录1}
  14. \pagebreak
  15. \flsection{附录2}
  16. \end{appendices}
  17. \clearpage
  18. \fontsize{10pt}{\baselineskip}\selectfont
  19. 追加页,无内容,无页眉页脚,无章节标题
  20. \end{document}
复制代码
$\href{https://kuingggg.github.io/}{\text{About Me}}$

TOP

回复 18# kuing

谢谢,终于弄出了目前想要的结果,最终去掉了附录页的页眉页脚和双横线。

那个2、3页的差异,是因为chapter标题的原因吧,其它页都没看出正文距离页眉有多远,只有带chapter标题的那页看出来了,距离页眉远了,这个是不正常的吗?

TOP

回复 19# abababa

我说的 2、3 页是正文的第 2、3 页,不是 PDF 的第 2、3 页,看页码……

好吧用双页模式截个图描个线:
QQ截图20190717210611.gif
2019-7-17 21:14

TOP

返回列表 回复 发帖