IFNUM 条件不适用于关联计数器

IFNUM 条件不适用于关联计数器

我正在使用authblk.sty和使用\ifnum\value{}>1概念来切换从属关系。但我无法获得if then else条件输出。

我的要求是

条件 1

如果隶属关系数为 1,则隶属关系数应放宽。

条件 2

如果隶属关系数多于一个,则隶属关系编号应为计数器 1、2、3 等。

\ifnum在 MWE 中提到了我的病情:

\documentclass[twocolumn]{article}
\usepackage[noblocks]{authblk}

\usepackage{letltxmacro,xparse}

\newcounter{affiliations}
\LetLtxMacro{\authblkauthor}{\author}
\LetLtxMacro{\authblkaffil}{\affil}

\ifnum\value{affiliations}>1
\renewcommand{\author}[1]{%
  \authblkauthor[\theauthors]{#1}%
}
\renewcommand{\affil}[1]{%
  \stepcounter{affiliations}%
  \authblkaffil[\theaffiliations]{#1}%
}
\else
\renewcommand{\author}[1]{%
  \authblkauthor[\theauthors]{#1}%
}
\renewcommand{\affil}[1]{%
  \stepcounter{affiliations}%
  \authblkaffil[$\relax$]{#1}%
}
\fi

\begin{document}

\title{Hormonal crosstalk for root development: a combined experimental and modeling perspective}

\author{Junli Liu}
\author{James Rowe}
\author{Keith Lindsey}

\affil{Integrative Cell Biology Laboratory, School of Biological and Biomedical Sciences,
  The Bio physical Sciences Institute, Durham University, Durham, UK}
\affil{Some other laboratory, Elsewhere}
\affil{Another laboratory, Somewhere Else}

\maketitle
\end{document}

但我的\ifnum条件不正常。总是\else只执行部分。\ifnum\value{affiliation}>1部分不执行。

答案1

\ifnum在您使用它时不会产生任何效果。

为了实现您的目标,您需要该包并在其中totcount注册您的计数器。affiliations

\usepackage{totcount}
\newtotcounter{affiliations}

\affil然后必须重新定义

\renewcommand{\affil}[1]{%
  \stepcounter{affiliations}%
  \ifnum\totvalue{affiliations}>1%
    \authblkaffil[\theaffiliations]{#1}%
  \else%
    \authblkaffil[$\relax$]{#1}%
  \fi%
}

MWE(需要至少两次编译)

\documentclass[twocolumn]{article}
\usepackage[noblocks]{authblk}

\usepackage{letltxmacro,xparse}

\usepackage{totcount}
\newtotcounter{affiliations}

\LetLtxMacro{\authblkauthor}{\author}
\LetLtxMacro{\authblkaffil}{\affil}

\renewcommand{\author}[1]{%
  \authblkauthor[\theauthors]{#1}%
}

\renewcommand{\affil}[1]{%
  \stepcounter{affiliations}%
  \ifnum\totvalue{affiliations}>1%
    \authblkaffil[\theaffiliations]{#1}%
  \else%
    \authblkaffil[$\relax$]{#1}%
  \fi%
}

\begin{document}

\title{Hormonal crosstalk for root development: a combined experimental and modeling perspective}

\author{Junli Liu}
\author{James Rowe}
\author{Keith Lindsey}

\affil{Integrative Cell Biology Laboratory, School of Biological and Biomedical Sciences,
  The Bio physical Sciences Institute, Durham University, Durham, UK}
\affil{Some other laboratory, Elsewhere}
\affil{Another laboratory, Somewhere Else}

\maketitle
\end{document} 

输出:

在此处输入图片描述

如果你只有一个,这就是结果\affil

\documentclass[twocolumn]{article}
\usepackage[noblocks]{authblk}

\usepackage{letltxmacro,xparse}

\usepackage{totcount}
\newtotcounter{affiliations}

\LetLtxMacro{\authblkauthor}{\author}
\LetLtxMacro{\authblkaffil}{\affil}

\renewcommand{\author}[1]{%
  \authblkauthor[\theauthors]{#1}%
}

\renewcommand{\affil}[1]{%
  \stepcounter{affiliations}%
  \ifnum\totvalue{affiliations}>1%
    \authblkaffil[\theaffiliations]{#1}%
  \else%
    \authblkaffil[$\relax$]{#1}%
  \fi%
}

\begin{document}

\title{Hormonal crosstalk for root development: a combined experimental and modeling perspective}

\author{Junli Liu}
\author{James Rowe}
\author{Keith Lindsey}

\affil{Integrative Cell Biology Laboratory, School of Biological and Biomedical Sciences,
  The Bio physical Sciences Institute, Durham University, Durham, UK}

\maketitle
\end{document}

在此处输入图片描述


您可能还想以\author这种方式重新定义:

\renewcommand{\author}[1]{%
  \ifnum\totvalue{affiliations}>1%
    \authblkauthor[\theauthors]{#1}%%
  \else%
    \authblkauthor[$\relax$]{#1}%
  \fi%
}

因此当只有一\author和一时,\affil其中就没有数字。

相关内容