0

I am trying to get alternate background color for bibliography, with AtBeginBebliography, as shown(Please note, \IF_COUNTER_IS_ODD does not have any meaning, it is just to show, I want orange \colorbox for odd number item, and the normal white background for even item.). This is a mwe

\documentclass[a4paper]{scrartcl}
\usepackage[dvipsnames, table]{xcolor}
\usepackage[
  defernumbers=true,
  sorting=ydnt,
  maxbibnames=99,
  citestyle=numeric
]{biblatex}
\addbibresource{mwe.bib}
\AtBeginBibliography{% 
    \DeclareFieldFormat{labelnumberwidth}{\IF_COUNTER_IS_ODD% 
        {\colorbox{orange}\mkbibbrackets{#1}}%
        {\mkbibbrackets{#1}}%
    }}
\AtEveryBibitem{\IF_COUNTER_IS_ODD
    {\colorbox{orange}}
    {}}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

mwe.bib

@article{einstein,
    author =       "Albert Einstein",
    title =        "{Zur Elektrodynamik bewegter K{\"o}rper}. ({German})
        [{On} the electrodynamics of moving bodies]",
    journal =      "Annalen der Physik",
    volume =       "322",
    number =       "10",
    pages =        "891--921",
    year =         "1905",
    DOI =          "http://dx.doi.org/10.1002/andp.19053221004"
}

@book{latexcompanion, author = "Michel Goossens and Frank Mittelbach and Alexander Samarin", title = "The \LaTeX\ Companion", year = "1993", publisher = "Addison-Wesley", address = "Reading, Massachusetts" }

BaRud
  • 2,179
  • 1
    I think attempts to use LaTeX box macros like \colorbox are doomed, because the way biblatex produces bibliography entries does not lend itself to absorbing the entry as an argument of a macro. But there is https://tex.stackexchange.com/q/457084/35864. An alternative if you don't like that might be possible with lua-ul but will need you to compile your document with LuaLaTeX (which may or may not be an issue for you). – moewe Sep 06 '20 at 15:26
  • Come to think of it, the lua-ul solution will look more like https://tex.stackexchange.com/q/547414/35864, which is probably not quite what you have in mind. – moewe Sep 06 '20 at 15:31
  • @moewe: nope, the solution is looking like your first reply, which is exactly what I was looking for. Thanks a lot. – BaRud Sep 06 '20 at 15:41

0 Answers0