I'm a Canadian based in Berlin, Germany. My day job is a Technical Writer in the API space. I write about topics such as technology, usability, creative writing and Canadian history. All views mine. I tweet at @glennjlea. Read more about me here or at LinkedIn.
Site version: 3.0

Creating LaTeX Stylesheets

Using a stylesheet makes it easy to keep in one place all the styles used by the document. Stylesheets are a useful method of organizing all the styles used throughout your LaTeX project. You could also have a single stylesheet file, stylesheet.sty for example, that is used across multiple projects.

The key development effort to create high-quality technical documentation is in the stylesheet. This took a considerable amount of time to develop. Getting it right is critical for the quality of the documentation.

Note: The upcoming topics will refer to the stylesheet frequently. You define the style then you need to implement it in the document.

## Why Use Style Sheets?

You could put all your styles in the head of each .tex file in your project but that makes no sense, especially if you have multiple files referring to the same style sheet.

Furthermore, keeping all your styles in a single file makes maintaining the styles vastly easier. For example, you could comment out particular commands, especially commands that include chapters, to help you during your development process.

You could also comment out chapters that are specific to outputs. I am sure there are other ways of doing this, but for me, simplicity is key, so commenting out of a command or include works.

Another useful way you could use stylesheets is to include examples of how to use a particular style (commented out, of course).

## Using a stylesheet subdirectory

For my LaTeX projects, I created a subdirectory called \styles, not surprisingly, and I placed in this directory a single style sheet called mystyles.sty. If more than one stylesheet is needed, you could place them in this subdirectory. You could also have several stylesheets for specific outputs and just comment out the unneeded stylesheet in the root file.

Here is an example project structure. Notice the \styles directory.

Project Root
├── manual-ROOT.tex        # document root file
├── \styles                # stylesheet subdirectory
├── \chapters              # subdirectory to store all chapters
├── \append                # subdirectory to store any appendices
├── \images                # subdirectory for shared images


## Including the stylesheet in the root file - main.tex

To use the stylesheet in your project, you simply include a command in the root file main.tex immediately following the \documentclass command but before the \begin{document} command.

Here is an example snippet from a main.tex file.

## Example stylesheet

Here is a segment of an example stylesheet I used. I kept all related styles together within sections in the stylesheet using comments. I shortened the comments to make the stylesheet easier to read.