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

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .