1

I would like to have a list of items using itemize and command.

It does not work if you have a command just before \myitem. Using command does not produce an item.

\iexitembegin is giving an error of formatting.

Would you have a solution? I would need really a possible way, ie. it is an important issue for daily use.

MWE:

\documentclass[a4paper]{article}

\hypersetup{pdftitle={Article},%
    pdfauthor={Username},%
    pdfdisplaydoctitle=true}

\usepackage[english]{babel}
\usepackage{sidecap}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{wrapfig}
\usepackage{titlepic}
\usepackage{indentfirst}
\usepackage{float}
\usepackage{enumerate}

\newcommand{\partone}[1]{
\begin{itemize}[topsep=0pt,itemsep=-1ex,partopsep=0pt,parsep=0pt, itemindent=-0ex,leftmargin=4.3ex]
\item[--] {\bfseries #1}
\end{itemize}
\smallskip
\smallskip
\smallskip
}

\newcommand{\myitem}[1]{\item[--] #1}
\newcommand{\myitembegin}{\begin{itemize}[noitemsep, topsep=0pt,itemsep=-1ex,partopsep=0pt,parsep=0pt]}
\newcommand{\myitemend}{\end{itemize}}

\title{Hello}
\date{}
\author{} 

\begin{document}
\maketitle

\partone{hello title}
\begin{itemize}[noitemsep, topsep=0pt,itemsep=-1ex,partopsep=0pt,parsep=0pt]
\item[--] test
\end{itemize}
\begin{itemize}[noitemsep, topsep=0pt,itemsep=-1ex,partopsep=0pt,parsep=0pt]
\item[--] test
\end{itemize}
\begin{itemize}[noitemsep, topsep=0pt,itemsep=-1ex,partopsep=0pt,parsep=0pt]
\item[--] test
\end{itemize}
\myitembegin
\myitem{hello world}
\myitem{lkdjfajdsfa}
\myitem{lkdjfajdsfa}
\myitem{toudouldsafjdslkdjfajdsfa}
\myitemend

\end{document}
  • 1
    As of now, your code is not compilable for several reasons: (1) hypersetup can only be used when hyperref is loaded. (2) You load enumerate but use the itemize environment. Try loading the enumitem package instead. – Troy Mar 8 '17 at 7:35
  • Can you also post the error message which pops up? "Error of formatting" is not really helpful at the moment.. – Troy Mar 8 '17 at 7:36
  • Instead of defining \myitembegin and \myitemend you should define a real environment. See the enumitem manual for more information about defining new list environments derivated from itemize. – Schweinebacke Mar 8 '17 at 7:43
1

Like @Schweinebacke wrote, you should define a real environment rather than using \newcommand, which can have unexpected results, when used for more complicated things than just inserting a small macro.

The enumitempackage can do exactly what you want. I copied your MWE and edited it to perform the task you're looking for. Basically, I just changed \myitembeginto \newlist{myitem}{2}, where 2 is the max depth of the list.

Next line is \setlist[myitem]{key-val options}, where you define the item label and other list-specific options. The complete example looks like this (I added the hyperref package to accomodate your MWE):

\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage{sidecap}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{wrapfig}
\usepackage{titlepic}
\usepackage{indentfirst}
\usepackage{float}
\usepackage{enumerate}
\usepackage{hyperref}
\usepackage{enumitem}

\hypersetup{pdftitle={Article},%
    pdfauthor={Username},%
    pdfdisplaydoctitle=true}


\newcommand{\partone}[1]{
\begin{itemize}[topsep=0pt,itemsep=-1ex,partopsep=0pt,parsep=0pt, itemindent=-0ex,leftmargin=4.3ex]
\item[--] {\bfseries #1}
\end{itemize}
\smallskip
\smallskip
\smallskip
}

\newlist{myitem}{itemize}{2}
\setlist[myitem]{label={--},noitemsep, topsep=0pt,itemsep=-1ex,partopsep=0pt,parsep=0pt}

\title{Hello}
\date{}
\author{} 

\begin{document}
\maketitle

\partone{hello title}
\begin{itemize}[noitemsep, topsep=0pt,itemsep=-1ex,partopsep=0pt,parsep=0pt]
\item[--] test
\end{itemize}
\begin{itemize}[noitemsep, topsep=0pt,itemsep=-1ex,partopsep=0pt,parsep=0pt]
\item[--] test
\end{itemize}
\begin{itemize}[noitemsep, topsep=0pt,itemsep=-1ex,partopsep=0pt,parsep=0pt]
\item[--] test
\end{itemize}
\begin{myitem}
\item hello world
\item lkdjfajdsfa
\item lkdjfajdsfa
\item toudouldsafjdslkdjfajdsfa
\end{myitem}

\end{document}

Most of the packages are not used for anything particular, but I left them in the MWE to show that they do not interfere with the desired output, as shown below pdflatex output

Hope this helps you out.

1

I'm not sure what's the purpose of itemsep=-1ex. You can just define your own itemize variant.

In the code below I dropped all unnecessary packages; for your document add the ones you need, of course.

\documentclass[a4paper]{article}
\usepackage{enumitem}

\newcommand{\partone}[1]{%
\begin{itemize}[
  label=--,
  topsep=0pt,
  itemsep=-1ex,
  partopsep=0pt,
  parsep=0pt,
  itemindent=-0ex,
  leftmargin=4.3ex
]
\item \textbf{#1}
\end{itemize}
\addvspace{\medskipamount}
}

\newenvironment{myitemize}
 {\begin{itemize}[label=--,noitemsep, topsep=0pt,itemsep=0pt,partopsep=0pt,parsep=0pt]}
 {\end{itemize}}

\begin{document}

\partone{hello title}
\begin{myitemize}
\item hello world
\item lkdjfajdsfa
\item lkdjfajdsfa
\item toudouldsafjdslkdjfajdsfa
\end{myitemize}

\end{document}

enter image description here

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.