下面的 MWE 产生了以下图片:
我希望将制表符和间距参数声明为可选键值,以便语法如下所示:
\begin{tabbedenum}[tabs=2, spacing=3]
注意:tabbedenum
环境来自这个答案。
\documentclass{article}
\usepackage[inline]{enumitem}
\usepackage{tabto}
\newenvironment{tabbedenum}[2][]
{\NumTabs{#2}\begin{enumerate*}[
before={\unskip\hspace{\dimexpr-\parindent-1pt}\tab},itemjoin={\tab},#1]}%
{\end{enumerate*}}
\usepackage{setspace}
\begin{document}
\begin{enumerate}
\item Some text.
\begin{spacing}{3}
\begin{tabbedenum}{2}
\item $\displaystyle\sum_{r=1}^{n}x_r + \displaystyle\sum_{r=1}^{n}y_r = \displaystyle\sum_{r=1}^{n}(x_r+y_r)?$
\item $\displaystyle\sum_{r=1}^{n}x_r \cdot \displaystyle\sum_{r=1}^{n}y_r = \displaystyle\sum_{r=1}^{n}(x_r\cdot y_r)?$
\item $\displaystyle\sum_{r=1}^{n}(c\cdot x_r) = \displaystyle c\cdot\sum_{r=1}^{n}x_r?$
\item $\displaystyle\sum_{r=1}^{n}x_r + \displaystyle\sum_{r=1}^{n}y_r = \displaystyle\sum_{r=1}^{n}(x_r+y_r)?$
\end{tabbedenum}
\end{spacing}
\item Some text.
\end{enumerate}
\end{document}
答案1
以下是使用l3keys
和的方法environ
:
\documentclass{article}
\usepackage[inline]{enumitem}
\usepackage{tabto}
\newenvironment{tabbedenum}[2][]
{\NumTabs{#2}\begin{enumerate*}[
before={\unskip\hspace{\dimexpr-\parindent-1pt}\tab},itemjoin={\tab},#1]}%
{\end{enumerate*}}
\usepackage{expl3}
\usepackage{environ}
\ExplSyntaxOn
\cs_new:Nn \geoff_tse_parse_begin:nn {
\keys_set:nn { geoff/tse } { #1 }
\geoff_tse_begin:VVVn
\l_geoff_tse_spacing_tl \l_geoff_tse_tabs_tl \l_geoff_tse_enumopt_tl { #2 }
}
\cs_new:Nn \geoff_tse_begin:nnnn {
\begin{spacing}{ #1 }
\NumTabs{ #2 }
\begin{enumerate*}[
before={\unskip\hspace{\dimexpr-\parindent-1pt}\tab},
itemjoin={\tab},
#3]
#4
\end{enumerate*}
\end{spacing}
}
\cs_generate_variant:Nn \geoff_tse_begin:nnnn { VVVn }
\cs_generate_variant:Nn \geoff_tse_parse_begin:nn { nV }
\tl_new:N \l_geoff_tse_tabs_tl
\tl_new:N \l_geoff_tse_spacing_tl
\tl_new:N \l_geoff_tse_enumopt_tl
\keys_define:nn { geoff/tse }{
tabs .tl_set:N = \l_geoff_tse_tabs_tl,
tabs .initial:n = { 2 },
spacing .tl_set:N = \l_geoff_tse_spacing_tl,
spacing .initial:n = { 3 },
enumopt .tl_set:N = \l_geoff_tse_enumopt_tl,
enumopt .initial:n = { },
}
\NewEnviron{tabbedspacedenum}[1][]{
\geoff_tse_parse_begin:nV { #1 } \BODY
}
\ExplSyntaxOff
\usepackage{setspace}
\begin{document}
\begin{enumerate}
\item Some text.
\begin{spacing}{3}
\begin{tabbedenum}{2}
\item $\displaystyle\sum_{r=1}^{n}x_r + \displaystyle\sum_{r=1}^{n}y_r = \displaystyle\sum_{r=1}^{n}(x_r+y_r)?$
\item $\displaystyle\sum_{r=1}^{n}x_r \cdot \displaystyle\sum_{r=1}^{n}y_r = \displaystyle\sum_{r=1}^{n}(x_r\cdot y_r)?$
\item $\displaystyle\sum_{r=1}^{n}(c\cdot x_r) = \displaystyle c\cdot\sum_{r=1}^{n}x_r?$
\item $\displaystyle\sum_{r=1}^{n}x_r + \displaystyle\sum_{r=1}^{n}y_r = \displaystyle\sum_{r=1}^{n}(x_r+y_r)?$
\end{tabbedenum}
\end{spacing}
\item Some text.
\end{enumerate}
\clearpage
\begin{enumerate}
\item Some text.
\begin{tabbedspacedenum}
\item $\displaystyle\sum_{r=1}^{n}x_r + \displaystyle\sum_{r=1}^{n}y_r = \displaystyle\sum_{r=1}^{n}(x_r+y_r)?$
\item $\displaystyle\sum_{r=1}^{n}x_r \cdot \displaystyle\sum_{r=1}^{n}y_r = \displaystyle\sum_{r=1}^{n}(x_r\cdot y_r)?$
\item $\displaystyle\sum_{r=1}^{n}(c\cdot x_r) = \displaystyle c\cdot\sum_{r=1}^{n}x_r?$
\item $\displaystyle\sum_{r=1}^{n}x_r + \displaystyle\sum_{r=1}^{n}y_r = \displaystyle\sum_{r=1}^{n}(x_r+y_r)?$
\end{tabbedspacedenum}
\item Some text.
\end{enumerate}
\clearpage
\begin{enumerate}
\item Some text.
\begin{tabbedspacedenum}[tabs=4,spacing=1]
\item $4 + 5 > 6$?
\item $2 + 2 > 4$?
\item $2 + 2 > 4$?
\item $2 + 2 > 4$?
\end{tabbedspacedenum}
\item Some text.
\end{enumerate}
\end{document}