我想手动对文档中的章节进行版本控制,并将章节的相应版本号添加到其页脚。假设我有两个章节,第 1 章和第 2 章,第 1 章的版本为 2.0,第 2 章的版本为 3.0。我希望第 1 章的页脚显示:版本 2.0,第 2 章的页脚显示:版本 3.0。我想手动定义版本,而不是使用 VCS 版本。
我不能使用,fancyhdr
因为我使用titlesec
并且它们冲突:
/usr/local/texlive/2016basic/texmf-dist/tex/latex/titlesec/ttlps.def:261: Package titlesec Error: Incompatible package.
/usr/local/texlive/2016basic/texmf-dist/tex/latex/titlesec/ttlps.def:262: Package titlesec Error: Incompatible package.
这是我的thesis.cls
课程(最小的工作示例,我剥离了不相关的部分,例如颜色等):
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{thesis}
\PassOptionsToClass{11pt}{book}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\ProcessOptions
\LoadClass{book}
\RequirePackage[utf8]{inputenc}
\RequirePackage[T1]{fontenc}
\RequirePackage[polish,english]{babel}
\RequirePackage{geometry}
\RequirePackage[outermarks,pagestyles,clearempty,psfloats,rigidchapters,%
newlinetospace]{titlesec}
\RequirePackage{titletoc}
\RequirePackage[usenames,dvipsnames,svgnames,table]{xcolor}
\definecolor{SREBRO}{cmyk}{0.47,0.37,0.38,0.09}
\newcommand{\secfont}{\fontfamily{fla}\selectfont}
\newcommand{\chnfont}{\fontfamily{fla}\selectfont}
\setlength{\@fptop}{0pt}
% Widows and orphans (club lines):
\widowpenalty=300
\clubpenalty=300
% Page layout:
\newlength{\headindent}
\setlength{\headindent}{2.5cm}
\widenhead{\headindent}{0pt}
\geometry{%
a4paper,tmargin=3cm,bmargin=2.8cm,lmargin=4.5cm,rmargin=2.5cm,headsep=35pt,
footskip=1.5cm,bindingoffset=0.5cm,reversemarginpar,marginparwidth=2.5cm,
marginparsep=0.5cm, asymmetric}
\DeclareOption{oneside}{%
\geometry{twoside=false,lmargin=5cm,rmargin=2.5cm,bindingoffset=0cm}}
% Titles:
\titleformat{name=\chapter}[block]{\secfont\Huge\filleft}{}{0em}{%
\parbox{0.9\textwidth}%
{\raggedleft\chnfont\fontsize{65}{50}\selectfont%
\textcolor{SREBRO}{\thechapter}}%
\vspace{0.5ex}\\}
\titleformat{name=\chapter,numberless}[block]{\secfont\Huge\filleft}{}{0em}{}
\titlespacing*{\chapter}{-\headindent}{0.5cm}{7cm}
\titlecontents{chapter}[1.5em]{\addvspace{1.8ex}\secfont\bfseries}%
{\contentslabel{1.5em}}{\hspace*{-1.5em}}%
{~\hfill\contentspage}[\addvspace{0.3ex}]
% Page styles:
\renewpagestyle{plain}{\sethead{}{}{}\setfoot{}{}{}}
\renewpagestyle{empty}{\sethead{}{}{}\setfoot{}{}{}}
\newcommand{\setdefmainpagestyle}{%
\sethead[\large\usepage][]%
[\footnotesize\itshape
\if@mainmatter
\ifthenelse{\value{chapter}>0}{\thechapter~~}{}
\fi
\chaptertitle]%
{\footnotesize\itshape
\if@mainmatter
\ifthesection%
{\thesection~~\sectiontitle}%
{\ifthenelse{\value{chapter}>0}{\thechapter~~}{}\chaptertitle}
\else
\chaptertitle
\fi
}{}{\large\usepage}
\setfoot{version 3 \today}{}{}
%\setfloathead{}{}{}{\setheadrule{0pt}}[p]
}
\newpagestyle{main}{\setdefmainpagestyle}
\AtBeginDocument{\pagestyle{main}\raggedbottom}
\let\setminus\backslash
%
\ProcessOptions\relax
一些 main.tex 示例:
\documentclass{thesis}
\begin{document}
\title{Title}
\maketitle
\chapter{Chapter 1}
\chapter{Chapter 2}
\end{document}
答案1
像这样吗?
请注意,如果一章包含多页,您的代码将无法编译,因此我对其进行了修改以使其可以工作。(可能您省略了所需的包。)
\chapterversion{<version>}
设置章节版本,然后在主页的默认页面样式处于活动状态时将其添加为右下角页脚。
\begin{filecontents}{\jobname.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{\jobname}
\PassOptionsToClass{11pt}{book}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\ProcessOptions
\LoadClass{book}
\RequirePackage[utf8]{inputenc}
\RequirePackage[T1]{fontenc}
\RequirePackage[polish,english]{babel}
\RequirePackage{geometry}
\RequirePackage[outermarks,pagestyles,clearempty,psfloats,rigidchapters,%
newlinetospace]{titlesec}
\RequirePackage{titletoc}
\RequirePackage[usenames,dvipsnames,svgnames,table]{xcolor}
\definecolor{SREBRO}{cmyk}{0.47,0.37,0.38,0.09}
\newcommand{\secfont}{\fontfamily{fla}\selectfont}
\newcommand{\chnfont}{\fontfamily{fla}\selectfont}
\setlength{\@fptop}{0pt}
% Widows and orphans (club lines):
\widowpenalty=300
\clubpenalty=300
% Page layout:
\newlength{\headindent}
\setlength{\headindent}{2.5cm}
\widenhead{\headindent}{0pt}
\geometry{%
a4paper,tmargin=3cm,bmargin=2.8cm,lmargin=4.5cm,rmargin=2.5cm,headsep=35pt,
footskip=1.5cm,bindingoffset=0.5cm,reversemarginpar,marginparwidth=2.5cm,
marginparsep=0.5cm, asymmetric}
\DeclareOption{oneside}{%
\geometry{twoside=false,lmargin=5cm,rmargin=2.5cm,bindingoffset=0cm}}
% Titles:
\titleformat{name=\chapter}[block]{\secfont\Huge\filleft}{}{0em}{%
\parbox{0.9\textwidth}%
{\raggedleft\chnfont\fontsize{65}{50}\selectfont%
\textcolor{SREBRO}{\thechapter}}%
\vspace{0.5ex}\\}
\titleformat{name=\chapter,numberless}[block]{\secfont\Huge\filleft}{}{0em}{}
\titlespacing*{\chapter}{-\headindent}{0.5cm}{7cm}
\titlecontents{chapter}[1.5em]{\addvspace{1.8ex}\secfont\bfseries}%
{\contentslabel{1.5em}}{\hspace*{-1.5em}}%
{~\hfill\contentspage}[\addvspace{0.3ex}]
% Page styles:
\renewpagestyle{plain}{\sethead{}{}{}\setfoot{}{}{}}
\renewpagestyle{empty}{\sethead{}{}{}\setfoot{}{}{}}
\newcommand{\setdefmainpagestyle}{%
\sethead[\large\usepage][]%
[\footnotesize\itshape
\if@mainmatter
\ifnum\value{chapter}>0\thechapter~~\fi
\fi
\chaptertitle]%
{\footnotesize\itshape
\if@mainmatter
\ifthesection%
{\thesection~~\sectiontitle}%
{\ifnum\value{chapter}>0\thechapter~~\chaptertitle\fi}%
\else
\chaptertitle
\fi
}{}{\large\usepage}%
\setfoot{version 3 \today}{}{\ifx\thesis@chapterversion\@empty\relax\else chapter version \thesis@chapterversion \fi}%
%\setfloathead{}{}{}{\setheadrule{0pt}}[p]
}
\newpagestyle{main}{\setdefmainpagestyle}
\AtBeginDocument{\pagestyle{main}\raggedbottom}
\let\setminus\backslash
%
\let\thesis@chapterversion\@empty
\newcommand*\chapterversion[1]{\gdef\thesis@chapterversion{#1}}
\ProcessOptions\relax
\end{filecontents}
\documentclass{\jobname}
\usepackage{kantlipsum}
\begin{document}
\title{Title}
\maketitle
\chapter{Chapter 1}\chapterversion{3.0}
\kant[1-5]
\chapter{Chapter 2}\chapterversion{2.0}
\kant[6-10]
\end{document}