I made a layout in LaTeX (geometry, margins, headers, etc) and I need to have multiple different documents using that same layout. So I wonder if instead of copy-pasting the 'layout part' of the code I could create something like a template and use it on every document I have.

I've searched for a while but couldn't find anything useful on that. Is it possible? And, if so, how can it be done?

  • 2
    Put the definitions into a file mylayout.sty and include it in the preamble of your documents as \usepackage{mylayout}.
    – gernot
    Jan 27, 2017 at 22:16
  • 1
    Put all of your layout (not typesetting) etc. in a telmovianavaz.sty file and say \usepackage{telmovianavaz} in your documents. That is what .sty files are meant for (amongst other things)
    – user31729
    Jan 27, 2017 at 22:16
  • You may create a preamble.tex and put \input{preamble.tex} in all your document or, for more complex features, you may also create your own class: sharelatex.com/learn/Writing_your_own_class.
    – CarLaTeX
    Jan 27, 2017 at 22:24
  • @Christain Hupfer: As it's for the general layout, wouldn't it be more judicious to make a personal classfile?
    – Bernard
    Jan 27, 2017 at 22:25
  • @Bernard... Sure, but not so easy for inexperienced users, is it?
    – user31729
    Jan 27, 2017 at 22:37

1 Answer 1


There is a good introduction LaTeX for class and package writers with a lot of information about that theme.

As stated in the comments, you could write your own style file or even class.

I can only guess, what would be an appropriate choice for you, but I guess, you targeting for your own style file.

This is a more ore less useless empty style. Feel free to fill it with your preamble. Of course, you don't need those extensive comments at the top of your file, but remember: its better to document your ideas, than ...

This style must be saved as empty.sty. Of course you should give your style a more verbatim name. But if you change the name of the file, be sure, to change this name in the file also, especially in the command \ProvidesPackage. Otherwise LaTeX will throw an error.

I defined a new boolean variable @draft. It is set by using the style option draft or final: \usepackage[draft]{empty} would define draft mode.

This option is handed over to the graphicx-package, which is loaded by this style. (In your case: geometry and so on.) Also be careful: instead of calling \usepackage, you have to say \RequirePackage.

You can also define some commands and even use the defined boolean variable, as I have shown at the end of this file.

EDIT: one final word where to store the file. In general it would be a wise idea, to store somewhere, where LaTeX searches and finds tex-files. Meanwhile, I favor TeXLive, so my suggestions are TeXLive related. TeXLive distinguishes between three locations on your filesystem, where TeX- and LaTeX-inputs may be stored:

  1. The main directory, where the distributors collect all the files, they put into their distribution. TeXLive stores the path to this location in either $TEXMFMAIN or in $TEXMFDIST.
  2. There is a second location, which is dedicated to the manager of a site wide TeXLive installation. In this location the manager can store the templates, styles, fonts and such, that are related to their company. TeXLive stores the location in $TEXMFLOCAL.
  3. Finally, there is a location dedicated to the individual user. In this location YOU can store your private extensions, including my empty.sty. :-) TeXlive stores the path in $TEXMFHOME.

These three locations have been established in those good old days (tm) and are strongly influenced from networked UNIX-systems, where it was quite usual, to have one TeX-installation for the complete company/university/... with hundreds of machines and thousands of possible users.

Nowadays with our personal PCs, there is no real need, to distinguish between site wide installation by the sysadmin and private files of the user, as in most cases, the user is identical with the system administrator.

Nevertheless, there is still one thing, worth mentioning. LaTeX makes heavily usage of a lot of files. It would dramatically increase the system- and especially the IO-load, if LaTeX would search directly on the filesystem and would therefore recursively walk through all the thousands of directories over and over again, just in order to find your empty.sty. To protect the system from this labour, TeXLive maintains databases of installed files and tries to look up the location of a certain file in one of these databases in favour of painfully searching directly on the file system. At least all files in $TEXMFMAIN, $TEXMFDIST and $TEXMFLOCAL should be inserted into their according databases. You can update the databases by running texhash or mktexlsr.

Given the fact, that a) there are lots of users, for whom an individual database had to be maintained, and b) a user usually don't have a lot of different TeX input files, TeXlive is usually set up, to search $TEXMFHOME on the filesystem instead of having a database.

Alas, after having copied the empty.sty to your desired location, you can check, if your TeX-system will find the style by executing

kpsewhich tex empty.sty

kpsewhich should print the correct location of your file.

If it doesn't, you have eventually forgotten to update the database or placed the file in the wrong location.

One final final word. To maintain some order in the otherwise sheer chaos of thousands of files, that belong to a full grown TeX installation, maintainers and distributors have long ago agreed on a unique scheme, the so called TDS, the TeX Directory Structure. Read that manual, to get an impression how to spread your files in the desired location. (HINT: it should be $TEXMFHOME/tex/latex/telmovianavaz/empty.sty.)

(I also corrected the typo Christian Hupfer found. Thank you Christian!)

%%% @(#) empty.sty -- emty style example
%%% Time-stamp:  <2017-01-28 00:45:49 tmjb>
%%% @(#)       $Id: $
%%% @(#) $Keywords: emty, style for TeX.SE $
%%%           File: /Users/tmjb/Desktop/LaTeX-Test/empty.sty
%%%        Project: TeX.SE
%%%    Description: This is an empty style file, just to answer a
%%%                 question at TeX.SE
%%%        Version: $Revision:  $
%%%         Author: tmjb -- Jan Braun <braun@somewhe.re>
%%%     Maintainer: tmjb -- Jan Braun <braun@somewhe.re>
%%%  Creation-Date: Sat Jan 28 2017 -- Jan Braun <braun@somewhe.re>
%%%      Copyright: (c) 2017 Jan Braun

%%% ------------------------------------------------------ &Change Log ---
%%% $Log: $

%%% ============================================================ &Code ===

%%% ---------------------------------------------------- &Package Name ---
% \NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{empty}[2017/01/28 TeX.SE emty style example V 0.1.1]

%%% ------------------------------------------------------- &Variables ---
%% We need some variables, to store and indicate which options (see
%% later) are choosen ...
\newif\if@draft                 % for Option draft

%%% --------------------------------------------------------- &Options ---
%% Options are definid by the main package or for this special style
%% file.  Just add them in square brackets like this:
%% \usepackage[final,foo,bar]{empty}
%% I advise, to avoid using final and draft in package related
%% options, as the are normally handed over from the main class
%% package options.
%% ............................................................ &draft ...
%% Option final is per default defined by the main class package,
%% unless you specify draft.  This style defines it for continuity
%% reasons.  Draft and final should be  mutualy exclusive

%% ............................................................ &final ...
%% Option final is per default defined by the main class package,
%% unless you specifyraft.  This style defines it for continuity
%% reasons.  Draft and final should be mutualy exclusive

%% ....................................................... &Undeclared ...
%% This one is for any option, which was not declared before.
%% Set the options.

%%% -------------------------------------------------------- &Messages ---
%% Print out some warning messages, while compiling the text.
  \typeout{\MessageBreak empty.sty: WARNING! DRAFT-mode is in use! \MessageBreak }

%%% -------------------------------------------------------- &Packages ---
%% To get all definitions of this style to work, we need some more
%% packages.  They are automatically loaded here.

%%% ------------------------------------------------------ &Definitions ---

%%% ........................................................ &Constants ...
%%% Define some consistent strings.
%%% Userspace command, to change the value of the above defined string.

%% Define a command, to print nonsense, but only in draft mode.
   \newcommand{\foo}[1][bar]{foo #1 baz}
   \typeout{\MessageBreak empty.sty: WARNING! FINAL-mode is in use! \MessageBreak } 

%%% ============================================================= &EOF ===

%%% Local Variables:
%%% mode: LaTeX
%%% TeX-engine: luatex 
%%% TeX-master: nil
%%% TeX-parse-self: t
%%% TeX-auto-save: t
%%% End:
  • 1
    There's a typo: fina instead of final in \DeclareOption{fina}{...}. And perhaps like a Holzhammer ;-)
    – user31729
    Jan 27, 2017 at 23:59
  • There's another in the banner. empty claims it is emty.
    – cfr
    Jan 28, 2017 at 0:40
  • 1
    Wouldn't it be better to use the global option draft?
    – Johannes_B
    Jan 28, 2017 at 7:35
  • @ChristianHupfer thank you: corrected in my file template as well in this answer.
    – Jan
    Jan 28, 2017 at 8:20
  • 1
    A draft option is provided by the standard classes and will also be passed to packages.
    – Johannes_B
    Jan 28, 2017 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.