How do you extend article document class in LaTeX?

前端 未结 3 515
执念已碎
执念已碎 2021-02-04 07:40

I don\'t really need a lot of changes to the default article document class. All I want is:

  • redefine page margins (I want them to be the same on all pages, but dif
相关标签:
3条回答
  • 2021-02-04 07:53

    You start with

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

    and add any customizations after that.

    UPDATE: I recommend you to read LaTeX2e for class and package writers: PDF, HTML. The examples in Section 3 (The structure of a class or package) should be helpful.

    0 讨论(0)
  • 2021-02-04 07:55

    There are a number of packages that can help you achieve the results you're looking for. The packages I've selected below are the ones I like, but there is more than one way to do it.

    \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
    

    You'll want to read the documentation for the geometry package to adjust the margins. The titlesec package can be used if you want to modify the appearance of the headings (aside from just turning off the numbers).

    The titlepage is LaTeX's default title page. You'll need to modify it to add your company name and logo. I've separated out the "stuff to be printed" from all the other code associated with the title page. You should only need to change the \maketitlepage command. In your document, use \maketitle to print the title page.

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

    Let me know if I missed any of your requirements.

    0 讨论(0)
  • 2021-02-04 08:15

    A couple of points that might be interesting:

    • You can redefine the margins in the header (i.e. before \begin{document}} by reseting the controlling lengths like \setlength{\textwidth}{6.80in}, \setlength{\oddsidemargin}{0.0in} and so on.

    • \section*{...} will give you un-numbered sections already. Likewise for \subsection* and \subsubsection*. If you do use this trick and also want working references, you might have a look at How do I emit the text content of a reference in LaTeX?.

    • Have you looked at the titlepage environment?

    But perhaps most important, the memoir class may give you all the control you need without any class hacking. Check out the documentation.

    Or use Can Berk Güder's suggestion.

    0 讨论(0)
提交回复
热议问题