我想要得到以下信息:
为此我使用了以下代码:
\documentclass{book}
\usepackage{enumerate}
\begin{document}
\begin{enumerate}
\item First item
\item Second item
\end{enumerate}
[Hint:
\begin{enumerate}
\item Hint for first item
\item Hint for Second item
\end{enumerate}]
\end{document}
生成:
我怎样才能得到我想要的确切结果?
答案1
我不知道您是否愿意接受建议,但是这里有一个:
\documentclass{article}
\newcounter{hintcntr}
%\renewcommand{\thehintcntr}{\arabic{hintcntr}}
\makeatletter
\newenvironment{hints}
{% \begin{hints}
\setcounter{hintcntr}{0}% Restart numbering
\renewcommand{\item}{\stepcounter{hintcntr}\@ifstar\@itemstar\@itemnostar}
\def\@itemstar{\ignorespaces}% \item*
\def\@itemnostar{\ignorespaces\thehintcntr.~}% \item
\par%
[~Hint:%
}
{\unskip~]}% \end{hints}
\makeatother
\begin{document}
\begin{enumerate}
\item First item
\item Second item
\item Third item
\item Last item
\end{enumerate}
\begin{hints}
\item Hint for first item in list
\item Hint for second item in list
\item*% no hint here
\item Hint for last item in list
\end{hints}
\end{document}
环境hints
设置一个常规段落并\item
打印下一个提示,而\item*
仅仅步进提示计数器而不打印任何内容。
hints
以下是与您当前请求的输出相匹配的环境的实现:
\newcounter{hintcntr}
%\renewcommand{\thehintcntr}{\arabic{hintcntr}}
\makeatletter
\newenvironment{hints}
{% \begin{hints}
\setcounter{hintcntr}{0}% Restart numbering
\def\newpar{\def\newpar{\par}}% http://tex.stackexchange.com/a/89187/5764
\renewcommand{\item}{\stepcounter{hintcntr}\@ifstar\@itemstar\@itemnostar}
\def\@itemstar{\ignorespaces}% \item*
\def\@itemnostar{\ignorespaces\newpar\noindent\thehintcntr.~}% \item
\par\noindent%
[~Hint:%
}
{\unskip~]}% \end{hints}
\makeatother
答案2
另一个选择是使用enumitem
包及其inline
选项以及enumerate*
用于内部列表的。可以轻松设置新列表以产生所需的输出:
\documentclass{book}
\usepackage[inline]{enumitem}
\newlist{hint}{enumerate*}{1}
\setlist[hint,1]{label=\arabic*.}
\newenvironment{hints}
{[Hint:~\begin{hint}}
{\end{hint}]}
\begin{document}
\begin{enumerate}
\item First item
\item Second item
\end{enumerate}
\begin{hints}
\item Hint for first item \\
\item Hint for Second item
\end{hints}
\end{document}