4

I made this wishlist environment in a .cls file. However, it is not working. Instead of a star, I get a dot. On the other levels as well, it is a totally normal list without any of the labels I specified. The code looks like this:

\newenvironment{wishlist}{\begin{itemize}{\renewcommand{\labelitemi}{\color{orange}$\bigstar$}
    \renewcommand{\labelitemii}{\roman{enumii}}
    \renewcommand{\labelitemiii}{\textendash}
    \renewcommand{\labelitemiv}{\alph{enumvi}}
    }}
    {\end{itemize}}

I used these packages to make the lables:

\RequirePackage{xcolor}
\RequirePackage{pifont}
\RequirePackage{amssymb}
1
  • Why you not use enumitem package. It is high flexible and enable simple adoption to your needs.
    – Zarko
    Commented Nov 1, 2019 at 22:50

2 Answers 2

5

The label is set up when \begin{itemize} is executed. Therefore redefining \labelitemi etc. from within an \itemize environment has no effect. The solution is to put your \renewcommands before \begin{itemize}.

\documentclass{article}
\RequirePackage{xcolor}
\RequirePackage{pifont}
\RequirePackage{amssymb}

\newenvironment{wishlist}{
    \renewcommand{\labelitemi}{\color{orange}$\bigstar$}
    \renewcommand{\labelitemii}{\roman{enumii}}
    \renewcommand{\labelitemiii}{\textendash}
    \renewcommand{\labelitemiv}{\alph{enumvi}}
    \begin{itemize}}
    {\end{itemize}}

\begin{document}
\begin{wishlist}
\item AAA
\item BBB
\end{wishlist}
\end{document}

list

4
  • If the icons for the different wishlist levels shouldn't be applied to other itemize environments, it would be a good idea to wrap another set of braces around the definition to make it a local group. Commented Nov 1, 2019 at 22:58
  • \roman{enumii} does not work. I guess it's because it is an unordered list? Is there an easy way to make it work, or is this complicated?
    – Vebjorn
    Commented Nov 1, 2019 at 23:09
  • @barbarabeeton --- I can only see a problem if a wishlist appears inside an enumerate (or vice-versa), and I can't think of an easy way to fix that. That said, it's late here and I'm tired; if you can improve the code please feel free to edit. Commented Nov 1, 2019 at 23:16
  • 2
    @Vebjorn --- use enumerate rather than itemize and change itemi etc. to enumi. Commented Nov 1, 2019 at 23:17
4

I'd suggest enumitem:

\documentclass{article}
\usepackage{xcolor}
\usepackage{pifont}
\usepackage{amssymb}
\usepackage{enumitem}

\newlist{wishlist}{enumerate}{4}
\setlist[wishlist,1]{label=\textcolor{orange}{$\bigstar$}}
\setlist[wishlist,2]{label=\roman*}
\setlist[wishlist,3]{label=\textendash}
\setlist[wishlist,4]{label=\alph*}

\begin{document}

\begin{wishlist}
\item First (level 1)
\item Second (level 1)
  \begin{wishlist}
  \item First (level 2)
  \item Second (level 2)
    \begin{wishlist}
    \item First (level 3)
    \item Second (level 3)
      \begin{wishlist}
      \item First (level 4)
      \item Second (level 4)
      \end{wishlist}
    \end{wishlist}
  \end{wishlist}
\end{wishlist}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .