通过该format
选项,我可以在每个标签的开头注入代码description
:
\documentclass{article}
\usepackage{enumitem}
\begin{document}
\begin{description}[format={\ ...\ }]
\item[A] Apple
\item[B] Banana
\item[C] Carrot
\end{description}
\end{document}
我如何注入代码后每一个description
标签,实现下面的效果?
我主要感兴趣的是只影响单个特定的description
环境,而不是全部;但我也对使更改适用于所有description
环境的可能性感兴趣。
答案1
答案2
我确信这不是一个好的解决方案,但至少是一个可行的解决方案。我在线解释了我所做的。基本上,我在每个标签后都\item
添加了用户定义的位置。\addcode
\addcode
\documentclass{article}
\usepackage{enumitem}
\def\addcode{ Hi! $a+b=c$ :) \ldots} % This will be added after each `\item` (can be changed)
\makeatletter
\let\olditem\item % store old definition
\def\item{\@ifnextchar[{\item@with}{\item@without}} % if optional argument is given, call `\item@with`, else call `\item@without`
\def\item@with[#1]{\olditem[#1\addcode{}]}
\def\item@without{\olditem}
\makeatother
\begin{document}
\begin{description}
\item[A] Apple
\def\addcode{}
\item[B] Banana
\def\addcode{ Note that {[brackets]} need to be wrapped in curly braces }
\item[C] Carrot
\def\addcode{ Bye}
\item[D] Date
\end{description}
%
This will also effect \texttt{itemize} and similar environments.
\begin{itemize}
\item Test without
\item[A] Test with
\end{itemize}
Therefore you should initialize \texttt{\textbackslash addcode} with \texttt{\{\}}
\end{document}