我需要创建以下输出
1. [J1] bla bla bla
2. [J2] bla bla bla
....
13. [J13] bla bla bla
14. [C1] bla bla bla
15. [C2] bla bla bla
...
21. [B1] bla bla bla
有人知道如何获得它吗?
答案1
这也适用于引用。您不需要有\item
外部引用subenumerate
,它们只是作为示例添加的。
\documentclass{article}
\makeatletter
\newcounter{enumz}
\newenvironment{bienumerate}
{\enumerate\setcounter{enumz}{0}\let\item\bi@item}
{\endenumerate}
\newenvironment{subenumerate}[1]
{\setcounter{enumz}{0}\def\bi@prefix{#1}}
{}
\let\ltx@item\item
\newcommand{\bi@item}{%
\@ifundefined{bi@prefix}
{\ltx@item}
{\stepcounter{enumz}\ltx@item\relax
\protected@edef\@currentlabel{%
\@currentlabel~% <----------- comment this if you don't want the item number in the \ref
[\bi@prefix\theenumz]%
}%
[\bi@prefix\theenumz]~}%
}
\makeatother
\begin{document}
Test of reference: \ref{test}.
\begin{bienumerate}
\item bla bla bla
\begin{subenumerate}{J}
\item\label{test} bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\end{subenumerate}
\begin{subenumerate}{B}
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\end{subenumerate}
\item bla bla bla
\begin{subenumerate}{C}
\item bla bla bla
\item bla bla bla
\item bla bla bla
\end{subenumerate}
\end{bienumerate}
\end{document}
如果你注释掉标记的行,参考行将会像
答案2
像这样吗?
\documentclass{article}
\usepackage[inline]{enumitem}
\newlist{inlinelist}{enumerate*}{1}
\newcommand{\inlineformat}[1]{%
[#1]%
}
\setlist[inlinelist,1]{font={\bfseries},label*={\arabic*}}
\begin{document}
\begin{inlinelist}[label*={\inlineformat{J\arabic*}}]
\item Foo
\item Foobar
\end{inlinelist}
\begin{inlinelist}[label*={\inlineformat{C\arabic*}}]
\item Foobar
\item Foo
\item Otherstuff
\end{inlinelist}
\end{document}
答案3
这完全取决于你想如何指定语法。最简单的方法是定义与常规\item
类似列表不同的命令:
\documentclass{article}
\newcounter{numchar}
\newcommand{\numchar}{}
\newcommand{\setnumchar}[1]{%
\renewcommand{\numchar}{#1}% Update \numchar
\setcounter{numchar}{0}}% Reset numchar counter
\newcommand{\nextitem}{%
\item \relax\stepcounter{numchar}[\numchar\thenumchar]~\ignorespaces}
\begin{document}
\begin{enumerate}
\setnumchar{J}
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\setnumchar{C}
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\setnumchar{B}
\nextitem bla bla bla
\nextitem bla bla bla
\nextitem bla bla bla
\end{enumerate}
\end{document}
上面我已将其定义\nextitem
为\item
具有一些附加内容的。附加内容符合您的要求,如下所示\setnumchar
- 更新内部枚举的宏特点以及重置内部枚举。
如果您希望保留\item
-like 用法,则可以使用以下更新的定义\setnumchar
:
\documentclass{article}
\newcounter{numchar}
\newif\iffirstset
\newcommand{\numchar}{}
\newcommand{\setnumchar}[1]{%
\renewcommand{\numchar}{#1}% Update \numchar
\setcounter{numchar}{0}% Reset numchar counter
\iffirstset\else
\firstsettrue
\let\olditem\item
\renewcommand{\item}{%
\olditem\relax\stepcounter{numchar}[\numchar\thenumchar]~\ignorespaces}%
\fi
}
\begin{document}
\begin{enumerate}
\setnumchar{J}
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\setnumchar{C}
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\item bla bla bla
\setnumchar{B}
\item bla bla bla
\item bla bla bla
\item bla bla bla
\end{enumerate}
\end{document}