2

I am making my own list, similar to enumerate. I want numbering to be aligned to the right, so everything looks like this:

 1. Text
    Text
11. Text
    Text

I also want to sometimes put a special symbol after automatically put number like (this doen't work, but I hope the idea is clear):

\item la-la-la
\item[*] difficult la-la-la

So I would like the document to look like:

 1. la-la-la
2*. difficult la-la-la

The problem is that it looks like:

 1. la-la-la
 *. difficult la-la-la

so the "2" is gone.

Is there any solution?

My code so far (I am using LuaLaTeX):

\documentclass[10pt]{extarticle}
\usepackage[top=0.5in, bottom=1.25in, left=1in, right=1in]{geometry}
\pagestyle{empty}

\usepackage{mathtools}
\usepackage{comment}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{skull}
\usetikzlibrary{shapes.geometric}
\usepackage{tabularx}
\setlength\tabcolsep{0pt}
\setlength{\columnsep}{1cm}
\usepackage{ragged2e}
\usepackage[russian]{babel}
\usepackage{mathptmx}
\usepackage{polyglossia}    
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Times New Roman}
\newfontfamily\cyrillicfont{Times New Roman}
\usepackage{mathrsfs}
\setmainlanguage{russian}
\usepackage{enumitem}
\usepackage{lipsum}


\newcounter{qcounter}
\newcommand{\TTT}[1]{#1:}

\newenvironment{questions}{
    \begin{list}{ 
        \hfill\bfseries\upshape\arabic{qcounter}.
    }{
        \renewcommand{\makelabel}{\TTT}%
        \usecounter{qcounter}
        \setlength{\labelwidth}{2em}
        \setlength{\leftmargin}{3em}
        \setlength{\labelsep}{1em}
        \setlength{\itemsep}{3pt}
        \setlength{\listparindent}{1em}
        \setlength{\parsep}{0pt}
        \setlength{\topsep}{6pt}
    } 
}{    
    \end{list}
}

\begin{document}
\lipsum[1]
    \begin{questions}
    \item \lipsum[1]
    \end{questions}
\end{document}
  • Please have a look at tex.stackexchange.com/questions/261582/enumerate-with-noindent – Yorgos Dec 7 '16 at 21:32
  • @Yorgos I am not sure I get to the point – Michael Fraiman Dec 7 '16 at 21:37
  • it's not clear what you want to achieve. You want your nested enumerate environment to start with 1*? (for instance) or you want to have some items like 1,2,3*,4,.....? From what i know, you can use enumitem package in order to modify your list – Yorgos Dec 7 '16 at 22:02
3

Assuming that you do not want to nest these environments, you can define a new enumerate-like environment using the enumitem package with the command:

\newlist{questions}{enumerate}{1}

This defines a questions environment that behaves like an enumerate environment and has 1 level of nesting (to allow nesting change {1} to give the required nesting level but you will also have to modify \fakeitem below). You can set the "properties" of your environment using the command:

\setlist[questions]{
   label=\arabic*.,   % label format
   leftmargin=*,      % indent labels
   before=\let\item\fakeitem,
}

The first two lines I have explained with comments. The before= command redefines the \item command to be \fakeitem only inside this environment. The idea is that we hijack \item to make it do what you want. The label counter for this environment is questionsi so we need \fakeitem to accept an optional argument, which it should add to the label, and we need to manually increment the counter:

\newcommand\fakeitem[1][\relax]{% argument defaults to \relax
   \refstepcounter{questionsi}%  increment label counter
   \realitem[\arabic{questionsi}#1.]}
}

Here \realitem is the original \item command.

Putting this together gives what you want:

enter image description here

Here is the full code:

\documentclass{article}
\usepackage{enumitem}

\let\realitem\item% save a copy of the \item command
\newcommand\fakeitem[1][\relax]{% argument defaults to \relax=do nothing
   \refstepcounter{questionsi}
   \realitem[\arabic{questionsi}#1.]% make label <questioni>#1.
}

\newlist{questions}{enumerate}{1}% define a new enumerate environment
\setlist[questions]{% define properties of questions
   label=\arabic*., % label format
   leftmargin=*,    % indent labels
   before=\let\item\fakeitem, % change the \item command
}

\usepackage{lipsum}% for MWe only

\begin{document}

    \begin{questions}
       \item la-la-la
       \item[*] difficult la-la-la
       \item[$\dag$] \lipsum[1]
    \end{questions}

\end{document}

Btw, there is another nice feature of using enumitem: if you would like all of the questions environments to use the same numbering then all you have to do is add resume to the \setlist command:

\setlist[questions]{
   label=\arabic*.,   % label format
   leftmargin=*,      % indent labels
   before=\let\item\fakeitem,
   resume             % use continuous numbering for the questions environments
}
  • I am now working to set the vertical spacing between items. I use itemsep=3pt. But it is bigger than 3pt, comparing to other part of the document, where the vertical space is made manually. What can be the solution here? – Michael Fraiman Dec 8 '16 at 17:06
  • @MichaelFreimann The enumitem manual is usually pretty good but it is a little vague on this point. The vertical spacing between items is controlled by itemsep and parsep. Adding itemsep=0pt and parsep=3pt to the \setlist command will probably give you want you want: this should give you 3pt separation between items and between paragraphs in items. The alternative is itemsep=3pt and parsep=0pt which will give 3pt between items and 0pt between paragraphs. – Andrew Dec 8 '16 at 23:03

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.