Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

生成的pdf有问题,可以不要系统自动生成的那个标题么? #108

Closed
ghost opened this issue Apr 15, 2016 · 15 comments
Closed

Comments

@ghost
Copy link

ghost commented Apr 15, 2016

可以不要系统自动生成的那个标题么?生成pdf的程序有没有可选项可以去掉?要不跟原来的标题冲突了,而且copyright和前言都识别为章节了。

@yidao620c
Copy link
Owner

找了好久没找到这个选项,真是郁闷。

@ghost
Copy link
Author

ghost commented Apr 19, 2016

提供一种思路:

  1. 把自己写的标题去掉,把copyright和前言去掉,然后生成pdf(生成pdf的那里,系统默认标题,就能对的上了)
  2. 把copyright和前言单独生成一个pdf
  3. 把两个pdf拼接起来。

可选操作(加一个封面)

@CarlKing5019
Copy link
Contributor

CarlKing5019 commented Jul 10, 2017

我解决了这个问题,现把解决方法共享给大家。

在 latex 文件导言区加入以下代码:

% 隐藏原目录名
\renewcommand{\contentsname}{}

% 在 section 前插入分页
\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}

% 章节编号只编号到 subsection
\newcommand\normalsecnumdepth{\setcounter{secnumdepth}{2}}

% 所有层次章节都不编号
\newcommand\specialsecnumdepth{\setcounter{secnumdepth}{-2}}  

% toc 到 subsection
\newcommand\normaltocdepth{
    \setcounter{tocdepth}{2}
    \addtocontents{toc}{\setcounter{tocdepth}{2}}
}

% toc 到 section
\newcommand\specialtocdepth{
    \setcounter{tocdepth}{1}
    \addtocontents{toc}{\setcounter{tocdepth}{1}}
}

\sphinxtableofcontents 前插入

\specialsecnumdepth
\specialtocdepth
\section{目录}
\vspace{-36pt}

\section{第一章:数据结构和算法} 前插入

\normaltocdepth

\section{附录A} 前插入

\specialtocdepth

之后编译后的 pdf 文件, 无论正文中目录页还是书签栏显示都是正常的. 如下图:


@yidao620c
Copy link
Owner

谢谢 CarlKing5019 童鞋

@ghost
Copy link
Author

ghost commented Jul 29, 2017

@CarlKing5019 可以共享出来

@CarlKing5019
Copy link
Contributor

@yulongjun 我上传了一份到我的 github 里, 可以从 这里 下载.

@McooLewis
Copy link

你好,请问这个文档下下来之后如何生成pdf版本的呢,是用make pdf命令吗,我试了下但是并没有生成啊,谢谢.

@CarlKing5019
Copy link
Contributor

@McooLewis , 请使用 make help 命令查看帮助, 或者直接打开 Makefile 文件查看可选命令.

@McooLewis
Copy link

好的,十分感谢.

@WanderMax
Copy link

pdf 的档案需要更新下了, 4.1 之后提交了不少修正

@yidao620c
Copy link
Owner

to all:

最新版3.0.0的PDF已发布,根据最新源码生成,并且去掉了多余标题。另外这个步骤并没有CarlKing5019的那么复杂。只需要一步即可:

编辑文件build/latex/python3-cookbook.tex
\setcounter{tocdepth}{2}下增加一行\setcounter{secnumdepth}{-2}

再执行:

xelatex scrapy-cookbook.tex

@yidao620c yidao620c reopened this Dec 7, 2017
@CarlKing5019
Copy link
Contributor

我之前的解决方案中, 核心代码也是 \setcounter{secnumdepth}{-2} 用于去除所有章节的编号. 其余的代码是用于优化排版的. 下图是使用默认设置生成的目录和正文, 可以看到存在几个问题, 1. 前言里的 subsection 出现在目录中了; 2. 目录名是英文; 3. 各个 section 之间没有分页.


优化排版的代码具体来说如下:

  1. 命令 \normaltocdepth \specialtocdepth 用于调整 tocdepth, 前言和附录使用 \specialtocdepth, 正文使用 \ normaltocdepth.

  2. 以下代码用于修改目录名字, 并且把目录加入到目录中.

% 隐藏原目录名
\renewcommand{\contentsname}{}
\section{目录}
\vspace{-36pt}
  1. 以下代码用于在每一个 section 前插入分页.
% 在 section 前插入分页
\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}

@yidao620c yidao620c reopened this Dec 8, 2017
@yidao620c
Copy link
Owner

赞一个, @CarlKing5019

@yidao620c
Copy link
Owner

已经参考 @CarlKing5019 的方法重新生成了最新的PDF文件

@CarlKing5019
Copy link
Contributor

赞, @yidao620c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants