7

I have defined a \newcommand called \NewEntry that takes two parameters and prints one above the other.

\newcommand{\NewEntry}[2]{
    #1 \\
    #2
}

Calling this command by

\NewEntry{ENTRY}
{\begin{itemize}[topsep=0pt]
\item First Item
\item Second Item
\end{itemize}
}

leads to a vertical space between "ENTRY" and "First item", even though topsep is set to zero.

enter image description here

I would like to remove this space.

If the command is called by

\NewEntry{ENTRY}
{Blah\begin{itemize}[topsep=0pt]
\item First Item
\item Second Item
\end{itemize}
}

then "Blah" occupies the space that I am trying to remove.

enter image description here

A MWE follows:

\documentclass{article}
\usepackage{enumitem}
\setlength{\parindent}{0pt}

\newcommand{\NewEntry}[2]{
    #1 \\
    #2
}

\begin{document}
    \NewEntry{ENTRY}
    {Blah\begin{itemize}[topsep=0pt]
    \item First Item
    \item Second Item
    \end{itemize}
    }
    \NewEntry{ENTRY}
    {\begin{itemize}[topsep=0pt]
    \item First Item
    \item Second Item
    \end{itemize}
    }
\end{document}

Any help would be greatly appreciated.

3
  • this \NewEntry macro does not seem very well structured but I can see that you are trying to structure your text. If you let us know what it is supposed to represent/typeset maybe we can suggest a better way to package it...
    – Bordaigorl
    Commented Sep 30, 2015 at 14:56
  • For example, if the second argument is always a list of two items you could instead require three arguments for \NewEntry and format the itemize inside it...(just as an example of what I'm talking about)
    – Bordaigorl
    Commented Sep 30, 2015 at 14:57
  • @Bordaigorl Thank you for the suggestions. I have asked a new question, providing more details on the context of the problem, since it looks like the structure of my document needs imrpovement.
    – Tony
    Commented Sep 30, 2015 at 22:53

4 Answers 4

1

enter image description here

\documentclass{article}
\usepackage{enumitem}
\setlength{\parindent}{0pt}

\newcommand{\NewEntry}[2]{%
    #1 \par\noindent
    #2}

\begin{document}
    \NewEntry{ENTRY}{}
    Blah
    \begin{itemize}[topsep=0pt]
    \item First Item
    \item Second Item
    \end{itemize}

    \NewEntry{ENTRY}{}        
    \begin{itemize}[topsep=0pt]
    \item First Item
    \item Second Item
    \end{itemize}

\end{document}

itemize starts in a new line by itself, so adding one more \\ in your macro will lead to a blank line. Replacing this with \par\noindent can solve the problem. Further, you may remember adding an empty pair {} so perhaps you might add another argument later.

5

Remove the faulty \\ after #1 -- it does no good there. Leave an empty blank line to separate the items. In my point of view this however no really convincing way to use itemize etc.

\documentclass{article}
\usepackage{enumitem}
\setlength{\parindent}{0pt}

\newcommand{\NewEntry}[2]{%
    #1% 

    #2%
}

\begin{document}
    \NewEntry{ENTRY}
    {\begin{itemize}[topsep=0pt]
    \item First Item
    \item Second Item
    \end{itemize}
    }
    \NewEntry{ENTRY}{%
      \begin{itemize}[topsep=0pt]
    \item First Item
    \item Second Item
    \end{itemize}
    }
\end{document}

Some suggestions to improve this

\documentclass{article}
\usepackage{xparse}
\usepackage{enumitem}
\setlength{\parindent}{0pt}

\newlist{notopsepitemize}{itemize}{1}
\setlist[notopsepitemize,1]{label={\textbullet},topsep=0pt}


\ExplSyntaxOn
\clist_new:N \l_tonychief_item_clist
\NewDocumentCommand{\NewEntry}{O{}mm}{
\clist_set:Nn \l_tonychief_item_clist {#3}
    #2

    \begin{notopsepitemize}[#1]
    \item 
      \clist_use:Nn \l_tonychief_item_clist {\item} %
    \end{notopsepitemize}
    }
\ExplSyntaxOff

\begin{document}
    \NewEntry{ENTRY}{Item One, Item Two, Item Three, Item Four}%

    \NewEntry[topsep=20pt]{Other ENTRY}{Item One, Item Two, Item Three, Item Four}%
\end{document}

enter image description here

4

If it is to be used with itemize like this, here is an enumitem way using before=Entry

\documentclass{article}
\usepackage{enumitem}
\setlength{\parindent}{0pt}

\begin{document}
    \begin{itemize}[topsep=0pt,before=Entry]
    \item First Item
    \item Second Item
    \end{itemize}
\end{document}

enter image description here

1
  • great to learn about before!
    – Bordaigorl
    Commented Sep 30, 2015 at 14:54
2

I agree with @Christian that a \par is better than \\ and that in general it seems a rather odd way of constructing your \NewEntry command.

However just for reference, you may use a negative space in the argument with the itemize:

\NewEntry{ENTRY}
{\vspace{-\baselineskip}
\begin{itemize}[topsep=0pt]
\item First Item
\item Second Item
\end{itemize}
}

Still, I would not recommend such a construction.

Try instead to see if you could make your command more "semantic".

You must log in to answer this question.

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