2

In my bibliography, I need to highlight some entries with a different font (for example bold, sans-serif, larger or colored).

How can I do this?

5

This answer uses the biblatex package with biber.

First, the entries that need highlighting need to be defined. You do this by adding a keywords entry into the respective items. Let's say, you want to have bold entries with keyword bold and sans-serif entries with keyword sans.

Then, you add the following to your preamble: 

\renewbibmacro*{begentry}{%
    \ifkeyword{bold}{\bfseries}{}%
    \ifkeyword{sans}{\sffamily}{}%
}

The renewbibmacro command adds some code to the beginning of each entry. Then you use ifkeyword to check whether the entry contains a specific keyword. The first parameter is the keyword you want to check, the second parameter contains code you want to enter if the entry has that keyword, and the third parameter contains code that's entered if the keyword is not there. Please don't forget the % signs at the end of each line, otherwise formatting might break.

You can use any formatting command you would normally enter into normal text as follows: {\command Some text.} You can use for example the size commands (\tiny ... \Huge) or the commands shown here in column "Equivalent to". You can also use \color{some-color} when you use the color or the xcolor packages.

Here is a minimal working example:

\documentclass{article}

\usepackage[backend=biber]{biblatex}

\renewbibmacro*{begentry}{%
    \ifkeyword{bold}{\bfseries}{}%
    \ifkeyword{sans}{\sffamily}{}%
}


\usepackage{filecontents}

\begin{filecontents*}{\jobname.bib}
    @book{Knu86,
        author = {Knuth, Donald E.},
        year = {1986},
        title = {The \TeX book},
    }

    @book{Aut16,
        author = {Author, Ann},
        year = {2016},
        title = {My second book},
        keywords = {bold},
    }

    @book{Wri25,
        author = {Writer, A. Good},
        year = {2025},
        title = {Best seller},
        keywords = {bold,sans},
    }

    @book{Doe86,
        author = {Doe, John},
        year = {1986},
        title = {Life without a name},
        keywords = {sans},
    }

    @book{Aut00,
        author = {Author, Ann},
        year = {2000},
        title = {My first book},
    }
\end{filecontents*}

\addbibresource{\jobname.bib}

\begin{document}

\nocite{*}
\printbibliography

\end{document}

And this is the output it yields:

Reference list

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.