如何在LaTeX中扩展文章文档类?

15

我并不需要对默认文章文档类进行太多更改,我只希望:

  • 重新定义页面边距(我希望它们在所有页面上都相同,但与默认值不同);
  • 使用标题页;
  • 在标题页上添加更多元素(对于我来说,标题作者日期不足够,我还想在标题页上加上公司和公司的标志);
  • 更改章节子章节子子章节的样式(我不希望显示号码,否则-它们很好)。

也许有一些包可以在这种情况下有所帮助?

3个回答

16

有许多软件包可以帮助您达到所需的结果。我选择的软件包是我喜欢的,但有不止一种方法。

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{paulius-article}[2009/02/25 v0.1 Paulius' modified article class]

% Passes and class options to the underlying article class
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions

% Load LaTeX's article class with the `titlepage' option so that \maketitle creates a title page, not just a title block
\LoadClass[titlepage]{article}

% Redefine the page margins
% TODO: Adjust margins to your liking
\RequirePackage[left=1in,right=1in,top=1in,bottom=1in]{geometry}

% Remove the numbers from all the headings (\section, \subsection, etc.)
\setcounter{secnumdepth}{-1}

% To modify the heading styles more thoroughly use the titlesec package
%\RequirePackage{titlesec}

% Adjust the title page design
% NOTE: This is the default LaTeX title page -- free free to make it look like whatever you want.
% TODO: Add company name and logo somewhere in here.
\newcommand{\maketitlepage}{%
  \null\vfil
  \vskip 60\p@
  \begin{center}%
    {\LARGE \@title \par}%
    \vskip 3em%
    {\large
     \lineskip .75em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
      \vskip 1.5em%
    {\large \@date \par}%       % Set date in \large size.
  \end{center}\par
  \@thanks
  \vfil\null%
  \end{titlepage}%
}

% This some before-and-after code that surrounds the title page.  It shouldn't need to be modified.  
% I've pulled out the part the actually typesets the title page and placed it in the \maketitlepage command above.
\renewcommand\maketitle{\begin{titlepage}%
  \let\footnotesize\small%
  \let\footnoterule\relax%
  \let \footnote \thanks%
  \maketitlepage%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}

% TODO: If there are any other article modifications required, add them here.

% That's all, folks!
\endinput

您需要阅读geometry包的文档来调整边距。如果要修改标题的外观(除了关闭编号),可以使用titlesec包

LaTeX的默认标题页是titlepage。您需要修改它以添加公司名称和标志。我已将“要打印的内容”与与标题页相关的所有其他代码分开。您只需要更改\maketitlepage命令即可。在您的文档中,使用\maketitle打印标题页。

\documentclass{paulius-article}

\title{My New Document Class}
\author{Paulius}

\usepackage{lipsum}% provides some filler text

\begin{document}
\maketitle% Actually makes a title page

\section{Section Heading}
\subsection{Look no numbers!}
\lipsum[1-10]

\end{document}

如果我漏掉了您的任何要求,请告诉我。


10

你从这里开始

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{classname}[2009/02/24]
\LoadClass{article}

然后加入任何自定义内容。

更新:我建议你阅读LaTeX2e用于类和包的编写者:PDFHTML。第3节中的例子(类或包的结构)应该是有帮助的。


我已经做到了这一步,甚至有一堆\setlength{..},但似乎对我没有用。你有什么好的注释扩展可以分享吗?也许有某个链接? - Paulius
1
好链接。我跟那个东西睡了一个星期,试图让我的论文符合边距要求... - dmckee --- ex-moderator kitten
@dmckee:那些边缘女士们... =) - Can Berk Güder

6
一些可能有趣的要点:
  • 您可以通过重置控制长度(例如\setlength{\textwidth}{6.80in}\setlength{\oddsidemargin}{0.0in}等)在页眉中(即在\begin{document}之前)重新定义边距。

  • \section*{...}将为您提供未编号的章节。同样适用于\subsection*\subsubsection*。如果您使用此技巧并且还希望工作参考文献,则可以查看如何在LaTeX中发出引用的文本内容?

  • 您是否看过titlepage环境?

但也许最重要的是,memoir类可能会给您提供所有所需的控制,而无需进行任何类别的修改。请查看文档

或者使用Can Berk Güder的建议


好的,我只是浏览了一下,但它看起来非常有前途。 - Paulius

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接