自定义包中的标题页选项

自定义包中的标题页选项

我已经制作了自己的包,它加载了一些包并使用以下内容设置了自定义标题页

% Title and author
\makeatletter
\def\@maketitle{%
  \newpage
  %\vspace{-\topskip}      % remove the initial space

  \vskip 6em
   \begin{flushleft}Incomplete draft. Please do not cite or quote without premission \end{flushleft}
  \vskip 6em
  {}
  \begingroup    % instead of \begin{center}
  \begin{flushleft}
  \let \footnote \thanks
  \hrule height \z@        % to avoid the insertion of lineskip glue
    {\LARGE \protect\textbf{\@title} \par}%
    \vskip 2.5em
    {\large
      \lineskip .5em

        \@author
        \par}%
    \vskip 1.5em
    {\small
      \@date}
  \end{flushleft}
  \par\endgroup            % instead of \end{center}
  \vskip 6em             % <--- modify this to adjust the separation
}
\makeatother

我希望能够仅在加载带有“起草”选项的包时才显示有关“草稿不完整”的注释。我尝试使用

  \DeclareOption{drafting}{
  \vskip 6em
   \begin{flushleft}Incomplete draft. Please do not cite or quote without premission \end{flushleft}
  \vskip 6em
  }
  \DeclareOption*{\PackageWarning{faden}{Unknown ‘\CurrentOption’}}
  \ProcessOptions\relax

但这并不管用

我把 MWE 放在下面

\documentclass{article}
\usepackage[utf8]{inputenc}


\usepackage[top=2.5cm, bottom=2.5cm, left=3.5cm, right=3.5cm]{geometry} %Margins

% Title and author
\makeatletter
\def\@maketitle{%
  \newpage
  %\vspace{-\topskip}      % remove the initial space
  \vskip 6em
   \begin{flushleft}Incomplete draft. Please do not cite or quote without premission \end{flushleft}
  \vskip 6em
  {}
  \begingroup    % instead of \begin{center}
  \begin{flushleft}
  \let \footnote \thanks
  \hrule height \z@        % to avoid the insertion of lineskip glue
    {\LARGE \protect\textbf{\@title} \par}%
    \vskip 2.5em
    {\large
      \lineskip .5em

        \@author
        \par}%
    \vskip 1.5em
    {\small
      \@date}
  \end{flushleft}
  \par\endgroup            % instead of \end{center}
  \vskip 6em             % <--- modify this to adjust the separation
}
\makeatother

% Author and title
\title{Test}
\author{Namesen}
\date{\today} % no date

\begin{document}
\maketitle
\section{Title}
\label{sec:title}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\end{document}

答案1

这是一个相当基本的方法:

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesClass{myclass}[2015/03/16 v0.0001 For example]

% Condition
\newif\if@drafting
\def\maybedraft{%
  \if@drafting
   \begin{flushleft}
     Incomplete draft. Do not read; do not believe.
   \end{flushleft}
   \else
   Full draft. Enjoy!
   \fi}

\DeclareOption{drafting}{\@draftingtrue}

\ProcessOptions\relax
\LoadClass[]{article}[1994/06/01]


% Title and author
\def\@maketitle{%
  \newpage
  %\vspace{-\topskip}      % remove the initial space

  \vskip 6em

  \noindent
  \maybedraft

  \vskip 6em

  \begingroup    % instead of \begin{center}
  \begin{flushleft}
  \let \footnote \thanks
  \hrule height \z@        % to avoid the insertion of lineskip glue
    {\LARGE \protect\textbf{\@title} \par}%
    \vskip 2.5em
    {\large
      \lineskip .5em

        \@author
        \par}%
    \vskip 1.5em
    {\small
      \@date}
  \end{flushleft}
  \par\endgroup            % instead of \end{center}
  \vskip 6em             % <--- modify this to adjust the separation
}

以及.tex文件:

\documentclass[drafting]{myclass}
%\documentclass[]{myclass}
\usepackage[T1]{fontenc}

\title{Test}
\author{Namesen}
\date{\today}

\begin{document}

\maketitle
\section{Title}
\label{sec:title}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\end{document}

相关内容