创建标题页:package .sty

创建标题页:package .sty

我想.sty为标题页创建一个包()。我遵循了本指南https://en.wikibooks.org/wiki/LaTeX/Title_Creation从中我得到了以下两个代码:第一个代码是名为的包columbidaeTitle.sty,第二个代码是加载先前创建的包的文档。

哥伦比亚Title.sty

% Copyright note: This package defines how titles should
% be typeset at the columbidae University
% Please check for updates
\ProvidesPackage{columbidaeTitle}[2015/08/10 v.01 an
example package^^J for wikibooks]
\RequirePackage{graphicx}
\newcommand*{\project}[1]{\gdef\@project{#1}%
}
\newcommand*{\@project}{Final Year Project}
\newcommand*{\supervisor}[1]{\gdef\@supervisor{#1}%
}
\newcommand*{\@supervisor}{\texttt{\string\supervisor} currently
not set. Please fix this.}
\renewcommand*{\maketitle}{%
\begin{titlepage}
{\raggedleft%
    \includegraphics[width=3cm]{example-image-16x9}\par
}\vspace{1cm}
    \centering
{\scshape\LARGE Columbidae University \par}
\vspace{1cm}
{\scshape\Large\@project\unskip\strut\par}
\vspace{1.5cm}
{\huge\bfseries\@title\unskip\strut\par}
\vspace{2cm}
{\Large\itshape\@author\unskip\strut\par}
\vfill
supervised by\par
\@supervisor\unskip\strut\par

\vfill

{\large \@date\par}
\end{titlepage}
}
\endinput

文档:

\documentclass{book}
\usepackage{columbidaeTitle}
\supervisor{Dr. James Miller}
\project{Bachelor Thesis}
\author{A LaTeX enthusiast}
\title{Why i want to be a duck}

\begin{document}
\maketitle
\tableofcontents
\chapter{Ducks are awesome}
\end{document}

我有一个问题。我希望整个文档都有这个边距:

\usepackage[bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm]{geometry}

除了扉页,我希望

\newgeometry{left=3cm,right=3cm,bottom=2cm,top=3cm}

我尝试插入\RequirePackage{geometry}文件columbidaeTitle.sty然后

\newgeometry{left=3cm,right=3cm,bottom=2cm,top=3cm}
\begin{titlepage}
...
\end{titlepage}
\restoregeometry

但它不起作用。我该怎么做?

答案1

只需有条件地加载即可geometry。当然,文档应该明确说明该包必须如果使用此包,则在之后加载geometry。可以添加对此的测试。

columbidaeTitle.sty

% Copyright note: This package defines how titles should
% be typeset at the columbidae University
% Please check for updates

\ProvidesPackage{columbidaeTitle}[2015/08/10 v.01 an example package^^J for wikibooks]
\RequirePackage{graphicx}

\@ifpackageloaded{geometry}{}{\RequirePackage[pass]{geometry}}

\newcommand*{\project}[1]{\gdef\@project{#1}}
\newcommand*{\@project}{Final Year Project}
\newcommand*{\supervisor}[1]{\gdef\@supervisor{#1}}
\newcommand*{\@supervisor}{\texttt{\string\supervisor} currently not set. Please fix this.}
\renewcommand*{\maketitle}{%
  \begin{titlepage}
  \newgeometry{left=3cm,right=3cm,bottom=2cm,top=3cm}
  {\raggedleft\includegraphics[width=3cm]{example-image-16x9}\par}
  \vspace{1cm}
  \centering
  {\scshape\LARGE Columbidae University \par}
  \vspace{1cm}
  {\scshape\Large\@project\unskip\strut\par}
  \vspace{1.5cm}
  {\huge\bfseries\@title\unskip\strut\par}
  \vspace{2cm}
  {\Large\itshape\@author\unskip\strut\par}
  \vfill
  supervised by\par
  \@supervisor\unskip\strut\par
  \vfill
  {\large \@date\par}
  \end{titlepage}
}
\endinput

test.tex

\documentclass{book}

\usepackage[bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm,showframe]{geometry}

\usepackage{columbidaeTitle}
\supervisor{Dr. James Miller}
\project{Bachelor Thesis}
\author{A LaTeX enthusiast}
\title{Why i want to be a duck}

\begin{document}
\maketitle
\tableofcontents
\chapter{Ducks are awesome}
\end{document}

输出

在此处输入图片描述

如果删除了geometryin的调用,则输出test.tex

在此处输入图片描述

相关内容