![IFNUM 条件不适用于关联计数器](https://linux22.com/image/306221/IFNUM%20%E6%9D%A1%E4%BB%B6%E4%B8%8D%E9%80%82%E7%94%A8%E4%BA%8E%E5%85%B3%E8%81%94%E8%AE%A1%E6%95%B0%E5%99%A8.png)
我正在使用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
其中就没有数字。