.sty package, or a .cls document class. Start at the lowest level that does the job and move up only when you need to.
Level 1: Customize the Preamble
article, report and book are more customizable than they look. titlesec (section styling), fancyhdr (headers and footers) and geometry (margins) cover most “we want our own look” requirements:
customized-article.tex
Ready to use this syntax? Continue in the browser editor when you want to adapt the example in a real project.Open LaTeX Cloud Studio
If only one or two documents need this look, stop here. A preamble is the easiest level to understand, debug and hand to a co-author.
Level 2: Move the Preamble into a .sty Package
When the same preamble appears in a second document, move it into a package:
groupstyle.sty
\documentclass{article} and \usepackage{groupstyle}. Inside package files, use \RequirePackage instead of \usepackage, and give \ProvidesPackage a date so LaTeX can report version mismatches. A package builds on a standard class, so everything written for article keeps working. For most teams this is the right stopping point; see Create a LaTeX package for more.
Level 3: Write a .cls Document Class
Write a class when you need to change what the document is (its title layout, sectioning model or default structure), not only its styling.
Minimal Class Skeleton
myreport.cls
Usage
class-usage.tex
Forward Options and Override the Title
A class that builds onarticle follows one pattern: declare the class, forward unknown options to the base class, load the base class, then override what must change. This class reuses the Level 2 package and replaces \maketitle:
groupreport.cls
using-class.tex
article with \LoadClass means you inherit its tested behavior and maintain only your differences. Writing a class from scratch is rarely the right call.
Practical Rules
\makeatletterand\makeatotherare only needed in documents. Inside.styand.clsfiles,@is already a letter, so commands such as\@titlework directly.- Date the
\ProvidesClassline and update it on every change, so you can tell which class version produced a PDF. - Keep content out of the class. A class defines how documents look, not what they say. Boilerplate text belongs in a template document.
- Ship the class with the documents. Put the
.clsfile in the project, or in a shared Git repository, instead of a localtexmftree. TeX finds files in the project folder first, so every collaborator and every CI build compiles with the same class.
