我试图使用被注释掉的行,但除非我不使用 hyperref,否则它会失败。
错误信息相当隐晦,因为
! Missing \endcsname inserted.
<to be read again>
我似乎无法确定此事的原因。
\documentclass{article}
\usepackage{hyperref}
\usepackage{enumitem, calc}
\newlist{probenum}{enumerate}{1}
\setlist[probenum]{label=\textbf{\arabic*}.}
\def\horizenum#1#2#3{
\flushleft
\dimen0 \linewidth
\divide\dimen0 by #1\relax
\def\item{\hfil\egroup\penalty50 \hfill
\refstepcounter{#2}%
\leavevmode\hbox to \dimen0 \bgroup\space#3\space}%
\leavevmode\bgroup\hskip 0pt plus -1fill }
\def\endhorizenum{\hfil\egroup\endflushleft}
\begin{document}
\newcounter{test}
\setcounter{test}{0}
%\begin{horizenum}{2}{probenumi}{\textbf{\arabic{probenumi}.}}
\begin{horizenum}{2}{test}{\textbf{\arabic{test}.}}
\item Monday
\item Tuesday
\item Wednesday
\item Thursday
\end{horizenum}
\end{document}
答案1
您需要hyperref
在提供新定义后进行加载。通常hyperref
应尽可能晚地加载,因为它会尝试修改和挂接到各种预先存在的命令。
\documentclass{article}
\usepackage{enumitem,calc}
\newlist{probenum}{enumerate}{1}
\setlist[probenum]{label=\textbf{\arabic*}.}
\def\horizenum#1#2#3{
\flushleft
\dimen0 \linewidth
\divide\dimen0 by #1\relax
\def\item{\hfil\egroup\penalty50 \hfill
\refstepcounter{#2}%
\leavevmode\hbox to \dimen0 \bgroup\space#3\space}%
\leavevmode\bgroup\hskip 0pt plus -1fill }
\def\endhorizenum{\hfil\egroup\endflushleft}
\usepackage{hyperref}
\begin{document}
\begin{horizenum}{2}{probenumi}{\textbf{\arabic{probenumi}.}}
\item Monday
\item Tuesday
\item Wednesday
\item Thursday
\end{horizenum}
\end{document}
答案2
您必须改变加载包的顺序。
hyperref 应该是最后一个包,并且必须在 hyperref 之前加载环境
acts.
\documentclass{article}
\usepackage{enumitem,calc}
\newlist{probenum}{enumerate}{1}
\setlist[probenum]{label=\textbf{\arabic*}.}
\usepackage{hyperref}
\def\horizenum#1#2#3{%
\flushleft
\dimen0\linewidth%
\divide\dimen0 by #1\relax%
\def\item{\hfil\egroup\penalty50 \hfill%
\refstepcounter{#2}%
\leavevmode\hbox to \dimen0 \bgroup\space#3\space}%
\leavevmode\bgroup\hskip 0pt plus -1fill}
\def\endhorizenum{\hfil\egroup\endflushleft}
\begin{document}
\makeatletter
\newcounter{test}
\setcounter{test}{0}
\begin{horizenum}{2}{probenumi}{\textbf{\arabic{probenumi}.}}
% \begin{horizenum}{2}{test}{\textbf{\arabic{test}.}}
\item Monday
\item Tuesday
\item Wednesday
\item Thursday
\end{horizenum}
\end{document}