Text FormattingAdding background colour to enumerated list with mdframed removes numbering

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
congoblue
Posts: 2
Joined: Tue Jun 15, 2021 11:04 am

Adding background colour to enumerated list with mdframed removes numbering

Post by congoblue »

Hi, I am new to LaTeX so could be missing something really obvious. I've managed to find several solutions to problems already from helpful replies on this forum, but have now got stuck.

I am working on a user manual which is originated in standard markdown format. From this we generate an online/web version using Docusaurus2 and a PDF version using Pandoc with a slightly modified version of eisvogel.latex template.

Parts of the manual have a step-by-step guide using an enumerated list. I am trying to give all these lists a pale red background with dark red left border in the PDF, but when I do this the numbers disappear from the list; I cannot work out why this is happening. These lists are the only use of enumerated lists in the document so I was trying to redefine the "enumerate" environment so that all such sections would be automatically rendered with the red background.

I have added the following to the template file:

Code: Select all

\definecolor{numlist-border}{HTML}{FF4040}
\definecolor{numlist-background}{HTML}{FFE0E0}
\definecolor{numlist-text}{HTML}{606060}
\usepackage{mdframed}
\newmdenv[backgroundcolor=numlist-background,rightline=false,bottomline=false,topline=false,linewidth=4pt,linecolor=numlist-border,skipabove=\parskip]{customnumlist}
\renewenvironment{enumerate}{\begin{customnumlist}\list{}{\rightmargin=0em\leftmargin=0em}\item\relax\color{numlist-text}\ignorespaces}%
{\endlist\end{customnumlist}}
The unstyled lists look like this in the pdf:
enum1.png
enum1.png (19.82 KiB) Viewed 3822 times
With the above definitions in the template file, they look like this:
enum2.png
enum2.png (20.82 KiB) Viewed 3822 times
Can anyone help me with the right code to render this list with the numbers still showing ?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

congoblue
Posts: 2
Joined: Tue Jun 15, 2021 11:04 am

Adding background colour to enumerated list with mdframed removes numbering

Post by congoblue »

OK, I have worked it out, the renewenvironment{enumerate} is overwriting the original definition for enumerate which contains the numbering magic, leaving me with just a plain list.

So I need to store the original definition and add it back into the renewenvironment command like this:

Code: Select all

\let\origenumerate\enumerate
\let\origendenumerate\endenumerate
\renewenvironment{enumerate}{\begin{customnumlist}\origenumerate\leftskip=0.6cm}%
{\origendenumerate\end{customnumlist}}
And now it works as desired.
enum3.png
enum3.png (14.84 KiB) Viewed 3817 times
Post Reply