我正在尝试为 SOP 创建自定义类文件。我认为我在使用 fancyhdr 包时遇到了问题,但我不确定原因。
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sop}[10/10/2014 article class for standard operating procedures]
% Passes and class options to the underlying article class
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
\LoadClass{article}
% Redefine the page margins
\RequirePackage[left=1in,right=1in,top=.75in,bottom=.75in]{geometry}
% Modifications to the section titles
\renewcommand*\thesection{\arabic{section}.0}
\renewcommand*\thesubsection{\arabic{section}.\arabic{subsection}}
\renewcommand*\thesubsubsection{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}}
% Modification of title block
\RequirePackage{titling}
\newcommand{\sopchaptertitle}[1]{\def\@sopchaptertitle{#1}}
\newcommand{\sopchapternumber}[1]{\def\@sopchapternumber{#1}}
%%% Drop before title
\setlength\droptitle{12cm}
%%% Define the internal variable \@title to be the supplied data
\renewcommand\maketitlehooka{%
\def\@title{\@sopchaptertitle\ \@sopchapternumber}}
%%% No author field, so \maketitlehookb gobbles what comes after it
\renewcommand\maketitlehookb[1]{}
%%% No date field, so \maketitlehookc gobbles what comes after it
\renewcommand\maketitlehookc[1]{}
%%% Formatting the title
\pretitle{\centering\sffamily\LARGE}
%%% Space after the title
\posttitle{\par\vspace{3cm}}
%%% The rest of the class
% For "Page N of M" and header/footer constructioe
\RequirePackage{lastpage}
% For easier construction of page headers/footers
\RequirePackage{fancyhdr}
\newcommand{\revision}[1]{\def\@revision{#1}}
\newcommand{\revisionMMYY}[1]{\def\@revisionMMYY{#1}}
\newcommand{\tcn}[1]{\def\@tcn{#1}}
\fancypagestyle{plain}{ % for first page
\fancyhf{}
\fancyhead[R]{%
SOP- \thesopchapternumber \ Page \thepage{} of \pageref*{LastPage}
}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[R]{%
REV \therevision,\ \therevisionMMYY
}
\renewcommand{\footrulewidth}{0pt}
}
\pagestyle{fancy} % for other pages
\fancyhf{}
\fancyhead[R]{%
SOP-\thesopchapternumber \ Page \thepage{} of \pageref*{LastPage}
}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[R]{%
REV \therevision,\ \therevisionMMYY
}
\renewcommand{\footrulewidth}{0pt}
% For easier customization of itemized, enumerated, and other lists
\RequirePackage{enumitem}
% For hyperlinked cross-references
\RequirePackage{hyperref}
% Ensure first page is correct style
\RequirePackage{appendix}
\RequirePackage{makebox}
\RequirePackage{nextpage}
\thispagestyle{plain}
\endinput
这是一个基本的 Tex 文件,我正在尝试用它来编译它,只是为了让它工作。
\documentclass[10pt]{sop}
%
% SOP Standard Form Data
\sopchaptertitle{john doe PROCEDURE}
\sopchapternumber{D.1}
\date{11/13/14}
\author{johndoe}
%...more of the above
%Here begins the actual document
\begin{document}
\maketitle
\section{Main Title}
\section{Approval}
Approval1....\makebox[1.5in]{\hrulefill}\\\vspace{1.5in}
Approval2....\makebox[1.5in]{\hrulefill}
\newpage
\section{Purpose and Discussion}
%...more of the above...
\end{document}
编辑:这是我的日志文件。https://www.dropbox.com/s/qebydr5p1xt9ozq/text.log?dl=0
答案1
您的 MWE 中有几件事需要修复:
在主文档中,您省略了
\revision
和\revisionMMYY
命令。您的类文件没有这些命令的默认值,因此引用它们时会导致错误。您误解了类或包代码中有时会出现的构造的用法
\thesomething
。大多数情况下,这些构造用于打印使用命令定义的计数器的格式化值\newcounter{}
(请参阅LaTeX Wikibook:计数器)。正如@cfr 提到的,如果您使用了\newcounter{sopchapternumber}
,那么包括、、等的宏\thesopchapternumber
将\value{sopchapternumber}
可用\arabic{sopchapternumber}
。在我之前的例子中,titling
包中还添加了非计数器的命令,但这些是规则的例外,并且是由包代码明确添加的\thetitle
。\theauthor
book
此外,如果这些 SOP 是基于章节的,我会考虑以章节为基础或以章节为基础来设计课程report
,而不是article
。
修正后的 MWE:
\documentclass[10pt]{sop}
\sopchaptertitle{john doe PROCEDURE}
\sopchapternumber{D.1}
\revision{Some Revision}
\revisionMMYY{Some Month, Some Year}
\date{11/13/14}
\author{johndoe}
\begin{document}
\maketitle
\section{Main Title}
\section{Approval}
Approval1....\makebox[1.5in]{\hrulefill}\\\vspace{1.5in}
Approval2....\makebox[1.5in]{\hrulefill}
\newpage
\section{Purpose and Discussion}
\end{document}
班级:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sop}[2014/10/10 article class for standard operating procedures]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
\LoadClass{article}
% Redefine the page margins
\RequirePackage[left=1in,right=1in,top=.75in,bottom=.75in]{geometry}
% Modifications to the section titles
\renewcommand*\thesection{\arabic{section}.0}
\renewcommand*\thesubsection{\arabic{section}.\arabic{subsection}}
\renewcommand*\thesubsubsection{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}}
% Modification of title block
\RequirePackage{titling}
\newcommand{\sopchaptertitle}[1]{\def\@sopchaptertitle{#1}}
\newcommand{\sopchapternumber}[1]{\def\@sopchapternumber{#1}}
%%% Drop before title
\setlength\droptitle{12cm}
%%% Define the internal variable \@title to be the supplied data
\renewcommand\maketitlehooka{%
\def\@title{\@sopchaptertitle\ \@sopchapternumber}}
%%% No author field, so \maketitlehookb gobbles what comes after it
\renewcommand\maketitlehookb[1]{}
%%% No date field, so \maketitlehookc gobbles what comes after it
\renewcommand\maketitlehookc[1]{}
%%% Formatting the title
\pretitle{\centering\sffamily\LARGE}
%%% Space after the title
\posttitle{\par\vspace{3cm}}
%%% The rest of the class
% For "Page N of M" and header/footer constructioe
\RequirePackage{lastpage}
% For easier construction of page headers/footers
\RequirePackage{fancyhdr}
\newcommand{\revision}[1]{\def\@revision{#1}}
\newcommand{\revisionMMYY}[1]{\def\@revisionMMYY{#1}}
\newcommand{\tcn}[1]{\def\@tcn{#1}}
\fancypagestyle{plain}{ % for first page
\fancyhf{}
\fancyhead[R]{%
SOP- \@sopchapternumber \ Page \thepage{} of \pageref*{LastPage}
}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[R]{%
REV \@revision{},\ \@revisionMMYY
}
\renewcommand{\footrulewidth}{0pt}
}
\pagestyle{fancy} % for other pages
\fancyhf{}
\fancyhead[R]{%
SOP-\@sopchapternumber \ Page \thepage{} of \pageref*{LastPage}
}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[R]{%
REV \@revision{},\ \@revisionMMYY
}
\renewcommand{\footrulewidth}{0pt}
% For easier customization of itemized, enumerated, and other lists
\RequirePackage{enumitem}
% For hyperlinked cross-references
\RequirePackage{hyperref}
% Ensure first page is correct style
\RequirePackage{appendix}
\RequirePackage{makebox}
\RequirePackage{nextpage}
\thispagestyle{plain}
\endinput