1

I have defined two custom enumitem environments with a grey background. The first one is for an inline itemize and a second one is for a normal itemize. The second one lost the bullets and I wonder why.

\documentclass[parskip=half]{scrbook}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\usepackage{tcolorbox}
\usepackage[inline, shortlabels]{enumitem}

% inline itemize
\newenvironment{inlineitem}[1][]
    {% begin-Befehle
        \begin{itemize*}[%
            %before=\hspace{1em},% Abstand vor dem ersten Aufzählungspunkt
            itemjoin=\hspace{1em},% Abstand zwischen zwei Aufzählungspunkten
            #1
        ]
    }
    {% end-Befehle
        \end{itemize*}%
    }
\newenvironment{MaterialInline}[1][]
    {% begin-Befehl
        \begin{tcolorbox}[%
            grow to left by=2mm,%
            left*=0mm,%
            grow to right by=2mm,%
            right*=0mm,%
            boxrule=0pt,% keine Rahmenlinie
            arc=0mm,% keinen Rundung in den Ecken
            ]%
        Material:~%
        \begin{itemize*}[%
            itemjoin=\hspace{1em},% Abstand zwischen zwei Aufzählungspunkten
            #1
        ]
    }
    {% end-Befehle
        \end{itemize*}%
        \end{tcolorbox}%
    }
\newenvironment{Material}[1][]
    {% begin-Befehl
        \begin{tcolorbox}[%
            grow to left by=2mm,%
            left*=0mm,%
            grow to right by=2mm,%
            right*=0mm,%
            boxrule=0pt,% keine Rahmenlinie
            arc=0mm,% keinen Rundung in den Ecken
            ]%
        \subsubsection{Material}
        \begin{itemize}[%
            #1
        ]
    }
    {% end-Befehle
        \end{itemize}%
        \end{tcolorbox}%
    }
\begin{document}


Done without a custom environment:


\begin{tcolorbox}[%
  grow to left by=2mm,%
  left*=0mm,%
  grow to right by=2mm,%
  right*=0mm,%
  boxrule=0pt,% keine Rahmenlinie
  arc=0mm,% keinen Rundung in den Ecken
  ]
  Material:~%
  \begin{inlineitem}
    \item Item 1
    \item Item 2
    \item Item 3
  \end{inlineitem}
\end{tcolorbox}

The following is done with the custom environment MaterialInline:


\begin{MaterialInline}
  \item Item 1
  \item Item 2
  \item Item 3
\end{MaterialInline}


Material without a custom environment:
\begin{tcolorbox}[%
  grow to left by=2mm,%
  left*=0mm,%
  grow to right by=2mm,%
  right*=0mm,%
  boxrule=0pt,% keine Rahmenlinie
  arc=0mm,% keinen Rundung in den Ecken
  ]
  \subsubsection{Material}
  \begin{itemize}
    \item Item 1
    \item Item 2
    \item Item 3
  \end{itemize}
\end{tcolorbox}


The following is done with the custom environment Material:
\begin{Material}
  \item Item 1
  \item Item 2
  \item Item 3
\end{Material}

\end{document}

enter image description here

0

2 Answers 2

3

By using

\begin{itemize}[%
            #1
        ]

the text (#1) becomes the label, so no bullets. (try with *~#1 to see what happens).

A correct definition would be

 ...
\subsubsection{Material}
    \begin{itemize}
    }
    {% end-Befehle
    \end{itemize}%
\end{tcolorbox}%
}

I guess when you add itemjoin= ... which is intended for the inline list, is ignored with everything that follows, and the correct vertical list is used.

You can also remove the #1 from the MaterialInline environment.

a

This is the complete code.

% !TeX TS-program = pdflatex


\documentclass[parskip=half]{scrbook}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\usepackage{tcolorbox}
\usepackage[inline, shortlabels]{enumitem}

% inline itemize
\newenvironment{MaterialInline}[1][]
{% begin-Befehl
    \begin{tcolorbox}[%
        grow to left by=2mm,%
        left*=0mm,%
        grow to right by=2mm,%
        right*=0mm,%
        boxrule=0pt,% keine Rahmenlinie
        arc=0mm,% keinen Rundung in den Ecken
        ]%
        Material:~%
        \begin{itemize*}[%
            itemjoin=\hspace{1em},% Abstand zwischen zwei Aufzählungspunkten
            ]
        }
        {% end-Befehle
        \end{itemize*}%
    \end{tcolorbox}%
}
\newenvironment{Material}[1][]
{% begin-Befehl
    \begin{tcolorbox}[%
        grow to left by=2mm,%
        left*=0mm,%
        grow to right by=2mm,%
        right*=0mm,%
        boxrule=0pt,% keine Rahmenlinie
        arc=0mm,% keinen Rundung in den Ecken
        ]%
        \subsubsection{Material}
        \begin{itemize} 
        }
        {% end-Befehle
        \end{itemize}%
    \end{tcolorbox}%
}
\begin{document}    
    
    The following is done with the custom environment MaterialInline:   
    
    \begin{MaterialInline}
        \item Item 1
        \item Item 2
        \item Item 3
    \end{MaterialInline}        
    
    The following is done with the custom environment Material:
    \begin{Material}
        \item Item 1
        \item Item 2
        \item Item 3
    \end{Material}
    
\end{document}
4
  • I do not want to remove #1 because \begin{Material}[<customize>] should work as a override for the default settings. For example \begin{Material}[label={--}] replaces the default bullet to a long minus symbol. I ask me why a lonely \begin{itemize}[#1] in my definition of the custom environment "Material" takes the bullet away. I suspect that the interpreter derives an empty symbol for the label from this? Is that what you meant to say with "the text becomes the label"? Did you actually mean to say "the #1 becomes the label"?
    – Michael.H
    May 31, 2022 at 18:01
  • My workaround is to leave the itemjoin=..., in front of #1. I know this is not straight path, but with this modification the code \begin{Material}[label={--}] works. Unlike what you write, the code is not ignored afterwards. Or did I misunderstand you there? Is there a better way to achive this? As we all know itemjoin is no option for itemize, but for inline itemize. That is the reason why I delete this option in my original code example. That's how I got into trouble.
    – Michael.H
    May 31, 2022 at 18:13
  • @Michael.H Thank you for your feedback! As I said : the text ( the parameter #1 of \item) becomes the label, so no bullets. (Try with *~#1 without the itemjoin= , to see what happens). May 31, 2022 at 18:49
  • If you want to keep the [...], maybe instead of passing blank as the default, pass label={<whatever bullet you want>} as the default? May 31, 2022 at 18:54
2

In definition for environment Material, you can determine if its optional argument is empty or not, and only use \begin{itemize}[#1] if #1 is non empty. For example

\usepackage{etoolbox} % already loaded by `tcolorbox`
\newenvironment{Material}[1][]
    {% begin-Befehl
        \begin{tcolorbox}[...]%
        \subsubsection{Material}
        \ifstrempty{#1}
          {\begin{itemize}}
          {\begin{itemize}[#1]}%
    }
    {% end-Befehle
        \end{itemize}%
        \end{tcolorbox}%
    }

This solves the missing-bullets problem, but introduces a minor new one: Now \begin{Material} \item ... is indistinguishable from \begin{Material}[] \item ... and you'll never be able to set an empty list label.

To overcome this, I recommend using xparse's arg-type o. It distinguishes "missing" (\begin{Material} \item ...) from "given by user" (\begin{Material}[<any value, even emtpy>] \item ...) for an optional argument.

\NewDocumentEnvironment{Material}{o}
    {% begin-Befehl
        \begin{tcolorbox}[...]%
        \subsubsection{Material}
        \IfValueTF{#1}
          {\begin{itemize}[#1]} % optional #1 is given by user
          {\begin{itemize}}     % optional #1 has no value
    }
    {% end-Befehle
        \end{itemize}%
        \end{tcolorbox}%
    }

You must log in to answer this question.

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