Проблема перечисления, переопределяющая среду `перечисления`

Проблема перечисления, переопределяющая среду `перечисления`

Я хотел бы переопределить enumerateсреду с необязательным аргументом. По сути, я хочу переопределить \theenumiтак, чтобы каждый раз, когда я маркирую элемент и вызываю его, \refя получал реальную распечатанную метку, а не просто (арабское) значение counter enumi.

Я попробовал с кодом ниже, и он работает, за исключением того, что он всегда добавляет дополнительную точку ( .) к каждой метке. Когда я вызываю его с помощью, он \refпечатает правильную метку.

Вот MWE того, что я попробовал:

\documentclass{book}
\usepackage{enumerate}
%%
%%
\let\oldenumerate\enumerate
\let\endoldenumerate\endenumerate
\renewenvironment{enumerate}[1][\arabic{enumi}.]% Defaults to 1. 2. 3. ...
{%
    \bgroup\renewcommand\theenumi{#1}%
    \oldenumerate%
}%
{%
    \endoldenumerate\egroup%
}%
\begin{document}
First list with default enumeration
\begin{enumerate}
\item First item
\item Second item
\end{enumerate}
Second list with custom enumeration
\begin{enumerate}[(\emph{\roman{enumi}})]
\item First item
\item Second item
\end{enumerate}
Labels have an extra dot in the lists, but references \ref{a} and \ref{b} are printed correctly.
\end{document}

и это вывод приведенного выше кода:

Выход вышеуказанного MWE

Как мне переопределить enumerate, чтобы избежать лишней точки в списках?

решение1

Вместо того, чтобы изобретать велосипед, гораздо проще использовать пакет enumitemдля таких вещей. Для этого конкретного примера я добавил отрицательный керн, чтобы скобки были хорошо разделены курсивом. Как указывает Каннаппан Сампат, вы также можете указать формат ссылок отдельно.

\documentclass{article}
\usepackage{enumitem}
\begin{document}
Second list with custom enumeration
\begin{enumerate}[label=(\kern-.5pt\emph{\roman*}),ref=(\roman*)]
\item First item \label{a}
\item Second item \label{b}
\end{enumerate}
Labels have an extra dot in the lists, but references \ref{a} and \ref{b} are printed correctly.
\end{document}

введите описание изображения здесь

решение2

Вот решение с enumitem:

\documentclass{book}
\usepackage{enumitem}
%%% Set the default: number followed by a period
\setlist[enumerate,1]{label=\arabic*.}

\begin{document}
First list with default enumeration
\begin{enumerate}
\item First item
\item\label{a} Second item
\end{enumerate}
Second list with custom enumeration
\begin{enumerate}[label=(\emph{\roman*})]
\item First item
\item\label{b} Second item
\end{enumerate}
Labels have an extra dot in the lists, and references
\ref{a} and \ref{b} are printed correctly.
\end{document}

введите описание изображения здесь

Связанный контент