TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I insert the title in the footer? And decide if it is set or not?


     {No \protect\title\space given}
     {You have to provide a title}%
   \gdef\mytitle{You have to provide a title}%

See the error if no define \title and no use \maketitle


% \title{Title}
% \author{R\'egis S. Santos}
% \date{\the\year}

% \maketitle


fix my code, please.

share|improve this question
up vote 7 down vote accepted

After \maketitle the title is forgotten. By the way, \title wouldn't print the title anyway: it's a command for declaring what the title is.


If you need it in a package, then redefine \title:


This duplication will allow you to say normally

\author{A. U. Thor}

in the document.

If you want to raise an error if the author doesn't provide a \title declaration, add to your package

   \PackageError{preteste}% use the package name
     {No \protect\title\space given\@gobble}
     {You have to provide a title}%
   \gdef\mytitle{You have to provide a title}%

After raising the error, it will redefine itself to print an informative message in the footer. The \title declaration in the document will clear this definition, so there's nothing to worry about.

The titling package can be used, but maybe it's too much for this simple application.

share|improve this answer
I've used this method, but I put the \fancyfoot[C]{\title} a file.sty, then it will not work. Do you have any other suggestions? – Regis da Silva Oct 9 '11 at 23:28
Read egreg's answer more carefully: you need to put fancyfoot[C]{\mytitle} not \title. – Alan Munn Oct 10 '11 at 0:50
Also make sure that you load your file.sty after you have loaded the fancyhdr package, and after you have defined \mytitle – cmhughes Oct 10 '11 at 1:34
Thanks egreg, but how to verify \ifdefined\@title or similar, if the title is not set. – Regis da Silva Oct 10 '11 at 22:29
@RegisdaSilva See edited message – egreg Oct 10 '11 at 23:15

I think an easy solution involves the following instructions in the document's preamble after the \title, \author, and \date commands have been set up:


You can then insert the title string in the footer as follows:


Finally, if you want to put all of this stuff in a package, be sure to invoke this package only after the \title has been set up and the fancyhdr package has been loaded. Happy TeXing!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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