9

I want to get the following :

enter image description here

For this I have used the the following code:

\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}

which produces :
enter image description here

How can I do the exact result which I want ?

Soumitra Sen
  • 2,995

2 Answers2

8

Another option would be to use the enumitem package with its inline option and an enumerate* for the inner list. A new list can be easily set to produce the desired output:

\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}

enter image description here

Gonzalo Medina
  • 505,128
6

I don't know whether you're up for suggestions, but here's one:

enter image description here

\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}

The hints environment sets a regular paragraph with \item printing the next hint, while \item* just steps the hint counter without printing anything.


Here's an implementation of the hints environment that matches in output what you're currently requesting:

enter image description here

\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
Werner
  • 603,163