使用 biblatex 的表格书目

使用 biblatex 的表格书目

我正在研究自定义 biblatex 样式,因为我必须满足非常特殊的要求。引用部分 (cbx) 运行良好,但我对参考书目定义有问题。我需要一个表格参考书目(例如参见这个模板制作BibTeX)。

我无法使用tabular环境,因为&书目行内会产生错误。使用 eg 的其他方法list也失败了。

您知道如何使用 biblatex 制作表格式参考书目吗?

答案1

通常,你可以使用以下命令定义新的参考书目格式\defbibenvironment

\defbibenvironment{bibliography}{<begin code>}{<end code>}{<item code>}

在内部biblatex对这些代码段进行分组,并&在处理项目时将其用作列表末尾标记。因此,现有设置不适合tabular

一种解决方法是使用列表环境借用enumitem标签multiline格式,但这不能处理长标签和短项目。

\defbibenvironment{bibliography}
  {\list{<label code>}{<list format code>}
   \renewcommand*{\makelabel}[1]{%
     \nobreak\strut\smash{\parbox[t]\labelwidth{\raggedright##1}}}}
  {\endlist}
  {\item}

允许使用 的解决方案tabular需要深入biblatex研究内部原理。在这里,我们定义\defbibenvironment和的表格变体\printbibliography\defbibtabular\printbibtabular。前者接受五个参数:

\defbibtabular{<name>}{<begin code>}{<end code>}{<label code>}{<item code>}

后者允许与相同的选项列表\printbibliography,但使用默认设置env=bibtabular

\documentclass{article}
\usepackage{csquotes}
\usepackage[american]{babel}
\usepackage[style=authortitle]{biblatex}

\makeatletter

% user-level command for printing tabular bibliography
\let\printbibtabular\printbibliography
\patchcmd{\printbibtabular}{\blx@printbibliography}{\bbx@printbibtabular}{}{}
\patchcmd{\printbibtabular}{\blx@printbibliography}{\bbx@printbibtabular}{}{}
\let\bbx@printbibtabular\blx@printbibliography
\patchcmd{\bbx@printbibtabular}{\blx@bibliography}{\bbx@bibtabular}{}{}
\patchcmd{\bbx@printbibtabular}
  {\def\blx@theenv{bibliography}}{\def\blx@theenv{bibtabular}}{}{}

% underlying macros
\def\bbx@bibtabular#1{%
  \blx@bibheading\blx@theheading\blx@thetitle
  \blx@bibnote\blx@theprenote
  \begingroup
  \blx@bibinit
  \let\@noitemerr\@empty
  \let\blx@noitem\blx@warn@bibempty
  \ifnum\bibinitsep=\z@
    \let\blx@initsep\relax
  \fi
  \ifnum\bibnamesep=\z@
    \let\blx@namesep\relax
  \fi
  \csuse{blx@hook@bibinit}%
  % copy filtered list of entries to internal list macro
  \def\blx@do##1{%
    \blx@ifdata{##1}{%
      \begingroup
      \blx@getdata{##1}
      \blx@bibcheck
      \iftoggle{blx@skipentry}{}{%
        \global\let\blx@noitem\@empty
        \listadd\blx@tempa{##1}}%
      \endgroup}{}}
  \let\blx@done\relax
  \blx@listloop{#1}
  % tabular output for each item in list macro
  \def\do##1{\bbx@tab@label{##1} & \bbx@tab@item{##1} \\}
  \csuse{blx@env@\blx@theenv}%
  \dolistloop{\blx@tempa}
  \csuse{blx@endenv@\blx@theenv}%
  \blx@bibnote\blx@thepostnote
  \endgroup}

\def\bbx@tab@label#1{%
  \begingroup
  \blx@getdata{#1}%
  \blx@setoptions@type\abx@field@entrytype
  \blx@setoptions@entry
  \blx@thelabelnumber
  \blx@addprefixnumber
  \addtocounter{instcount}\@ne
  \csuse{bbx@tabenv@\blx@theenv}\relax
  \endgroup}

\def\bbx@tab@item#1{%
  \begingroup
  \blx@getdata{#1}%
  \blx@setoptions@type\abx@field@entrytype
  \blx@setoptions@entry
  \csuse{blx@item@\blx@theenv}\relax
  \blx@initsep
  \blx@namesep
  \csuse{blx@hook@bibitem}%
  \blx@execute
  \blx@initunit
  \blx@anchor
  \blx@beglang
  \bibsentence
  \blx@pagetracker
  \blx@driver\abx@field@entrytype
  \blx@postpunct
  \blx@endlang
  \endgroup}

% user-level command for defining tabular bibliography format
\newrobustcmd*{\defbibtabular}[5]{%
  \long\csdef{blx@env@#1}{#2}%
  \long\csdef{blx@endenv@#1}{#3}%
  \long\csdef{bbx@tabenv@#1}{#4}%
  \long\csdef{blx@item@#1}{#5}}

% user-level access to some entry options
\def\useeditorfalse{\togglefalse{blx@useeditor}}
\def\usetranslatorfalse{\togglefalse{blx@usetranslator}}

\makeatother

% sortname labels (a robust style should add provision for missing labelnames)
\newbibmacro*{sortname}{%
  \renewcommand*{\multinamedelim}{\addslash\break}%
  \let\finalnamedelim\multinamedelim
  \printtext[bold]{\printnames[last-first]{labelname}}}

% bibitem hook to suppress redundant sortname list
\newbibmacro*{omitsortname}{%
  \ifnameundef{labelname}{}{%
    \ifnameundef{author}
      {\ifnameundef{editor}
         {\ifusetranslator{\clearname{translator}}{}}}
         {\clearname{editor}}
      {\clearname{author}}%
    \useeditorfalse%
    \usetranslatorfalse}}

% demo new tabular bibliography format
\defbibtabular{bibtabular}
  {\begin{tabular}{p{0.3\textwidth}p{0.7\textwidth}}}
  {\end{tabular}}
  {\usebibmacro{sortname}}
  {\usebibmacro{omitsortname}}

% add multiline labels in default bibliography format
\defbibenvironment{bibliography}
  {\list
     {\usebibmacro{sortname}}
     {\setlength{\labelwidth}{0.3\textwidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}%
     \renewcommand*{\makelabel}[1]{%
       \nobreak\strut\smash{\parbox[t]\labelwidth{\raggedright##1}}}}
  {\endlist}
  {\item\usebibmacro{omitsortname}}

\addbibresource{biblatex-examples.bib}
\newcommand{\cmd}[1]{\texttt{\textbackslash #1}}
\begin{document}
\cite{vangennep:trans,companion,bertram}
\printbibliography[title={\cmd{printbibliography} with multiline labels}]
\printbibtabular[title={New \cmd{printbibtabular} command}]
\end{document}

在此处输入图片描述

相关内容