在下面的代码中,我想定义一些特殊项目,这些项目在后续使用的项目之前添加内容。
\documentclass[12pt]{article}
\usepackage{amssymb}
\newcommand\squareitem{\item}
\newcommand\bulletitem{\item}
\begin{document}
What I want to type using special items.
\begin{itemize}
\squareitem Item 1
\item Item 2
\bulletitem Item 3
\end{itemize}
What I would like to do without typing all the code.
\begin{itemize}
\item Item 1
\hfill $\square$
\item Item 2
\item Item 3
\hfill \textbullet
\end{itemize}
\end{document}
答案1
\documentclass[12pt]{article}
\usepackage{amssymb}
\let\svitem\item
\let\itemtag\relax
\newcommand\squareitem{\let\nextitemtag S\item}
\newcommand\bulletitem{\let\nextitemtag B\item}
\newenvironment{tagitemize}{
\renewcommand\item{%
\ifx S\itemtag\par\hfill$\square$\par\fi
\ifx B\itemtag\par\hfill$\bullet$\par\fi
\let\itemtag\nextitemtag\let\nextitemtag\relax
\svitem
}
\itemize
}{%
\ifx S\itemtag\par\hfill$\square$\par\fi
\ifx B\itemtag\par\hfill$\bullet$\par\fi
\enditemize}
\begin{document}
\begin{tagitemize}
\squareitem Item 1
\item Item 2
\bulletitem Item 3
\end{tagitemize}
\end{document}