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.
You can define a title for your document using \title{} and then create the title itself using \maketitle . You can also add other information such as the author(s) and the date, e.g. Note the use of \today to automatically insert the date you created the document. Of course you can just write a date if you prefer!
The \maketitle command generates a title on a separate title page - except in the article style, where the title normally goes at the top of the first page.
\maketitle. This command will print the title, the author and the date in the format shown in the example. If it's not enclosed in a titlepage environment, it will be shown at the beginning of the document, above the first line. Open an example in Overleaf.
If you want to center some text just use \centering . If you want to align it differently you can use the environment \raggedleft for right-alignment and \raggedright for left-alignment.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With