1

I would like to have the authors split up into columns of multicols. The problem is I don’t get the \value{listtotal} to define the count of columns dynamically.

So, for one author there should be only one column, for two authors two columns and so on.

\documentclass{scrartcl}
\usepackage{filecontents}
\usepackage{multicol}
\setlength{\columnseprule}{3pt}
\usepackage{biblatex}
\begin{filecontents}{\jobname.bib}
@book{example1,
author = {Author, A.}}

@book{example2,
author = {Author, A. and Buther, B.}}

@book{example3,
author = {Author, A. and Buther, B. and Cuthor, C.}}
\end{filecontents}
\addbibresource{\jobname.bib}

\renewcommand*{\multinamedelim}{
  %\hfil.    %this is working but not wanted
  \par\columnbreak}
\let\finalnamedelim\multinamedelim

\newcommand\name{}
\newcommand\getname[2][\name]{%
    \begin{multicols}{3} %\value{listtotal} ???
    \citename{#1}{#2}%
    \end{multicols}}

\begin{document}
% one multicol-environment
\def\name{example1}
\getname{author}

% two multicol-environment
\def\name{example2}
\getname{author}

% three multicol-environment
\def\name{example3}
\getname{author}

\end{document}

enter image description here

2
  • At the point where you need to use \value{listtotal} here the value is not defined. listtotal is only populated with the correct value in certain situations when you are "inside" biblatex's list printing routines. The number of authors is not available at that point for you. – moewe Jul 2 '18 at 13:25
  • I thought that is the case, so probably no chance to get the number of items in that list?! – LukasCB Jul 2 '18 at 13:27
2

As explained in the comments the counter listtotal is only populated with the value you need in the specific context of biblatex list printing. In particular it is not available outside of list printing in biblatex, much less outside of biblatex itself. You need to get hold of the value before you start your multicolumn. That could be done using a fake citation command.

I must say that I find the interface/argument structure of the macro \getname really confusing, but I assume that it is useful for the purpose you designed it for.

Note that multicols still provides two columns even if the argument is 1. You have to treat that case separately.

\multicolumnauthor is the solution I would use, but it has the drawback of adding additional space between several multicols because of \leavevmode, so that might not be applicable to you.

\documentclass{scrartcl}
\usepackage{filecontents}
\usepackage{multicol}
\setlength{\columnseprule}{3pt}
\usepackage{biblatex}
\begin{filecontents}{\jobname.bib}
@book{example1,
author = {Author, A.}}

@book{example2,
author = {Author, A. and Buther, B.}}

@book{example3,
author = {Author, A. and Buther, B. and Cuthor, C.}}
\end{filecontents}
\addbibresource{\jobname.bib}

\DeclareDelimFormat{multinamedelim}{\endgraf\columnbreak}
\DeclareDelimAlias{finalnamedelim}{multinamedelim}

\DeclareCiteCommand{\getnumberofauthors}
  {}
  {\xdef\numofnames{\the\value{author}}}
  {}
  {}

\newcommand\name{}
\newsavebox{\discardbox}
\newcommand\getname[2][\name]{%
  \def\numofnames{1}%
  \sbox{\discardbox}{\getnumberofauthors{#1}}%
  \begin{multicols}{\numofnames}
  \citename{#1}{#2}%
  \end{multicols}}

\DeclareCiteCommand{\multicolumnauthor}
  {}
  {\ifnumgreater{\value{author}}{1}
     {\begin{multicols}{\value{author}}
      \printnames{author}%
      \end{multicols}}
     {\printnames{author}}}
  {}
  {}

\begin{document}
% one multicol-environment
\def\name{example1}
\getname{author}

% two multicol-environment
\def\name{example2}
\getname{author}

% three multicol-environment
\def\name{example3}
\getname{author}

\multicolumnauthor{example1}
\multicolumnauthor{example2}
\multicolumnauthor{example3}
\end{document}

enter image description here

2
  • I knew with your biblatex magic power you would find a solution. Indeed getname looks weird separated by the rest of code I use. However \DeclareCiteCommand{\multicolumnauthor} is nice code, I will go with the savebox since the case for one author and two columns is no problem in my document. Thanks a lot! – LukasCB Jul 2 '18 at 19:55
  • ok, ok, you convinced me and I changed my internal code to \DeclareCiteCommand{\multicolumnauthor} etc and I found a workaround for \leavemode, because now I can check whether the field is empty or not which is important to my code. – LukasCB Jul 3 '18 at 12:18

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.