假设\author{FirstName LastName}
,我如何从 中仅获取姓氏\@author
?我的目标是像 一样使用它\lhead{\@author[1]}
,而不必手动写出姓氏。
答案1
从中获取主要代码这个很好的答案,
\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}