0

My situation

I have an environment that consists of an itemize set withing a minipage (or varwidth, whatever...)

Let's call this environment myItemize.

I am encountering difficulty regarding the vertical spacing after and \end{myItemize}

(I do not care about the vertical spacing before the \begin{)

All code is at the end.

regular spacing after myItemize : ok-ish

By fiddling in myItemize definition, I can just about have it behave when followed by "regular text".

Illustration :

enter image description here

spacing before \item after myItemize : not ok

If the myItemize is nested inside an itemize, the ad-hoc spacing is no longer relevant.

Can someone show me the magic to be cast to have the same spacing after myItemize as would be after a itemize in both cases ?

I tried a bit with \ignorespacesafterend but no luck !

Illustration :

enter image description here

The code

\documentclass[12pt]{article}
\begin{document}

\newenvironment{myItemize}
{%
  \noindent
  \begin{minipage}{\linewidth}
    \begin{itemize}
}
{%
    \end{itemize}
    \strut
  \end{minipage}
  \vspace{-2.3\baselineskip}
  \vspace{-\lineskip}

  \strut
}
\newcommand\myCommand[2]
{
\begin{minipage}{.5\linewidth}
  \begin{#1}
    \item this is #2
    \item spacing below is about \textsc{ok}
  \end{#1}

  dummy below

  \hrulefill
\end{minipage}
}

\myCommand{myItemize}{{\verb!myItemize}}%
\myCommand{itemize}{{\verb!itemize}}

\begin{itemize}
  \item dummy item
    \begin{itemize}
      \item this is \verb!itemize!
      \item spacing is \textsc{ok}
    \end{itemize}
  \item dummy item

    \begin{myItemize}
      \item this is \verb!myItemize!
      \item spacing below is not \textsc{ok}
      \item I don't care about above spacing
    \end{myItemize}

  \item dummy item
\end{itemize}


\end{document}

Cheers,

6
  • Just an idea: Do not use itemize in your minipage directly, but use an own list defined by enumitem and adjust skips via its setup options.
    – TeXnician
    Jun 24 '17 at 20:07
  • @TeXnician In my documents, I actually do use enumitem, but took this off for minimalism. What kind of list do you mean ? A regular list environment ? I don't think I know much about these, of have much documentation at my disposal, either...
    – marsupilam
    Jun 24 '17 at 20:10
  • Have a look at the enumitem documentation p. 10 (about \newlist). If you have such a new list you can configure it the enumitem way (including settings per nesting level).
    – TeXnician
    Jun 24 '17 at 20:13
  • The minipage environment changes explicitly the inter-item spacings. I've answered this some while ago... tex.stackexchange.com/a/257836/31729
    – user31729
    Jun 24 '17 at 20:25
  • @ChristianHupfer This is not about the spacing between items, it is about the spacing after the environment.
    – marsupilam
    Jun 24 '17 at 20:30
2

First, there is the use of \begin inside an environment. Your original code would have expanded as:

\begin{MyItemize}
\begin{minipage}
\begin{itemize}
\end{MyItemize}
\end(itemize}
\end{minipage}

which is out of order. (\end tests \@currenvir against #1)

Second, \item adds \itemsep, except when in vmode. So part of the problem is how to avoid being in vmode without adding an extra line. In any case, the solution was to add a \strut to the last \item rather than to the end of itemize.

Third, itemize ends with a skip but minipage doesn't. The only way I could find to fix the \myCommand alignment without adding a line was to use \unskip in \myCommand, then put the skip back in. (Actually, the skip removed was 13.0pt plus 6.0pt minus 8.0pt whereas \baselineskip=14.5pt. I haven't managed to identify the name of the skip used by itemize.)

\documentclass[12pt]{article}

\newenvironment{myItemize}
{%
  \noindent
  \minipage{\linewidth}\null
    \itemize
}
{%
    \strut\enditemize
  \endminipage
}

\newcommand\myCommand[2]
{
\begin{minipage}[t]{.5\linewidth}\null
  \begin{#1}
    \item this is #2
    \item spacing below is about \textsc{ok}
  \end{#1}\unskip\par\vskip\baselineskip

  dummy below \the\parskip

  \hrulefill
\end{minipage}
}
\begin{document}
\myCommand{myItemize}{myItemize}%
\myCommand{itemize}{itemize}

\begin{itemize}
  \item dummy item
    \begin{itemize}
      \item this is \verb!itemize!
      \item spacing is \textsc{ok}
    \end{itemize}
  \item dummy item \smash{\rule{1pt}{\dimexpr\baselineskip+\itemsep}}

    \begin{myItemize}
      \item this is \verb!myItemize!
      \item spacing below is not \textsc{ok}
      \item I don't care about above spacing
    \end{myItemize}

  \item dummy item \smash{\rule{1pt}{\dimexpr\baselineskip+\itemsep}}
\end{itemize}

\end{document}

demo

3
  • Thank you for the help. I hadn't understood the point you raise on environments in \newenvironment. Unfortunately, your answer solves only one half of the issue. Please see my answer for clarification.
    – marsupilam
    Jun 25 '17 at 8:39
  • Sorry about that. I was getting errors from the \myCommand code so simply deleted them. Jun 25 '17 at 16:18
  • I think the skip you could not identify is \dimexpr\topsep+\partopsep. Thanks for the good work, I learnt good stuff.
    – marsupilam
    Jun 25 '17 at 17:13
0

Maybe I explained myself poorly in the question.

John's solution is ok if the environment is followed by an \item, but not for regular text, but I would like the "after" vspace to be correct regardless.

I build from this solution by David Carlisle, to get rid conditionally of the extra \baselineskip introduced by \item.

The output

enter image description here

The code

\documentclass[12pt,border=5pt]{standalone}

\makeatletter
\def\detectItem{%
  \@ifnextchar\item%
    {\par\kern-\baselineskip}%
    {}%
}
\makeatother

\def\useDetectItem#1\ignorespaces\fi{#1\fi\detectItem}

\newenvironment{myItemize}
{%
  \noindent
  \minipage{\linewidth}
    \itemize
}
{%
    \strut%\smash{\rule[\dimexpr-\baselineskip-\itemsep]{1pt}{1cm}}
    \enditemize
  \endminipage%
  \par\kern\dimexpr\baselineskip-.7\lineskip\relax
  \aftergroup\useDetectItem}

\newcommand\myCommand[2]
{%
\begin{minipage}{.5\linewidth}
  \begin{#1}
    \item this is {\verb!#2}
    \item spacing below is \textsc{ok}
  \end{#1}
  dummy below

  \hrulefill
\end{minipage}%
}
\begin{document}

\begin{minipage}{390pt}
\myCommand{myItemize}{myItemize}%
\myCommand{itemize}{itemize}


\begin{itemize}
  \item dummy item
    \begin{itemize}
      \item this is \verb!itemize!
      \item spacing is \textsc{ok}
    \end{itemize}
  \item dummy item \smash{\rule{1pt}{\dimexpr\baselineskip+\itemsep}}

    \begin{myItemize}
      \item this is \verb!myItemize!
      \item spacing below is now \textsc{ok}
      \item I don't care about above spacing
    \end{myItemize}
  \item dummy item \smash{\rule{1pt}{\dimexpr\baselineskip+\itemsep}}
\end{itemize}
\end{minipage}

\end{document}

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.