11

How can i create this list in Latex

enter image description here

Here's my MW

\documentclass{book}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}[label=Group \arabic*.]
\item 
\begin{enumerate}[label=\alph*)]
\item very very very very very very very  very very very very very very very long Text 1
\item very very very very very very very long sentence 2
\item very very very very very very very long sentence 3
\item very very very very very very very very very very very very very very long sentence 4
\end{enumerate}
\item 
\begin{enumerate}[label=\alph*)]
\item very very very very very very very very very very very very very very very very very very very very very long sentence 1
\item very very very very very very very long sentence 2
\item very very very very very very very long sentence 3
\item very very very very very very very long sentence 4
\end{enumerate}
\end{enumerate}
\end{document}

Is it possible to add text above line

1
  • 5
    nitpick ... this list isn't perfect. in the unanswered questions, the rule is drawn at the baseline; in the answered questions, it is slightly below the baseline so that it doesn't touch the bottoms of the answers that don't have descenders. "below" is the proper way. Nov 3 '17 at 16:45
13

Edit

My first solution was causing havoc with the way that enumitem aligns labels and the item text, so I have changed it slightly so that I now use the enumitem \SetLabelAlign command. This is, in fact, slightly easier than what I did previously.

Here is a different approach where I define a new enumerate like environment called underrated -- since we are underlining in an enumerate environment:

\newlist{underrated}{enumerate}{1}% define a new eumerate-like environment
\setlist[underrated]{%
    before=\let\item\underlineItem, % Set \item -> \underlineItem
    align=underline,% use underline "style" above
    label=\alph*),
    ref=\alph*,
    leftmargin=40mm,
    labelwidth=42mm,
}

The idea is to define a new "alignment style", underline, that will put the line before the item labels. There is a catch, however, in that when there is some text to be underlined, like the underline me in \item[underline me], we need to "pass" this text from \item back to the underline style. This is done by hijacking the \item command and replacing it with \underlineItem:

\let\realItem\item% save the original \item command for later use
\newcommand\underlineItem[1][]{%
   \def\underratedText{#1}%  
   \realItem\ignorespaces%
 }

So all that this really does is define \underratedText, which is used in the new label alignment style, and then call the real \item. To define this style we essentially just underline the text, following the example in the enumitem manual:

\SetLabelAlign{underline}{\parbox[t]\labelwidth{%
   \underline{\hbox to 36mm{\quad\texttt{\underratedText}}}\space#1}%
}

For good measure I also defined a new enumerate like environment, MyGroup, for the groups. With this set up, the code:

  \begin{MyGroup}
    \item\mbox{}
      \begin{underrated}
        \item A lunar eclipse is an omen of a coming disaster
        \item Superstitions have been around forever
        \item[an answer] People hold many superstitious beliefs about
        the moon
        \item[another answer] It is made of green cheese
      \end{underrated}

    \item\mbox{}
      \begin{underrated}
        \item The history of astronomy is interesting
        \item Ice age people recorded the appearance of new moons by
        making scratches in animal bones
        \item For example, Stonehenge in Britain,m build 3500 years
        ago to track the movement of the sun
        \item Ancient people observed and recorded lunar and solar
        events in different ways
      \end{underrated}
  \end{MyGroup}

produces

enter image description here

The \mbox's after the \item are necessary to force enumerate to start a new line; see Forcing new line after item number in enumerate environment.

Here is the full code:

\documentclass{book}
\usepackage{enumitem}

\let\realItem\item% save the original \item command for later use
\newcommand\underlineItem[1][]{%
   \def\underratedText{#1}\realItem\ignorespaces%
}
\SetLabelAlign{underline}{%
   \parbox[t]\labelwidth{%
      \underline{\hbox to 36mm{\quad\texttt{\underratedText}}}%
      \space#1%
   }%
 }

\newlist{underrated}{enumerate}{1}% define a new eumerate-like environment
\setlist[underrated]{%
    before=\let\item\underlineItem, % Set \item -> \underlineItem
    align=underline,% use underline "style" above
    label=\alph*),
    ref=\alph*,
    leftmargin=40mm,
    labelwidth=42mm,
}
\newlist{MyGroup}{enumerate}{1}
\setlist[MyGroup]{
   label=\bfseries Group \arabic*:,
   style=nextline,
   leftmargin=*,
   labelsep=2em,
   itemsep=2em
}

\begin{document}
  \begin{MyGroup}
    \item\mbox{}
      \begin{underrated}
        \item A lunar eclipse is an omen of a coming disaster
        \item Superstitions have been around forever
        \item[an answer] People hold many superstitious beliefs about
        the moon
        \item[another answer] It is made of green cheese
      \end{underrated}

    \item\mbox{}
      \begin{underrated}
        \item The history of astronomy is interesting
        \item Ice age people recorded the appearance of new moons by
        making scratches in animal bones
        \item For example, Stonehenge in Britain,m build 3500 years
        ago to track the movement of the sun
        \item Ancient people observed and recorded lunar and solar
        events in different ways
      \end{underrated}
  \end{MyGroup}
\end{document}
4
  • 1
    Very good. But: (a) You do not need xparse here and (b) using \ignorespaces after \space should fix the optional argument issue.
    – TeXnician
    Nov 3 '17 at 15:43
  • @TeXnician Thanks very much, this fixes my problem!! I have updated the code. I should have thought of adding \ignorespaces.
    – user30471
    Nov 3 '17 at 15:46
  • @Andrew Could you please fix the problem of alignement when the text is too long is start from begining of the line which make it under an answer i.stack.imgur.com/JO2Na.jpg
    – Educ
    Nov 3 '17 at 16:30
  • 3
    @Educ This needed a slight variation on the original idea. This is why you should give a full "MWE" :)
    – user30471
    Nov 3 '17 at 17:49
9

One version:

list

\documentclass{book}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}[label=Group \arabic*.]
\item 
\begin{enumerate}[leftmargin=3.75cm,label={\rule{3cm}{.5pt}~\alph*)}]
\item long sentence 1
\item long sentence 2
\item long sentence 3
\item long sentence 4
\end{enumerate}
\item
\begin{enumerate}[leftmargin=3.75cm,label={\rule{3cm}{.5pt}~\alph*)}]
\item long sentence 1
\item long sentence 2
\item long sentence 3
\item long sentence 4
\end{enumerate}
\end{enumerate}
\end{document}

Version 2:

list 2

\documentclass{book}
\usepackage{enumitem}

\newcounter{group}
\newenvironment{groupenv}{%
    \refstepcounter{group}%
    \noindent Group~\thegroup.
    \begin{enumerate}[leftmargin=3.75cm,label={\rule{3cm}{.5pt}~\alph*)}]
}{
    \end{enumerate}
}
\begin{document}
\begin{groupenv}
\item long sentence 1
\item long sentence 2
\item long sentence 3
\item long sentence 4
\end{groupenv}
\begin{groupenv}
\item long sentence 1
\item long sentence 2
\item long sentence 3
\item long sentence 4
\end{groupenv}
\end{document}

With simple overlays:

list with text

\documentclass{book}
\usepackage{enumitem}

\usepackage{tikz}
\usetikzlibrary{tikzmark}

\newcounter{group}
\newenvironment{groupenv}{%
    \refstepcounter{group}%
    \noindent Group~\thegroup.
    \begin{enumerate}[leftmargin=3.75cm,label={\rule{3cm}{.5pt}~\alph*)}]
}{
    \end{enumerate}
}
\begin{document}
\begin{groupenv}
\item\tikzmark{test1} long sentence 1
\item\tikzmark{test2} long sentence 2
\item\tikzmark{test3} long sentence 3
\item\tikzmark{test4} long sentence 4
\end{groupenv}
\begin{tikzpicture}[overlay,remember picture]
    \node at ([xshift=-2.25cm,yshift=.5\baselineskip]pic cs:test1) {this is test};
    \node at ([xshift=-2.25cm,yshift=.5\baselineskip]pic cs:test2) {this is tested};
    \node at ([xshift=-2.25cm,yshift=.5\baselineskip]pic cs:test3) {this is untested};
    \node at ([xshift=-2.25cm,yshift=.5\baselineskip]pic cs:test4) {this is a test};
\end{tikzpicture}
\begin{groupenv}
\item long sentence 1
\item long sentence 2
\item long sentence 3
\item long sentence 4
\end{groupenv}
\end{document}
3
  • Is it possible to add text above line
    – Educ
    Nov 3 '17 at 14:35
  • could you please make it automatic i don't wanna repeat copy past code of tex. Thank you
    – Educ
    Nov 3 '17 at 15:10
  • @Educ You may do it yourself using \newcommand. If you want to fill more than just one group (which I suspect that manual filling is okay), then please clarify your question. Maybe one would choose another approach for this.
    – TeXnician
    Nov 3 '17 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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