为课程构建标题栏

为课程构建标题栏

我正在尝试构建一个带有标题块的类(使用标题),以便最终用户将数据输入两个字段。一个变量是 sopchaptertitle,另一个变量是 sopchapternumber。然后我想将它们连接起来,并将生成的标题放置在距离页面顶部一定距离并位于页面中央的位置。接下来是一定距离的空白和第一部分。

它看起来应该是这样的: 在此处输入图片描述

这是我的代码:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sop}

% 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}}

% Title block
\RequirePackage{titling}
\newcommand{\sopchaptertitle}[1]{\newcommand{\thesopchaptertitle}{#1}}
\newcommand{\sopchapternumber}[1]{\newcommand{\thesopchapternumber}{#1}}
\let\oldtitle\title
\renewcommand{\title}[1]{\oldtitle{#1}\newcommand{\mythetitle}{#1}}
\let\oldpretitle\pretitle
\renewcommand{\pretitle}[1]{\oldpretitle{#1}\newcommand{\mythepretitle}{#1}}
\let\oldposttitle\posttitle
\renewcommand{\posttitle}[1]{\oldposttitle{#1}\newcommand{\mytheposttitle}{#1}}
\renewcommand{\maketitle}{%
\mythepretitle{\setlength{\droptitle}{12.0cm}\begin{center}\LARGE}
\mythetitle{\thesopchaptertitle\ \thesopchapternumber}
\mytheposttitle{\par\end{center}\vskip 0.5em}
}
%.... a page N of M section (which works)
% For easier customization of itemized, enumerated, and other lists
\RequirePackage{enumitem}
% For hyperlinked cross-references
\RequirePackage{hyperref}
% Ensure first page is correct style
\thispagestyle{plain}
% That's all, folks!
\endinput

它被喂食的是:

\documentclass[10pt]{sop}
%
% SOP Standard Form Data
\sopchaptertitle{This is my procedure title}
\sopchapternumber{this is my procedure number D.4}
%...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}

我收到了这些错误:

(/usr/share/texmf/tex/latex/oberdiek/rerunfilecheck.sty)))
! Missing = inserted for \ifnum.
<to be read again> 
                   M
l.4 \sopchaptertitle
                    {this is my procedure title}
? 
! Missing number, treated as zero.
<to be read again> 
                   M
l.4 \sopchaptertitle
                    {this is my procedure title}
? 

(/usr/share/texmf/tex/generic/oberdiek/gettitlestring.sty)) (./sop-test.out)
(./sop-test.out)
! Undefined control sequence.
\HyOrg@maketitle ->\mythepretitle 
                                  {\setlength {\droptitle }{12.0cm}\begin {c...
l.15 

? 
! Extra }, or forgotten \endgroup.
\HyOrg@maketitle ...12.0cm}\begin {center}\LARGE }
                                                   \mythetitle     {\thesopchapt...
    l.15 

? 
! Undefined control sequence.
\HyOrg@maketitle ... {center}\LARGE } \mythetitle 
                                                  {\thesopchaptertitle \ \th...
l.15 

? 
! Undefined control sequence.
\HyOrg@maketitle ...apternumber } \mytheposttitle 
                                                  {\par \end {center}\vskip ...
l.15 

? 
! Missing } inserted.
<inserted text> 
                }
l.15 

? 

支架看起来很平衡,除此以外一切droptitle似乎都正常。

有人可以解释一下为什么droptitle它不起作用吗?

答案1

问题在于,它\mythepretitle被调用但从未被给出定义。

根据中的代码sop.cls,你有

\let\oldpretitle\pretitle
\renewcommand{\pretitle}[1]{\oldpretitle{#1}\newcommand{\mythepretitle}{#1}}

但你永远不会

\pretitle{something}

so\mythepretitle从未被定义,尽管您想在 中使用它\maketitle

不清楚你为什么想要 的精确副本\pretitle。在titling.sty我们发现

\newcommand{\pretitle}[1]{\def\@bspretitle{#1}}

因此,在使用\maketitle它时,它将在正确的位置使用参数,请参阅的定义\maketitle。但是您正在重新定义\maketitle自己,因此加载titling变得完全无用,并且使用\pretitle而不是\mythepretitle将不执行任何操作。


使用您提供的功能titling可以更轻松地实现您的结果:

sop.cls

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sop}

% 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}}

% 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    

%.... a page N of M section (which works)
% For easier customization of itemized, enumerated, and other lists
\RequirePackage{enumitem}
% For hyperlinked cross-references
\RequirePackage{hyperref}
% Ensure first page is correct style
\thispagestyle{plain}
% That's all, folks!
\endinput

如果我们将其与您的最小示例一起使用,我们会得到以下结果

在此处输入图片描述

可能需要调整落差,同时考虑到顶部边距、头部高度和头部分离。如果您希望距离顶部纸张边距恰好 12 厘米,可能

 \setlength{\droptitle}{\dimexpr 12cm-0.75in-\headheight-\headsep\relax}

就是您所需要的。

相关内容