使用 \@author 变量将作者姓名放在精美的标题中

使用 \@author 变量将作者姓名放在精美的标题中

我使用\@author变量将作者姓名放入文档的页眉中。目前,页眉显示作者姓名和脚注标记,每页递增:

\makeatletter
\let\runauthor\@author
\let\runtitle\@title
\makeatother

\fancyhead[OC]{\runauthor}
\fancyhead[EC]{\sc \runtitle}

例如,如果作者是 John Doe,则打印

John Doe^1 (1.page)
John Doe^2 (2.page)
...
etc.

有任何想法吗 ?

答案1

这运行流畅。

\documentclass[twoside]{article}

\usepackage{fancyhdr}
\usepackage{authoraftertitle}

\makeatletter
\fancyhead[OC]{{\let\thanks\@gobble\MyAuthor}}
\fancyhead[EC]{\scshape \MyTitle}
\pagestyle{fancy}
\makeatother

\title{TTT}
\author{AAA\thanks{THXTHX}}

\usepackage{lipsum} % filler text

\begin{document}

\maketitle
\lipsum[1-40]

\end{document}

答案2

正如 egreg 所建议的,您的问题可能与命令中存在其他宏有关\author,可能是类似的东西\author{John Doe\thanks{Mum and Dad}}。如果没有完整的 MWE,很难判断(特别是,您正在使用什么文档类以及您如何调用\author)。但是,应该可行的解决方案是使用titling包:

\documentclass[twoside]{article}

\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{titling}

\author{John Doe}
\title{My Title}

\pagestyle{fancy}
\fancyhead[OC]{\theauthor}
\fancyhead[EC]{\scshape \thetitle}

\begin{document}

\lipsum

\end{document}

答案3

如果您对任何打包的解决方案都不满意,您可以像我一样编写自己的解决方案。此处的示例使用标准文章类边距,而我的压模器不是为此设计的。但它看起来仍然不错,而且您可以控制所有参数。

\documentclass[12pt]{article}

\makeatletter
%% SET UP CODE TO USE PAGE STAMPS AT TOP AND BOTTOM OF PAGE.  DEFAULT
%% STAMP IS "DRAFT", BUT IT CAN BE RESET AND USED FOR OTHER PURPOSES,
%% TOO.
\def\PageStampFlag{F}
\def\thePageStamp{}
\def\EmptyStyle{empty}
\def\PlainStyle{plain}

\newcommand{\ps@pagestamp}{
  \renewcommand{\@oddhead}{\hfil\textbf{\Large\thePageStamp}\hfil}
  \renewcommand{\@evenhead}{\@oddhead}
  \renewcommand{\@evenfoot}{\hfil
                            \begin{tabular}{c}
                            \textrm{\thepage}\\
                            \textbf{\Large\thePageStamp}
                            \end{tabular}
                            \hfil}
  \renewcommand{\@oddfoot}{\@evenfoot}
}

\newcommand{\ps@emptypagestamp}{
  \renewcommand{\@oddhead}{\hfil\textbf{\Large\thePageStamp}\hfil}
  \renewcommand{\@evenhead}{\@oddhead}
  \renewcommand{\@evenfoot}{\hfil
                            \begin{tabular}{c}
                            ~\\
                            \textbf{\Large\thePageStamp}
                            \end{tabular}
                            \hfil}
  \renewcommand{\@oddfoot}{\@evenfoot}
}

\newcommand\PageStamp[1][DRAFT]{
  \def\PageStampFlag{T}
  \setlength\textheight{9in} %textheight+headheight+headsep=9in
  \def\thePageStamp{#1}
  \setlength\topmargin{-1.0in}
  \setlength\headheight{0.6in}
  \setlength\headsep{0.4in}
  \setlength\footskip{38pt}
  \def\PlainStyle{pagestamp}
  \def\EmptyStyle{emptypagestamp}
  \pagestyle{\PlainStyle}
}

\newcommand\StopPageStamp[0]{
  \def\PageStampFlag{F}
  \setlength\topmargin{0in}
  \setlength\headheight{0pt}
  \setlength\headsep{0pt}
  \setlength\textheight {9.0in}
  \setlength\footskip{30pt}
  \def\PlainStyle{plain}
  \def\EmptyStyle{empty}
  \pagestyle{\PlainStyle}
}

\makeatother

\begin{document}

\PageStamp[\today]

This is a test of Steven's pagestamping commands. Usage is
\verb|\PageStamp[stamp]|.  Default stamp is ``DRAFT''.  The command can
be reissued to change the pagestamp.  The alternate command
\verb|\StopPageStamp| will suspend the pagestamp, unless/until later
reinstituted with a \verb|\PageStamp[]|

\end{document}

在此处输入图片描述

相关内容