TransWikia.com

Changing background color of glossaries header row

TeX - LaTeX Asked on December 1, 2021

In the document I want to apply this to, I have a long glossary, formatted with the longheaderborder style. Rows of all tables in the document have alternating background colors. I style the top row/header of each table with rowcolor{headercolor}. I just can’t seem to get it to work with the glossary.

Below is a MWE (not really working though) of what I attempted. The colors used are not the colors I really want to use, but they are very noticeable for this example

I tried redefining the glossaryheader with the rowcolor{blue} I wanted to use. I also tried to color each cell separately with cellcolor{red}. As you may notice, no blue or red occur in the table, only yellow and green of rowcolors{0}{yellow}{green}, which I have included to demonstrate that xcolor at least has some effect on the glossary.

So: how can I change the background color of the top row of a glossary, styled with longheaderborder?

The example:

documentclass{article}
usepackage[table]{xcolor}
usepackage[automake,nogroupskip]{glossaries-extra}

renewcommand*{glossaryheader}{rowcolor{blue} bfseries Notation & cellcolor{red} bfseries Description\hline}
makeglossaries

newglossaryentry{MWE}{
  name={MWE},
  description={Minimal working example}
}
newglossaryentry{ex}{
  name={ex.},
  description={example}
}
newglossaryentry{I}{
  name={I},
  description={the author}
}

begin{document}
This is a gls{MWE}. It is an gls{ex} of what gls{I} want.

{
rowcolors{0}{yellow}{green}
printglossary[style=longheaderborder]
}
end{document}

Generated output:
Demonstration of above code. The header row of the glossary is yellow, while I expected it to be multicolored blue and red.

One Answer

As commented by leandriis, replacing renewcommand*{glossaryheader}{ bfseries Notationzzrtt & cellcolor{red} bfseries Description\hline} with renewcommand*entryname{cellcolor{blue} Name} renewcommand*descriptionname{cellcolor{red} Description} works in the above MWE.

When using usepackage[english]{babel} (or any other language), this breaks. Telling glossaries-extra that you want to provide your own translations for everything lets you adjust colors though. That means that in the above MWE, I replaced usepackage[automake,nogroupskip]{glossaries-extra} with usepackage[automake,nogroupskip,translate=false]{glossaries-extra}, and it all worked!

Answered by pkok on December 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP