1

I am doing documentation for my company i.e. writing countless documents which uses the same referred preamble in a file for itself.

The preamble is over 500 lines, so I want to avoid posting it here.

My only question is, when defining the document title in the documents, and defining the preamble in another file for itself, how do i display the title in the header? Not any sections, but the title itself.


Expanding on @Gunter's answer:

Some MWE:

\documentclass[11pt,norsk, fleqn, leqno]{extarticle}
\usepackage[a4paper, left=0.6in,right=0.6in,top=0.6in,bottom=0.9in,includeheadfoot]{geometry}
\usepackage{fancyhdr}

\makeatletter \edef\mytitle{@title} \makeatother

\lhead{picture} \chead{\mytitle} \rhead{\parbox[t]{2cm}{\hfill Side \thepage}}

\begin{document} \textbf{\title{\LARGE A title of something}} \maketitle

Test text.

\end{document}

When running this code I get the same error as in my other documents with the long preamble. Namely:

Undefined control sequence. [\edef\mytitle{\@title]
E. l4d3
  • 697

2 Answers2

3

Following the solution here: Use the values of \title, \author and \date on a custom title page, the following should work.

edit: the \title-command does not print the title. It merely defines it. And indeed, it needs to be defined, before it is safed in the \mytitle-macro. The command \maketitle is responsible for setting of the title page. I had to remove the \LARGE part from your title, because this caused errors. But I think this is a separate topic how to adjust the size of the title at the title page.

edit2: actually with a second \title-command referencing \mytitle you could adjust the size or the font style of your title, without the need to type the actual title twice.

\documentclass[11pt,norsk, fleqn, leqno]{extarticle}
\usepackage[a4paper, left=0.6in,right=0.6in,top=0.6in,bottom=0.9in,includeheadfoot]{geometry}
\usepackage{fancyhdr}

\title{A title of something} \author{N.N.}

\makeatletter \edef\mytitle{@title} \makeatother

\lhead{picture} \chead{\mytitle} \rhead{\parbox[t]{2cm}{\hfill Side \thepage}}

\begin{document} \pagestyle{fancy}

\title{\LARGE{\textbf{\mytitle}}}

\maketitle

\clearpage

Test text.

\end{document}

Gunter
  • 443
  • Are you sure this should work with the order of things/commands I work? Title comes last, after the definitions in your answer, not prior to. I couldn't get this to work due to errors. – E. l4d3 Jun 07 '21 at 16:04
  • Well, for my test case it worked. Maybe you can construct a MWE. You should of course not include your 500 line preamble, but the minimum set of packages to reproduce the issue (the original one and now the errors). Did you copy the \makeatletter and \makeatother part as well? This is important for the \@title to work. – Gunter Jun 07 '21 at 16:10
  • @E.l4d3: btw, do you really use xetex or xelatex? I tested my code with LuaLaTeX and XeLaTeX. – Gunter Jun 07 '21 at 16:35
  • I use xelatex not xetex. Apologies. Editing original question now. I am also adding an MWE. – E. l4d3 Jun 07 '21 at 16:46
  • @E.l4d3: I updated my solution based on your MWE with some explanation. – Gunter Jun 08 '21 at 04:01
  • @E.l4d3: Did the updated version solve your question? – Gunter Jun 10 '21 at 18:32
1

This works:

\documentclass[11pt,norsk, fleqn, leqno]{extarticle}
\usepackage[a4paper, left=0.6in,right=0.6in,top=0.6in,bottom=0.9in,includeheadfoot]{geometry}
\usepackage{fancyhdr}%
\title{A title of something}%
\author{N.N.}%
\makeatletter
\edef\mytitle{\@title}%
\makeatother

\lhead{picture}% \chead{\mytitle}% \rhead{\parbox[t]{2cm}{\hfill Side \thepage}}% \pagestyle{fancy} \begin{document}

{\title{\LARGE\textbf{A title of something}}} \maketitle

Test text. \clearpage test text \end{document}

Somehow you need any title before the \edef of \mytitle. It adapts to the later description when you compile it.

C. Peters
  • 1,297