1

I attempted creating a custom list as shown in the code below, but I need to know how to create a custom list with different label types (Arabic, Roman, etc.) and change the color of the frame for a specific label ( e.g. \item[blue] instead of red )?

Currently, I have separate lists for each label type and for each label color and I'm not sure how to make the color an optional argument in the list definition ( e.g. \begin{boxati}[label=(red)] ) or change the label type as in \label=(\arabic*).

Can someone please provide a solution that enables me to implement both or either of the features in the same list definition?

\documentclass{article}
\usepackage{amsmath,amsfonts}
\usepackage{tikz}

%==== Custom List : Roman ====%

\newcounter{boxlblcntri}  
\newcommand{\makeboxlabeli}[1]{\tikz[baseline=(char.base)]{
      \node[rounded corners=3pt, draw=red!50,thick,
      inner sep=4pt,minimum width =15pt,minimum height =15pt](char){#1};}}
\newenvironment{boxati}
{\begin{list}
      {\roman{boxlblcntri}}
      {\usecounter{boxlblcntri}
          \setlength{\labelwidth}{3.5em} 
          \setlength{\labelsep}{-12pt}   
          \setlength{\itemsep}{2pt}
          \setlength{\topsep}{6pt}
          \setlength{\leftmargin}{1.1cm}
          \setlength{\rightmargin}{0cm}
          \setlength{\itemindent}{0pt} 
          \let\makelabel=\makeboxlabeli
      }
  }
  {\end{list}}

\begin{document}

  \begin{boxati}
     \item 1
     \item 2
     \item 3
  \end{boxati}

\end{document}

An example of the list :

roman_list

2
  • 1
    Welcome to TeX.SX! Did you check the enumitem package? Apr 1, 2023 at 19:54
  • Thank you for the suggestion, I did try the enumitem package and made some progress, a very similar case was in this question link , but I couldn't figure out how to change the color as an optional argument. Apr 1, 2023 at 22:58

1 Answer 1

1

You could make use of expl3's keyval mechanism:

\documentclass{article}
\usepackage{tikz}

%==== Custom List : Roman ====%

\ExplSyntaxOn
\keys_define:nn { boxkeyval } {
    counter .tl_set:N = \l__boxkeyval_counter_tl,
    counter .initial:n = roman,
    color   .tl_set:N = \l__keyval_color_tl,
    color   .initial:n = red       
}
\newcounter{boxlblcntri}  
\newcommand{\makeboxlabeli}[1]{%
    \tikz[baseline=(char.base)]{
        \node[
            rounded~corners=3pt, 
            draw=\l__keyval_color_tl!50,
            thick, 
            inner~sep=4pt, 
            minimum~width=15pt,
            minimum~height=15pt
        ] (char) {#1}; 
    }%
}
\NewDocumentEnvironment{boxati}{ O{} +b }{
    \group_begin:
        \keys_set:nn { boxkeyval } { #1 }
        \begin{list}
            {\csname\l__boxkeyval_counter_tl\endcsname{boxlblcntri}}
            {   
                \usecounter{boxlblcntri}
                \setlength{\labelwidth}{3.5em} 
                \setlength{\labelsep}{-12pt}   
                \setlength{\itemsep}{2pt}
                \setlength{\topsep}{6pt}
                \setlength{\leftmargin}{1.1cm}
                \setlength{\rightmargin}{0cm}
                \setlength{\itemindent}{0pt} 
                \let\makelabel=\makeboxlabeli
            }
        #2
        \end{list}
    \group_end:
}{}
\ExplSyntaxOff

\begin{document}

\begin{boxati}
    \item 1
    \item 2
    \item 3
\end{boxati}

\begin{boxati}[counter=arabic, color=blue]
    \item 1
    \item 2
    \item 3
\end{boxati}

\end{document}

enter image description here

1
  • Thank you so very much for your detailed and helpful response. It's much appreciated! Apr 1, 2023 at 23:05

You must log in to answer this question.

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