You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TeX中是否存在类似\emptythanks的\emptyauthor与\emptyaffil命令?

双标题多作者多单位的TeX实现问题与解决办法

问题说明

我尝试使用titling包在TeX文档中实现双标题功能,现有方案仅支持每个标题对应1位作者与1个单位,但我的需求是每个标题对应2位作者与2个单位。当前代码运行后第二个标题会累积显示前一个标题的作者和单位,最终显示4位作者与4个单位,不符合预期。注意到titling包提供了\emptythanks命令,希望找到类似的\emptyauthor和\emptyaffil命令,或其他可行解决办法。

原代码如下:

\documentclass[12pt]{article}
    \usepackage[cp1251]{inputenc}
    \usepackage[english]{babel}
    
    \usepackage{amsmath}
    \usepackage{amsfonts}
    \usepackage{amsthm}
    \usepackage{dsfont}
    \usepackage{amssymb}
    \usepackage{csquotes}
    \usepackage{titling}
    \usepackage{letltxmacro}
    \usepackage{xparse}
    \usepackage[blocks]{authblk}
    
    %\newcommand{\emptyauthor}{\global\let\@author\@empty}
    %\newcommand{\emptyaffil}{\global\let\@affil\@empty}
    
    
    \makeatletter \LetLtxMacro\@uthorfrom@uthblk\author
    
    \RenewDocumentCommand{\author}{+o+m}{%\n      \ifnum0=\value{authors}%
      \def\AB@authors{}%
      \fi
      \IfValueTF{#1}{%
        \@uthorfrom@uthblk[#1]{#2}%
      }{%
        \@uthorfrom@uthblk{#2}%
      }%
    }
    
    \def\@maketitle{%
        \begin{center}%
          \let \footnote \thanks
          {\LARGE \@title \par}%
          \vskip 1.5em%
          {\large
            \lineskip .5em%
            \begin{tabular}[t]{c}%
              \@author%
            \end{tabular}\par}%
            \vskip 1em%
            % {\large \@date}%
          \end{center}%
          \par
          \vskip 1.5em%
          % reset counters for possible next \author macro
          \setcounter{authors}{0}%
          \setcounter{affil}{0}%
        }
    \makeatother
    
    
    \begin{document}
    
    %%%%%%%---------First Article-------------
    
    \title{First Article\thanks{thanks to everyone.}}
    
    
    \author[1]{Author A1}
    \author[2]{Author A2}
    
    \affil[1]{Affiliation of Author A1}
    \affil[2]{Affiliation of Author
    A2}
    
    \maketitle
    
    
    \begin{abstract}
      Abstract goes here...
    \end{abstract}
    
    
    %%%%%%%---------Second Article-------------
    
    
    \emptythanks
    %\emptyauthor
    %\emptyaffil
    
    \title{Second Article\thanks{thanks to your mom.}}
    
    \author[1]{\underline{Author B1}}
    \author[2]{\underline{Author B2}}
    
    \affil[1]{Affiliation of Author B1}
    \affil[2]{Affiliation of Author
    B2}
    
    \makeatletter
    \makeatother
    \maketitle
    
    \begin{abstract}
        Abstract goes here...
    \end{abstract}
    
    
    
    \end{document}

解决办法

问题核心是authblk包的作者和单位信息会累积存储,仅重置计数器不够,需要清空对应的内部变量。可以通过定义\emptyauthor和\emptyaffil命令来实现:

  1. 添加以下命令定义(取消原代码中注释的两行并修正):
\makeatletter
\newcommand{\emptyauthor}{\global\let\AB@authors\@empty\global\let\@author\@empty}
\newcommand{\emptyaffil}{\global\let\AB@affillist\@empty\global\let\@affil\@empty}
\makeatother
  • \AB@authors是authblk存储作者列表的内部变量,\@author是标准LaTeX的作者变量
  • \AB@affillist是authblk存储单位列表的内部变量,\@affil是标准LaTeX的单位变量
  1. 在切换到第二篇文章时,除了\emptythanks,还要调用这两个重置命令:
\emptythanks
\emptyauthor
\emptyaffil

修改后的完整代码

\documentclass[12pt]{article}
    \usepackage[cp1251]{inputenc}
    \usepackage[english]{babel}
    
    \usepackage{amsmath}
    \usepackage{amsfonts}
    \usepackage{amsthm}
    \usepackage{dsfont}
    \usepackage{amssymb}
    \usepackage{csquotes}
    \usepackage{titling}
    \usepackage{letltxmacro}
    \usepackage{xparse}
    \usepackage[blocks]{authblk}
    
    \makeatletter
    \newcommand{\emptyauthor}{\global\let\AB@authors\@empty\global\let\@author\@empty}
    \newcommand{\emptyaffil}{\global\let\AB@affillist\@empty\global\let\@affil\@empty}
    \makeatother
    
    
    \makeatletter \LetLtxMacro\@uthorfrom@uthblk\author
    
    \RenewDocumentCommand{\author}{+o+m}{%\n      \ifnum0=\value{authors}%
      \def\AB@authors{}%
      \fi
      \IfValueTF{#1}{%
        \@uthorfrom@uthblk[#1]{#2}%
      }{%
        \@uthorfrom@uthblk{#2}%
      }%
    }
    
    \def\@maketitle{%
        \begin{center}%
          \let \footnote \thanks
          {\LARGE \@title \par}%
          \vskip 1.5em%
          {\large
            \lineskip .5em%
            \begin{tabular}[t]{c}%
              \@author%
            \end{tabular}\par}%
            \vskip 1em%
            % {\large \@date}%
          \end{center}%
          \par
          \vskip 1.5em%
          % reset counters for possible next \author macro
          \setcounter{authors}{0}%
          \setcounter{affil}{0}%
        }
    \makeatother
    
    
    \begin{document}
    
    %%%%%%%---------First Article-------------
    
    \title{First Article\thanks{thanks to everyone.}}
    
    
    \author[1]{Author A1}
    \author[2]{Author A2}
    
    \affil[1]{Affiliation of Author A1}
    \affil[2]{Affiliation of Author
    A2}
    
    \maketitle
    
    
    \begin{abstract}
      Abstract goes here...
    \end{abstract}
    
    
    %%%%%%%---------Second Article-------------
    
    
    \emptythanks
    \emptyauthor
    \emptyaffil
    
    \title{Second Article\thanks{thanks to your mom.}}
    
    \author[1]{\underline{Author B1}}
    \author[2]{\underline{Author B2}}
    
    \affil[1]{Affiliation of Author B1}
    \affil[2]{Affiliation of Author
    B2}
    
    \maketitle
    
    \begin{abstract}
        Abstract goes here...
    \end{abstract}
    
    
    
    \end{document}

内容的提问来源于stack exchange,提问作者innokentijglum

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 00:35:29