2

I am using authblk.sty and using the \ifnum\value{}>1 concept using to switch the affiliation. But I can't able to get the if then else condition output.

My requirement is

Condition 1

If the affiliation is count is one the affiliation number should be relax.

Condition 2

If the affiliation is count is more than one the affiliation number should be counter 1,2,3 etc.

I mentioned my \ifnum condition in my 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}

But my \ifnum condition is not working properly. Always executed \else part only. \ifnum\value{affiliation}>1 part is not executed.

4

\ifnum does nothing in the way you are using it.

To achieve what you want you need the totcount package and to register your affiliations counter with it.

\usepackage{totcount}
\newtotcounter{affiliations}

Then the redefinition of \affil must be

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

MWE (needs at least two compilations)

\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} 

Output:

enter image description here

This is the result if you have only one \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}

enter image description here


You'd also probably want to redefine \author in this way:

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

so that when there is only one \author and one \affil you have no numbers in it.

  • Your code example the first affiliation number is always empty. I can't get required output. But the requirement is if the second and third affil is commented in the tex file the first affil is empty. Otherwise If more than one affil available in the tex file the stepcounter is counted 1,2,3...etc – Vetri Feb 23 '15 at 21:07
  • sorry the first example is executed perfectly. I got the solution. Thank you... – Vetri Feb 23 '15 at 21:11
  • See the last edit for \author too. Maybe it improves what you are trying to achieve. – karlkoeller Feb 23 '15 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.