Assuming \author{FirstName LastName}
, how do I obtain only the last name from \@author
? My objective is to use it as in \lhead{\@author[1]}
, without having to write the last name manually.
1 Answer
Taking the main code from this nice answer,
\documentclass{article}
% Function to extract the last word of a sentence
\newcommand*\TheLastWord[1]{\expandafter\xreverseit\expandafter{\expandafter}#1 \relax}
\def\xreverseit#1#2 #3{%
\ifx\relax#3%
#2%
\expandafter\xthree
\fi
\xreverseit{#1 #2}#3%
}
\def\xthree#1#2#3{}
\newcommand\thevariable{The example sentence} % Store the sentence in a variable
\usepackage{lipsum}
\usepackage{fancyhdr}
\fancyhf{}
\makeatletter
\lhead{\TheLastWord{\@author}}
\makeatother
\pagestyle{fancy}
\author{Filippo Bistaffa}
\begin{document}
\lipsum[1]
\end{document}