1

An example, how decrease vertical space using itemize?

  1. I can insert the code: \addtolength{\itemsep}{-0.5em} at begin each itemize.

  2. I can define and use a new environment as:

    \newenvironment{myItemize}{
       \begin{itemize}
       \addtolength{\itemsep}{-0.5em}
       }{
       \end{itemize}
       }
    

    But how can I call myItemize without replace all itemize?

I want do the same thing for equations inserting \vspace{-0.5em} beginning and ending equation environment.

  • 1
    Welcome to TeX SX! You should take a look at the enumitem package to define customised lists. – Bernard Apr 19 '18 at 23:51
3

There are a number of ways to achieve this. First, by redefining the way itemize works. For this, let's see what the itemize environment looks like (from the LaTeX kernel, latex.ltx):

\def\itemize{%
  \ifnum \@itemdepth >\thr@@\@toodeep\else
    \advance\@itemdepth\@ne
    \edef\@itemitem{labelitem\romannumeral\the\@itemdepth}%
    \expandafter
    \list
      \csname\@itemitem\endcsname
      {\def\makelabel##1{\hss\llap{##1}}}%
  \fi}
\let\enditemize =\endlist

Note that

\begin{itemize}
  <your list of items>
\end{itemize}

is roughly translated to

\begingroup
  \itemize
    <your list of items>
  \enditemize
\endgroup

So, one could just copy the definition of \itemize into your preamble and change it to suit your needs. Here's an example illustrating the changes mid-document:

enter image description here

\documentclass{article}

\begin{document}

\begin{itemize}
  \item First
  \item Second
  \item Third
  \item Last
\end{itemize}

% Redefine \itemize (\def will overwrite the definition)
\makeatletter
\def\itemize{%
  \ifnum \@itemdepth >\thr@@\@toodeep\else
    \advance\@itemdepth\@ne
    \edef\@itemitem{labelitem\romannumeral\the\@itemdepth}%
    \expandafter
    \list
      \csname\@itemitem\endcsname
      {\def\makelabel##1{\hss\llap{##1}}%
       \addtolength{\itemsep}{-0.5em}}% <- Added changes...
  \fi}
\makeatother

\begin{itemize}
  \item First
  \item Second
  \item Third
  \item Last
\end{itemize}

\end{document}

A different approach would be to copy the definition of \itemize into a different macro (say \tempitemize) and then redefine \itemize to call \tempitemize, followed by your insertions:

enter image description here

\documentclass{article}

\begin{document}

\begin{itemize}
  \item First
  \item Second
  \item Third
  \item Last
\end{itemize}

% Copy and redefine \itemize
\let\tempitemize\itemize % Store/copy \itemize in \tempitemize
\def\itemize{%
  \tempitemize % Original definition of \itemize
  \addtolength{\itemsep}{-0.5em}% <- Added changes...
}

\begin{itemize}
  \item First
  \item Second
  \item Third
  \item Last
\end{itemize}

\end{document}

The redefinition is a little simpler, but relies on the fact that your insertions happen after the (complete) execution of \itemize.

Maybe you don't want to fiddle with things at that level. The, perhaps, you can modify \itemize using a search-and-replace feature from etoolbox's \patchcmd.

enter image description here

\documentclass{article}

\usepackage{etoolbox}

\begin{document}

\begin{itemize}
  \item First
  \item Second
  \item Third
  \item Last
\end{itemize}

% Patch \itemize to insert some code
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\itemize} % <cmd>
  {\fi} % <search>
  {\addtolength{\itemsep}{-0.5em}\fi} % <replace>
  {}{} % <success><failure>

\begin{itemize}
  \item First
  \item Second
  \item Third
  \item Last
\end{itemize}

\end{document}

The above patch would be similar to changing the original definition of \itemize to this:

\def\itemize{%
  \ifnum \@itemdepth >\thr@@\@toodeep\else
    \advance\@itemdepth\@ne
    \edef\@itemitem{labelitem\romannumeral\the\@itemdepth}%
    \expandafter
    \list
      \csname\@itemitem\endcsname
      {\def\makelabel##1{\hss\llap{##1}}}%
    \addtolength{\itemsep}{-0.5em}% <- Added changes...
  \fi}

While this is slightly different from the first and the second option, the result is the same. This solution relies on the fact that you know the structure of the command you're patching. That is, \fi has to be within \itemize in order for the patch to work, otherwise nothing happens. Moreover, the first occurrence of \fi is prepended with \addtolength{\itemsep}{-0.5em}, so you'll have issues if there are multiple \fis within \itemize (say).

Finally, you can use an extendable approach with the enumitem package:

enter image description here

\documentclass{article}

\usepackage{enumitem}

\begin{document}

\begin{itemize}
  \item First
  \item Second
  \item Third
  \item Last
\end{itemize}

\setlist[itemize]{before = {\addtolength{\itemsep}{-0.5em}}}

\begin{itemize}
  \item First
  \item Second
  \item Third
  \item Last
\end{itemize}

\end{document}

Of course, you could also specify a new value for \itemsep using the itemsep = <value> key-value approach

\setlist[itemize]{itemsep = <value>}

Note that inserting this before/after equation environments might be done in a better way by adjusting the values of

  • \abovedisplayskip - length above a display equation that is preceded by a short line of text;
  • \abovedisplayshortskip - length above a display equation that is preceded by a long line of text;
  • \belowdisplayskip - similar to \abovedisplayskip but below the display equation; and
  • \belowdisplayshortskip - similar to \abovedisplayshortskip but below the display equation.

For more on this, see

  • Perfect! But and about equation environment? Should I open latex.ltx and redefine the piece of code in tex file or there is a package like enumitem? – Bismarck Gomes Apr 20 '18 at 16:36
  • 1
    @BismarckGomes -- it is never a good idea to change an established package directly, and even worse to change a core component such as latex.ltx'. if you want something you can use more than once, you can create your own little .sty` file with the replacement code, and then call it with \usepackage. – barbara beeton Apr 20 '18 at 16:41

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.