2

I am trying to create template for nested enumerated lists. The label of first list is aligned with left margin of the page (use environment FirstList). Then the subsequent nested lists is indented by some space (use environment SecondList). To indent the nested lists, I am using adjustwidth, however, it results in an extra pair of brackets. Please see figure below.

   \documentclass[12pt]{article}
 % Packages used in template.
 \usepackage{enumitem}
 \usepackage{changepage}
 \usepackage{etoolbox}

 % Set left, right, top, and bottom margins of the paper.
 \usepackage[a4paper, left = 1.5in, right = 0.70in, top = 0.5in, bottom = 2.2in]{geometry}
 \voffset = 0.15in
 \headsep = 31pt
 \topmargin = -48pt

 % Create new environments for listings
 \setlist[enumerate]{wide, align=left, topsep = 0in, parsep = 0.24in, partopsep = 0in, itemsep = 0in, labelindent = 0in, labelsep = 0.36in}
 \newenvironment{FirstList}[1][]{ \begingroup \let \olditem \item
     \renewcommand \item {\olditem
     \ifnum\value{enumi} > 9
     \setlength\hskip{-0.14in}
     \fi
     \ifnum\value{enumi} > 99
     \setlength\hskip{-0.14in}
     \fi
     \ifnum\value{enumi} > 999
     \setlength\hskip{-0.14in}
     \fi
     }
     \begin{enumerate}[#1] } {\end{enumerate} \endgroup}

 \newenvironment{SecondList}{ \begin{adjustwidth}{0.48in}{0in}
     \begin{enumerate}}{ \end{enumerate} \end{adjustwidth}}

 \begin{document}
     \begin{FirstList}

        \item This template is made for A4 page size. I will try to extend this point into more than two lines.

        \item In this template,

        \begin{SecondList}
            \item Left margin is $\mathrm{1.5}$ in.

            \item Right margin is $\mathrm{0.7}$ in.

        \end{SecondList}

        \item This is another enumerated point.

         \begin{SecondList}
            \item This is another enumerated point.

            \item This is another enumerated point.
        \end{SecondList}

         \item This is another enumerated point.

    \end{FirstList}
 \end{document}

enter image description here

Question No. 1- How to remove the extra brakets?

Question No. 2- Is it possible to create a single environment which can do this?

3 Answers 3

1

I leave you the details of the margins, which are not very clear from your question. In particular, add the desired values for rightmargin.

You can and should use a single environment for this and not overload enumerate.

I changed some of the values for geometry, first of all because \voffset should never be used for positioning the text block, nor you should modify \topmargin.

\documentclass[12pt]{article}
% Packages used in template.
\usepackage{enumitem}
\usepackage{changepage}
\usepackage{etoolbox}

% Set left, right, top, and bottom margins of the paper.
\usepackage[
  showframe,
  a4paper,
  left = 1.5in,
  right = 0.70in,
  top = 1in,
  bottom = 1.05in,
  headsep=31pt,
]{geometry}
%\voffset = 0.15in  %%%% <---- NO
%\headsep = 31pt    %%%% <---- NO
%\topmargin = -48pt %%%% <---- NO

% Create new environments for listings
\newlist{mylist}{enumerate}{3}
\setlist[mylist]{
  wide,
  align=left,
  topsep = 0in,
  parsep = 0.24in,
  partopsep = 0in,
  itemsep = 0in,
  labelsep = 0in,
  itemindent=0.5in,
  labelindent = -0.5in,
  labelwidth=0.5in,
}
\setlist[mylist,1]{leftmargin=0in,label=\arabic*.}
\setlist[mylist,2]{leftmargin=0.5in,label=(\alph*)}
\setlist[mylist,3]{leftmargin=1in,label=(\roman*)}

\begin{document}

\begin{mylist}

  \item This template is made for A4 page size. I will try to extend this point 
        into more than two lines.

  \item In this template,

  \begin{mylist}
    \item Left margin is $\mathrm{1.5}$ in.

    \item Right margin is $\mathrm{0.7}$ in.

  \end{mylist}

  \item This is another enumerated point.

  \begin{mylist}
    \item This is another enumerated point.

    \item This is another enumerated point.
  \end{mylist}

  \item This is another enumerated point.

\end{mylist}

\end{document}

enter image description here

2

Changing the SecondList environment to

\newenvironment{SecondList}
  {\begin{enumerate}[leftmargin=1in, rightmargin=0in, labelindent=*]}
  {\end{enumerate}}

works.

  • The leftmargin=1in, rightmargin=0in corresponds to your original \begin{adjustwidth}{0.48in}{0in}. Here I use a larger leftmargin since you have used a rather large labelsep = 0.36in.
  • The labelindent=* forces the re-computation.

Full example:

\documentclass[12pt]{article}
% Packages used in template.
\usepackage{enumitem}
\usepackage{changepage}
\usepackage{etoolbox}

% Set left, right, top, and bottom margins of the paper.
\usepackage[a4paper, left = 1.5in, right = 0.70in, top = 0.5in, bottom = 2.2in, showframe]{geometry}

% Create new environments for listings
\setlist[enumerate]{wide, align=left, topsep = 0in, parsep = 0.24in, partopsep = 0in, itemsep = 0in, labelindent = 0in, labelsep = 0.36in}

\newenvironment{FirstList}[1][]{ \begingroup \let \olditem \item
   \renewcommand \item {\olditem
   \ifnum\value{enumi} > 9
   \setlength\hskip{-0.14in}
   \fi
   \ifnum\value{enumi} > 99
   \setlength\hskip{-0.14in}
   \fi
   \ifnum\value{enumi} > 999
   \setlength\hskip{-0.14in}
   \fi
   }
   \begin{enumerate}[#1] } {\end{enumerate} \endgroup}

\newenvironment{SecondList}
  {\begin{enumerate}[leftmargin=1in, rightmargin=0in, labelindent=*]}
  {\end{enumerate}}

\begin{document}
   \begin{FirstList}

      \item This template is made for A4 page size. I will try to extend this point into more than two lines.

      \item In this template,

      \begin{SecondList}
          \item Left margin is $\mathrm{1.5}$ in.

          \item Right margin is $\mathrm{0.7}$ in.

      \end{SecondList}

      \item This is another enumerated point.

      \begin{SecondList}
          \item This is another enumerated point.

          \item This is another enumerated point.
      \end{SecondList}

      \item This is another enumerated point.

    \end{FirstList}
\end{document}

output of modified example


By the way,

  • Setting \voffset to non-zero value is not recommended and totally avoidable. Use geometry options and use them only is enough.
  • \setlist can set different styles for different levels of list, for example \setlist[enumerate, 2]{...}. Hence your FistList and SecondList environments are avoidable as well.
5
  • Thank you for your answer. Is it possible that the label of a nested list is directly below the text of parent list?
    – Ali Baig
    Mar 19, 2020 at 9:37
  • +1 For the fix but as you say at the end enumitem provides better tools for doing this
    – user30471
    Mar 19, 2020 at 10:44
  • @AliBaig You mean, you want to have "no vertical skip before (and maybe also after) nested list"? Mar 19, 2020 at 11:55
  • @muzimuzhiZ The label (a) of the SecondList and the text of item (1) should be at the same distance from the margin of the page.
    – Ali Baig
    Mar 19, 2020 at 17:57
  • @AliBaig Just remove options of enumerate env used inside the definition of SecondList env. Mar 20, 2020 at 4:57
1

As muzimuzhi said at the end of his nice post, the enumitem package provides better tools for doing this sort of thing. You can use \setlist[enumerate,1]{...} to set the parameters that you want for the first level of an enumerate environment and then \setlist[enumerate,2]{...} for the second level etc. Hence, following the suggestion muzimuzhi you can set up your enumerate environments with:

\setlist[enumerate,1]{
  wide,
  align=left,
  topsep = 0in,
  parsep = 0.24in,
  partopsep = 0in,
  itemsep = 0in,
  labelindent = 0in,
  labelsep = 0.36in,
}
\setlist[enumerate,2]{
  leftmargin=1in,
  rightmargin=0in,
  labelindent=*
}

This still leaves your custom \item command. Rather than defining this each time the FirstList environment is used I would move this code into the preamble as:

\let\olditem\item
\newcommand\MyItem {\olditem
   \ifnum\value{enumi} > 9   \setlength\hskip{-0.14in}\fi
   \ifnum\value{enumi} > 99  \setlength\hskip{-0.14in}\fi
   \ifnum\value{enumi} > 999 \setlength\hskip{-0.14in}\fi
}

and to get enumerate to use this you can add before=\let\item\MyItem to the \setlist command. Putting this in place, you can drop your FirstList and SecondList environments and just use enumerate (or you could, instead, define a new list environment with \newlist), so your MWE becomes

\documentclass[12pt]{article}
% Packages used in template.
\usepackage{enumitem}
\usepackage{changepage}
\usepackage{etoolbox}

% Set left, right, top, and bottom margins of the paper.
\usepackage[a4paper, left = 1.5in, right = 0.70in, top = 0.5in, bottom = 2.2in, showframe]{geometry}

\let\olditem\item
\newcommand\MyItem {\olditem
   \ifnum\value{enumi} > 9   \setlength\hskip{-0.14in}\fi
   \ifnum\value{enumi} > 99  \setlength\hskip{-0.14in}\fi
   \ifnum\value{enumi} > 999 \setlength\hskip{-0.14in}\fi
}

% Create new environments for listings
\setlist[enumerate,1]{
  wide,
  align=left,
  topsep = 0in,
  parsep = 0.24in,
  partopsep = 0in,
  itemsep = 0in,
  labelindent = 0in,
  labelsep = 0.36in,
  before=\let\item\MyItem
}
\setlist[enumerate,2]{
  leftmargin=1in,
  rightmargin=0in,
  labelindent=*
}

\begin{document}

   \begin{enumerate}
      \item This template is made for A4 page size. I will try to extend
      this point into more than two lines.

      \item In this template,

      \begin{enumerate}
          \item Left margin is $\mathrm{1.5}$ in.
          \item Right margin is $\mathrm{0.7}$ in.
      \end{enumerate}

      \item This is another enumerated point.

      \begin{enumerate}
          \item This is another enumerated point.
          \item This is another enumerated point.
      \end{enumerate}

      \item This is another enumerated point.

    \end{enumerate}

\end{document}

and the output is exactly the same as that in muzimuzhi's nice answer:

enter image description here

Edit

As far as I can see this does work properly with nesting? For example, \documentclass[12pt]{article} % Packages used in template. \usepackage{enumitem} \usepackage{changepage} \usepackage{etoolbox}

% Set left, right, top, and bottom margins of the paper.
\usepackage[a4paper, left = 1.5in, right = 0.70in, top = 0.5in, bottom = 2.2in, showframe]{geometry}

\let\olditem\item
\newcommand\MyItem {\olditem
   \ifnum\value{enumi} > 9   \setlength\hskip{-0.14in}\fi
   \ifnum\value{enumi} > 99  \setlength\hskip{-0.14in}\fi
   \ifnum\value{enumi} > 999 \setlength\hskip{-0.14in}\fi
}

% Create new environments for listings
\setlist[enumerate,1]{
  wide,
  align=left,
  topsep = 0in,
  parsep = 0.24in,
  partopsep = 0in,
  itemsep = 0in,
  labelindent = 0in,
  labelsep = 0.36in,
  before=\let\item\MyItem
}
\setlist[enumerate,2]{
  leftmargin=1in,
  rightmargin=0in,
  labelindent=*
}

\begin{document}

   \begin{enumerate}
      \item This template is made for A4 page size. I will try to extend
      this point into more than two lines.

      \item In this template,

      \begin{enumerate}
          \item This template is made for A4 page size. I will try to extend
          this point into more than two lines.
          \item Left margin is $\mathrm{1.5}$ in.
          \item Right margin is $\mathrm{0.7}$ in.
      \end{enumerate}

      \item This is another enumerated point.

      \begin{enumerate}
          \item This is another enumerated point.
          \item This template is made for A4 page size. I will try to extend
          this point into more than two lines.
          \item This is another enumerated point.
      \end{enumerate}

      \item This is another enumerated point.

    \end{enumerate}

\end{document}

produces:

enter image description here

2
  • Thank you for your reply. There is a little problem with your template. The second line in any nested level does not start below its label. For example, try
    – Ali Baig
    Mar 19, 2020 at 17:45
  • @AliBaig As far as I can see this works? See my edit.
    – user30471
    Mar 23, 2020 at 2:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .