Change \parskip only inside enumerate & itemize environment

前端 未结 4 1251
一个人的身影
一个人的身影 2021-02-15 12:08

Is there any way that I can change \\parskip to a different value inside certain environments, namely enumerate and itemize.

I wan

相关标签:
4条回答
  • 2021-02-15 12:46

    Yes you can; but you will have to alter either the enumerate and itemize environments from your class file (by copying them and adding your \parskip), or by redefining \@listi, which works for all lists:

    \makeatletter
    
    \def\@listi{%
      % default settings for base LaTeX classes at 10pt:
      \parsep 4pt plus 2pt minus 1pt
      \topsep 8pt plus 2pt minus 4pt
      \itemsep 4pt plus 2pt minus 1pt
      % your settings:
      \parskip 1em plus 1pt minus 1pt
    }
    
    \makeatother
    

    If you want different settings at nested list levels, change \@listii, \@listiii etc.

    0 讨论(0)
  • 2021-02-15 12:50

    you can also use:

    begin{itemize} \itemsep -5pt
    \item foo
    \item bar
    \end{itemize}
    

    and that will only affect the current list.

    0 讨论(0)
  • 2021-02-15 12:51

    If you use the enumitem package, you can say in your preamble

    \setlist[itemize]{parsep=0pt}
    \setlist[enumerate]{parsep=0pt}
    

    to get what you want. enumitem allows for doing much more list customization, see its documentation for details.

    0 讨论(0)
  • The following addition to the preamble updates enumerate to make the suggested change:

    \let\oldenumerate\enumerate% Keep a copy of \enumerate (or \begin{enumerate})
    \let\endoldenumerate\endenumerate% Keep a copy of \endenumerate (or \end{enumerate})
    \renewenvironment{enumerate}
      {\begin{oldenumerate}
         \setlength{\parskip}{0pt}}% Adjust \parskip to suit your needs
      {\end{oldenumerate}}
    

    Here is a complete minimal example showing the adjustment when setting \parskip to 0pt:

    enter image description here

    \documentclass{article}
    \begin{document}
    
    \begin{enumerate}
      \item First line
    
        Second line
    \end{enumerate}
    
    \let\oldenumerate\enumerate
    \let\endoldenumerate\endenumerate
    \renewenvironment{enumerate}
      {\begin{oldenumerate}
         \setlength{\parskip}{0pt}}
      {\end{oldenumerate}}
    
    \begin{enumerate}
      \item First line
    
        Second line
    \end{enumerate}
    
    \end{document}
    

    One would do exactly the same for itemize.

    0 讨论(0)
提交回复
热议问题