如何将作者(列表)分成几列?

如何将作者(列表)分成几列?

我想将作者分成多列。问题是我无法\value{listtotal}动态定义列数。

因此,对于一位作者应该只有一列,对于两位作者应该有两列,依此类推。

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

在此处输入图片描述

答案1

正如评论中所解释的那样,计数器listtotal仅填充了您在列表打印的特定上下文中所需的值biblatex。特别是,它在列表打印之外不可用biblatex,更不用说在biblatex其本身之外了。您需要在启动多列之前获取该值。这可以使用伪引用命令来完成。

我必须说,我发现宏的接口/参数结构\getname确实令人困惑,但我认为它对于你设计它的目的很有用。

请注意,multicols即使参数为,仍会提供两列1。您必须分别处理这种情况。

\multicolumnauthor是我会使用的解决方案,但是它的缺点是multicols由于而在几个之间添加了额外的空间\leavevmode,所以这可能不适用于您。

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

在此处输入图片描述

相关内容