Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 ?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

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
share|improve this answer
    
Thank you @Werner for your great cooperation. My problem is solved, and +1 for you. –  Soumitra Sen Mar 17 at 22:44

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

share|improve this answer
    
@G.M. it shows 5 errors like : Unknown option inline' for package enumitem', Missing number, treated as zero\item. What are these? –  Soumitra Sen Mar 17 at 22:54
    
@SoumitraSen you are using an outdated version of enumitem. Please update the package. –  Gonzalo Medina Mar 17 at 22:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.