43

I am wondering how I can get the document title in LaTex, for use elsewhere in the document. I just want to be able to echo it.

3
  • I'm sure there's a way of having the header of every page have the title in it. With fancyhdr or the memoir document class. So those files will contain an answer. I don't know enough to extract the info though... (I just searched fancyhdr.sty for "title" and got no hits, though...)
    – Seamus
    Commented Mar 27, 2010 at 23:58
  • 5
    How is this not a real question? The answer is \makeatletter \@title \makeatother. Commented Jun 4, 2014 at 3:50
  • 4
    Indeed. If there's any problem with this question it's that it should be moved to the tex stack exchange site.
    – nedned
    Commented Jun 4, 2014 at 8:49

4 Answers 4

31

Using \@title does not work because \maketitle clears \@title. This seems silly to me but that's the way it is. One solution is to redefine \title to save the title somewhere else. For instance,

\def\title#1{\gdef\@title{#1}\gdef\THETITLE{#1}}

then use \THETITLE.

You can do the other way around: \def\MYTITLE{...} then \title{\MYTITLE} and later use \MYTITLE again.

2
  • 2
    Thanks, that did the trick, although I had to enclose the define in \makeatletter and \makeatother, which starts to be a whole lot of effort. So since I only need to use the title one other time, there's not much point. It'd be nice if there were a more sensible solution.
    – nedned
    Commented Mar 28, 2010 at 9:36
  • 3
    This should be in tex.stackexchange.com. This didn't work for me. I needed to use \title{My Title} \makeatletter \let\thetitle\@title \makeatother And then use \thetitle later in the text.
    – gone
    Commented Mar 26, 2016 at 15:33
25

I had success just writing a new command.

\newcommand{\mytitle}{...}

\title{\mytitle}
0
8

There is a package called authoraftertitle that does exactly this

\documentclass{article}
\usepackage{authoraftertitle}
\setlength\parindent{0 pt}

\begin{document}

\title{a good title}
\author{a better author}
\date{the best date}

\maketitle

the title is: \textbf{\MyTitle} \\
the author is: \textbf{\MyAuthor} \\
the data is: \textbf{\MyDate} \\

\end{document}
4

This is a workaround...

\let\titleoriginal\title           % save original \title macro
\renewcommand{\title}[1]{          % substitute for a new \title
    \titleoriginal{#1}%               % define the real title
    \newcommand{\thetitle}{#1}        % define \thetitle
}

\title{This is my title}

\begin{document}
\thetitle
\end{document}

The short version of the title was ignored here...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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