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.


2 Answers 2


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.

  • 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? Commented Oct 9, 2011 at 23:28
  • 1
    Read egreg's answer more carefully: you need to put fancyfoot[C]{\mytitle} not \title.
    – Alan Munn
    Commented Oct 10, 2011 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
    Commented Oct 10, 2011 at 1:34
  • Thanks egreg, but how to verify \ifdefined\@title or similar, if the title is not set. Commented Oct 10, 2011 at 22:29
  • @RegisdaSilva See edited message
    – egreg
    Commented Oct 10, 2011 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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .