5

I am trying to construct my own custom list environment, and it would be a great help to solve the problem below.

I would like a list environment that took a mandatory argument which gave the text to be displayed as the label, so far I have this

\newenvironment{mylist}[1]
    {
    \begin{itemize}[label=#1]
    }{
    \end{itemize}
    }

This works so far, but when the text in a single list item overflows into the next line it looks like this

Example: aaaaaaaaaaaaaaaaaaaaaaaaaa
         aaaaaaaaaaaaaaaaaaaaaaaaaa

however I would like it to look like this

Example: aaaaaaaaaaaaaaaaaaaaaaaaaa
 aaaaaaaaaaaaaaaaaaaaaaaaaa

with the text on the second and subsequent lines at a definable distance from the left margin of the page (or from the left edge of the current environment, whatever that may be).

I have tried using the enumitem package, with the itemindent option, but all that seems to do is shift the second line left relative to its indented position. What I would like to do is shift the second line right from a non indented position.

Edit: a mwe

\documentclass[a4]{article}

\usepackage{enumitem}

%Used in my LaTeX document that I'm preparing, just in case there is some conflict between this and any proposed solution
\setlist{topsep=0mm,partopsep=0mm,parsep=0mm,itemsep=0.1mm,leftmargin=*}

\newenvironment{mylist}[1]
{
\begin{itemize}[label=#1]
}{
\end{itemize}
}

\begin{document}

\begin{mylist}{Example:}
    \item   Some text just to illustrate what happens when there is too much text and it overflows onto the next line.
\end{mylist}

\end{document}
  • 1
    It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill Jul 3 '16 at 5:18
  • I've now added a MWE :) – Eddy Jul 3 '16 at 5:27
  • @Eddy: Please post clear questions :-( – user31729 Jul 3 '16 at 6:22
  • @ChristianHupfer sorry, I'll try to post less minimal working examples in future so it's clear what the problem is. I do appreciate the help though :) – Eddy Jul 3 '16 at 6:25
  • @Eddy: Actually, my example did what you requested, indenting the first and the second level. You're misusing the features of enumitem by defining an extra mylist environment whereas this could be done with \newlist more easily. – user31729 Jul 3 '16 at 6:26
4

The following MWE will help you solve the problem:

\documentclass[a4paper]{article}

\usepackage{enumitem}
\usepackage{lipsum}

%Used in my LaTeX document that I'm preparing, just in case there is some conflict between this and any proposed solution

\setlist[itemize]{wide,topsep=0mm,partopsep=0mm,parsep=0mm,itemsep=0.1mm,labelindent=0pt,leftmargin=0pt}

\newenvironment{mylist}[1]
{
\begin{itemize}[label=#1]
}{
\end{itemize}
}



\begin{document}
\lipsum[1]
\begin{mylist}{Example:}
    \item   Some text just to illustrate what happens when there is too much text and it overflows onto the next line.
    \item   Some text just to illustrate what happens when there is too much text and it overflows onto the next line.
\end{mylist}
\lipsum[1]

\end{document}

I have now change \setlist from:

\setlist{topsep=0mm,partopsep=0mm,parsep=0mm,itemsep=0.1mm,leftmargin=*}

to

\setlist[itemize]{wide,topsep=0mm,partopsep=0mm,parsep=0mm,itemsep=0.1mm,labelindent=0pt,leftmargin=0pt}

You can adjust leftmargin=<dimension> to set the left margin from second line onwards.

  • So leftmargin=* aligns the content with the label, but leftmargin=<dimension> sets the distance between the left margin and the content? – Eddy Jul 3 '16 at 6:11
  • @Eddy: Yes. It is right. – Jagath Jul 3 '16 at 6:14
  • 1
    Ok, great! glad it was me being dumb and not that this was something really hard. Thanks for your help :) – Eddy Jul 3 '16 at 6:15
  • 1
    @Jagath AR: wide, labelindent=0pt can be shortened to wide=0pt. – Bernard Jul 3 '16 at 10:47

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.