Dear All,
I am using the fancyhdr package to set my headers and footers in an article I am writing and I am stuck regarding the following two issues:
i) I want the left header of each page to be the running title of the document (not the section). I know this can easily be done with something like
\newcommand{\runningtitle}{Title}
\lhead{\runningtitle}
but thought that there should be a way of feeding it directly to fancyhdr without doing that - tried \lhead{\title} but nothing happened. So, is there a way to directly pass the title of the article to fancyhdr without writing any other code - could not find anything in the documentation?
ii) On some pages, there is text from two sections - is there a way to include both their nameas in the header - soemthing like Introduction and Motivation?
Thanks,
George
Page Layout ⇒ Fancyhdr Questions
Fancyhdr Questions
Hi,
for the first issue, you can use the \@title command (obviously in the preamble and inside \makeatletter...\makeatother), as the following example suggests:
for the first issue, you can use the \@title command (obviously in the preamble and inside \makeatletter...\makeatother), as the following example suggests:
Code: Select all
\documentclass{book}
\usepackage{fancyhdr}
\usepackage{lipsum}% jus to generate some text
\pagestyle{fancy}
\makeatletter
\fancyhf{}
\lhead{\@title}
\rhead{\@author}
\makeatother
\title{The title of this book}
\author{Some author}
\begin{document}
\lipsum[1-15]
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Fancyhdr Questions
I think this won't work because \maketitle clears out \@title. An easy solution is to define user commands for the title etc.:gmedina wrote:for the first issue, you can use the \@title command
Code: Select all
\newcommand*\doctitle{abc}
\newcommand*\docauthor{def}
\title{\doctitle}
\author{\docauthor}
\lhead{\doctitle}
\rhead{\docauthor}
\hypersetup{pdftitle=\doctitle, pdfauthor=\docauthor}
Fancyhdr Questions
You are absolutely right, it will not work if it preceeds \maketitle and it will print out the title as plain text if I repeat the \title command after \maketitle. What do I need to change so that \maketitle does not clear the \@title macro (just thought I will give it a try as I am trying to learn a few things beyond the basics)?phi wrote:I think this won't work because \maketitle clears out \@title. An easy solution is to define user commands for the title etc.:gmedina wrote:for the first issue, you can use the \@title command
Thanks,
George
Re: Fancyhdr Questions
Ok, made the change in article.cls and is working now. The one thing I do not know is how do I update the changes so that I can keep the document class to article - at the moment I had to rename it to myclass.cls and use that name in the \documentclass directive?
Thanks,
George
Thanks,
George
Fancyhdr Questions
You have to redefine \maketitle. The actual definition depends on your document class. For the article class, the definition is as follows:gkl wrote:What do I need to change so that \maketitle does not clear the \@title macro (just thought I will give it a try as I am trying to learn a few things beyond the basics)?
Code: Select all
\if@titlepage
\newcommand\maketitle{\begin{titlepage}%
\let\footnotesize\small
\let\footnoterule\relax
\let \footnote \thanks
\null\vfil
\vskip 60\p@
\begin{center}%
{\LARGE \@title \par}%
\vskip 3em%
{\large
\lineskip .75em%
\begin{tabular}[t]{c}%
\@author
\end{tabular}\par}%
\vskip 1.5em%
{\large \@date \par}% % Set date in \large size.
\end{center}\par
\@thanks
\vfil\null
\end{titlepage}%
\setcounter{footnote}{0}%
\global\let\thanks\relax
\global\let\maketitle\relax
\global\let\@thanks\@empty
\global\let\@author\@empty
\global\let\@date\@empty
\global\let\@title\@empty
\global\let\title\relax
\global\let\author\relax
\global\let\date\relax
\global\let\and\relax
}
\else
\newcommand\maketitle{\par
\begingroup
\renewcommand\thefootnote{\@fnsymbol\c@footnote}%
\def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
\long\def\@makefntext##1{\parindent 1em\noindent
\hb@xt@1.8em{%
\hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
\if@twocolumn
\ifnum \col@number=\@ne
\@maketitle
\else
\twocolumn[\@maketitle]%
\fi
\else
\newpage
\global\@topnum\z@ % Prevents figures from going at top of page.
\@maketitle
\fi
\thispagestyle{plain}\@thanks
\endgroup
\setcounter{footnote}{0}%
\global\let\thanks\relax
\global\let\maketitle\relax
\global\let\@maketitle\relax
\global\let\@thanks\@empty
\global\let\@author\@empty
\global\let\@date\@empty
\global\let\@title\@empty
\global\let\title\relax
\global\let\author\relax
\global\let\date\relax
\global\let\and\relax
}
\def\@maketitle{%
\newpage
\null
\vskip 2em%
\begin{center}%
\let \footnote \thanks
{\LARGE \@title \par}%
\vskip 1.5em%
{\large
\lineskip .5em%
\begin{tabular}[t]{c}%
\@author
\end{tabular}\par}%
\vskip 1em%
{\large \@date}%
\end{center}%
\par
\vskip 1.5em}
\fi
Code: Select all
\if@titlepage
\renewcommand\maketitle{\begin{titlepage}%
\let\footnotesize\small
\let\footnoterule\relax
\let \footnote \thanks
\null\vfil
\vskip 60\p@
\begin{center}%
{\LARGE \@title \par}%
\vskip 3em%
{\large
\lineskip .75em%
\begin{tabular}[t]{c}%
\@author
\end{tabular}\par}%
\vskip 1.5em%
{\large \@date \par}% % Set date in \large size.
\end{center}\par
\@thanks
\vfil\null
\end{titlepage}%
\setcounter{footnote}{0}%
\global\let\thanks\relax
\global\let\maketitle\relax
\global\let\title\relax
\global\let\author\relax
\global\let\date\relax
\global\let\and\relax
}
\else
\renewcommand\maketitle{\par
\begingroup
\renewcommand\thefootnote{\@fnsymbol\c@footnote}%
\def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
\long\def\@makefntext##1{\parindent 1em\noindent
\hb@xt@1.8em{%
\hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
\if@twocolumn
\ifnum \col@number=\@ne
\@maketitle
\else
\twocolumn[\@maketitle]%
\fi
\else
\newpage
\global\@topnum\z@ % Prevents figures from going at top of page.
\@maketitle
\fi
\thispagestyle{plain}\@thanks
\endgroup
\setcounter{footnote}{0}%
\global\let\thanks\relax
\global\let\maketitle\relax
\global\let\@maketitle\relax
\global\let\title\relax
\global\let\author\relax
\global\let\date\relax
\global\let\and\relax
}
\fi
- localghost
- Site Moderator
- Posts: 9201
- Joined: Fri Feb 02, 2007 12:06 pm
Fancyhdr Questions
Saving the contents of \@title and \@author into other commands will do the trick.
This solution does not depend on the used (standard) document class.
For the second issue I'm not aware of an automatism which could do this.
Best regards
Thorsten¹
Code: Select all
\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage{lmodern}
\usepackage{fancyhdr}
\usepackage{blindtext}
\parindent0em
\parskip\medskipamount
\title{Title of the Document}
\author{Author name}
\makeatletter
\let\Title\@title
\let\Author\@author
\makeatother
\fancyhf{}
\cfoot{\thepage}
\lhead{\Title}
\rhead{\Author}
\pagestyle{fancy}
\begin{document}
\maketitle
\tableofcontents
\blinddocument
\end{document}
For the second issue I'm not aware of an automatism which could do this.
Best regards
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]
¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Board Rules
Avoidable Mistakes[/size]
¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Fancyhdr Questions
You don't have to create a new document class, simply put the changed definition in your document if you want to use them.gkl wrote:Ok, made the change in article.cls and is working now. The one thing I do not know is how do I update the changes so that I can keep the document class to article - at the moment I had to rename it to myclass.cls and use that name in the \documentclass directive?