如何使用 biblatex 對參考書目條目進行完全著色

如何使用 biblatex 對參考書目條目進行完全著色

我想對某些參考書目條目進行著色,例如“重要”和“獲獎”論文。我現在擁有的:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[backend=biber,
        isbn=true,
        giveninits=true,
        style=numeric,
        maxnames=99,
        sorting=ydnt,
        defernumbers=true,
        autocite=superscript]{biblatex}
\defbibheading{bibliography}[\refname]{}
\addbibresource{references.bib}
\renewbibmacro{in:}{}

\usepackage[usenames,dvipsnames]{xcolor}

\DeclareBibliographyCategory{important}
\DeclareBibliographyCategory{award}

\addtocategory{important}{small}
\addtocategory{award}{big}

\AtEveryBibitem{
\ifcategory{award}%
    {\color{blue}}%
    {}%
\ifcategory{important}%
    {\color{orange}}%
    {}%
}

\begin{document}

\section{Main text}

\cite{small}

\cite{big}

\section{Bibliography}
\printbibliography

\end{document}

但是,只有 Bibentry 本身是橙色的(或藍色的,下面未顯示),而不是它旁邊的參考號碼。我怎樣才能做到這一點?

在此輸入影像描述

答案1

您可以簡單地使用\AtBeginBibliography\AtEveryBibitem設定程式碼來僅對類別的參考書目條目進行著色important

PS = 由於您沒有添加文件範例.bib,因此我使用了biblatex-examples.bib.

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[backend=biber,
isbn=true,
giveninits=true,
style=numeric,
maxnames=99,
sorting=ydnt,
defernumbers=true,
autocite=superscript]{biblatex}
\defbibheading{bibliography}[\refname]{}
\addbibresource{biblatex-examples.bib}
\renewbibmacro{in:}{}

\usepackage[usenames,dvipsnames]{xcolor}

\DeclareBibliographyCategory{important}
\addtocategory{important}{knuth:ct:a}
\addtocategory{important}{knuth:ct:c}

\AtBeginBibliography{%
    \DeclareFieldFormat{labelnumberwidth}{\ifcategory{important}%
        {\color{orange}\mkbibbrackets{#1}}%
        {\mkbibbrackets{#1}}%
    }}
\AtEveryBibitem{\ifcategory{important}
    {\color{orange}}
    {}}

\begin{document}

    \section{Main text}

    \cite{knuth:ct}
    \cite{knuth:ct:a}
    \cite{knuth:ct:b}       
    \cite{knuth:ct:c}       
    \cite{companion}

    \section{Bibliography}

    \printbibliography

\end{document}

在此輸入影像描述

編輯:

\ifcategory指令的語法如下:

\ifcategory{hcategoryi}{htruei}{hfalsei}

\if與其他指令類似,請參閱biblatex手冊第 7 段。 4.6.2“獨立測試”。

htruei在or中,hfalsei您可以嵌套任意數量的\ifcategorys (或其他\ifs),您只需注意匹配所有大括號即可。

以下是三個不同類別的三種不同顏色的範例:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[backend=biber,
isbn=true,
giveninits=true,
style=numeric,
maxnames=99,
sorting=ydnt,
defernumbers=true,
autocite=superscript]{biblatex}
\defbibheading{bibliography}[\refname]{}
\addbibresource{biblatex-examples.bib}
\renewbibmacro{in:}{}

\usepackage[usenames,dvipsnames]{xcolor}

\DeclareBibliographyCategory{important}
\addtocategory{important}{knuth:ct:a}
\addtocategory{important}{knuth:ct:c}
\DeclareBibliographyCategory{awards}
\addtocategory{awards}{knuth:ct:b}
\DeclareBibliographyCategory{ducks}
\addtocategory{ducks}{companion}

\AtBeginBibliography{%
    \DeclareFieldFormat{labelnumberwidth}%
        {\ifcategory{important}% if
            {\color{orange}\mkbibbrackets{#1}}% then
            {\ifcategory{awards}% else if
                {\color{blue}\mkbibbrackets{#1}}% then
                {\ifcategory{ducks}% else if
                    {\color{green}\mkbibbrackets{#1}}% then
                    {{\mkbibbrackets{#1}}%else
                }% end if
            }% end if
        }% end if
}}
\AtEveryBibitem%
    {\ifcategory{important}% if
        {\color{orange}}% then
        {\ifcategory{awards}% else if
            {\color{blue}}% then
            {\ifcategory{ducks}% else if
                {\color{green}}% then
                {}%else
            }% end if
        }% end if
    }% end if

\begin{document}

    \section{Main text}

    \cite{knuth:ct}
    \cite{knuth:ct:a}
    \cite{knuth:ct:b}       
    \cite{knuth:ct:c}       
    \cite{companion}

    \section{Bibliography}

    \printbibliography

\end{document}

在此輸入影像描述

相關內容