0

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.

0
0

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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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