41

I want to include the values of author, date, and title in my use of fancyhdr in a document that uses \maketitle. Googling about, I saw that @date, etc. can access the date, etc., values set in the document preamble. It works fine, provided \maketitle is not used. Here's a minimal working example:

\documentclass{article}

\title{Things about Stuff}
\author{Someone}
\date{Somewhen}

\begin{document}

%\maketitle  %Toggle comment and:

Now you see them, now you don't.

\makeatletter
\@date
\@author
\@title
\makeatother

\end{document}

So, 1) why does the use of \maketitle cause subsequent invocation of @date, etc. to yield nothing, and 2) how can I access the value of \date, etc after the use of \maketitle?

lockstep
  • 250,273
vanden
  • 30,891
  • 23
  • 67
  • 87

3 Answers3

34

Use the titling package, which provides \thedate, \theauthor, \thetitle even after you've called \maketitle.

It's as simple as adding the package, and instead of calling \@date you call \thedate (which also avoids requiring \makeatletter and \makeatother).

\documentclass{article}

\usepackage{titling}

\title{Things about Stuff}
\author{Someone}
\date{Somewhen}

\begin{document}

\maketitle

Now you still see them.

\thedate
\theauthor
\thetitle

\end{document}
drfrogsplat
  • 1,065
30
\documentclass{article}

\makeatletter
\title{Things about Stuff}\let\Title\@title
\author{Someone}          \let\Author\@author
\date{Somewhen}           \let\Date\@date
\makeatother

\begin{document}

\maketitle 

Now you see them
\Date
\Author
\Title

\end{document}
13

Checking this site before I posted this question, I saw that this earlier question yielded the answer "use the titling package". That seems to work. But, I'd also come up with putting

\newcommand{\setdocdata}{
\title{Things about Stuff}
\author{Someone} 
\date{Somewhen}
}
\setdocdata{}

in my preamble and then using

\maketitle\setdocdata

which works, too, and might appeal to those who prefer to use as few packages as necessary.

(I still would like to know why, for the love of puppies, \maketitle was coded to blank the date, etc values.)

vanden
  • 30,891
  • 23
  • 67
  • 87