4

How can I typeset just the b (a subitem's label) without the 2 (the enclosing item's label) from a inparaenum list within a enumerate list?

enter image description here

\documentclass {article}
\usepackage {paralist}
\begin {document}

\noindent
Here is my list:

\begin {enumerate}

  \item First item.

  \item Second item:
      \begin {inparaenum}[(a)]
      \item \label {first}  first subitem,
      \item \label {second} second subitem.
      \end {inparaenum}

\end {enumerate}

\noindent
I want to typeset `b' not `\ref {second}'.

\end {document}
n.r.
  • 4,942

2 Answers2

2

The crossreference format is stored in a macro named \p@enumi etc.

paralist's inparaenum extends enumerate (up to 6 levels) and uses the counters enumi,..., enumvi then.

For the second level (it's nested in enumerate already, the \p@enumii format uses \theenumi, i.e. the current first level value, which is 2 in the current example.

The solution is to define \p@enumii to be empty.

\documentclass {article}



\usepackage {paralist}

\makeatletter
\renewcommand{\p@enumii}{}
\makeatother

\begin {document}
\noindent
Here is my list:

\begin {enumerate}
  \item First item.
  \item Second item:
    \begin {inparaenum}[(a)]
    \item \label {first}  first subitem,
    \item \label {second} second subitem.
    \end {inparaenum}
\end {enumerate}



\noindent
I want to typeset `b' not `\ref {second}'.

\end {document}

enter image description here

Apparently, paralist does not allow to change the crossreference format otherwise, an alternative could be enumitem with its inline lists and the ref option.

  • It seems it's enough to put the \makeatletter ... \makeatother block inside the inparaenum environment, so as keep it local to that particular list, even if \ref is without. – n.r. May 03 '16 at 17:13
  • @n.r. Perhaps, yes. I thought it should be a global settlement –  May 03 '16 at 17:14
  • Smart and Perfect solution. Works for \items without the use of paralist package also ! – Partha D. Dec 03 '21 at 01:19
2

Define your own environment based on inparaenum:

\documentclass{article}
\usepackage{paralist}

\makeatletter
\def\zinparaenum{%
  \ifnum\@enumdepth>\thr@@
    \@toodeep
  \else
    \advance\@enumdepth\@ne
    \edef\@enumctr{enum\romannumeral\the\@enumdepth}%
  \fi
  \@ifnextchar[{\@enumlabel@{\@zinparaenum@}[}{\@zinparaenum@}}
\def\@zinparaenum@{%
  \usecounter{\@enumctr}%
  \@namedef{p@\@enumctr}{}%
  \def\@itemlabel{\csname label\@enumctr\endcsname}%
  \let\@item\pl@item
  \def\makelabel##1{##1}%
  \ignorespaces}
\let\endzinparaenum\ignorespacesafterend
\makeatother

\begin{document}

Here is my list:
\begin{enumerate}

\item First item.

\item Second item:
  \begin{zinparaenum}[(a)]
  \item \label{first}  first subitem,
  \item \label{second} second subitem.
  \end{zinparaenum}

\end{enumerate}
I want to typeset `b' not `\ref{second}'.

\end{document}

The references will be just to the local number, without any prefix, independent of the level of nesting.

enter image description here

If you look into paralist.sty, the code above is just the definition of inparaenum, where I added a z to every occurrence of inparaenum, besides the main change which is locally redefining \p@<counter>.

egreg
  • 1,121,712