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?

3
  • To answer 1) the normal \maketitle macro resets all of these macros: \global \let \@author \@empty \global \let \@date \@empty \global \let \@title \@empty Sep 6, 2011 at 23:01
  • 1
    @Alan I don't think so. I did link to that other question in the answer that I gave below, but I could well imagine that someone might run into the difficulty that I did without having the interest in producing a custom title page. I added my question despite the existence of that one as mine seems to represent a distinct (way of arriving at the) problem. But, if the community disagrees, so be it :-)
    – vanden
    Sep 7, 2011 at 6:27

3 Answers 3

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}
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}
1
  • Problem is "titling" package does not seem to work with beamer class.. Feb 23 at 15:14
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.)

You must log in to answer this question.

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