1

When using Section headers in margins to put paragraph headings in the margin, when the paragraph starts with an itemize or enumerate, an extra space appears at the top of the paragraph, which is not the case if it starts with a normal text.

How do I prevent this?

Example code:

\documentclass{report}
\usepackage[a4paper]{geometry}
\usepackage[compact]{titlesec}
\usepackage{lipsum}

\titleformat{\paragraph}[leftmargin] {\normalfont \bfseries\filleft} {}{0pt}{} \titlespacing{\paragraph} {4pc}{1.5ex plus .1ex minus .2ex}{1pc}

\begin{document} \section{Section} \paragraph{first paragraph with title} \begin{itemize} \item item one \item item two \item item three \end{itemize} \lipsum[1]

\paragraph{second paragraph with title} \lipsum[1]

\end{document}

Which outputs: Output screenshot

noxewa
  • 65

1 Answers1

1

The space you're seeing is just the (blank) first line of the paragraph, before the list begins. To remove it, you can use enumitem to add negative spacing.

\documentclass{report}
\usepackage[a4paper]{geometry}
\usepackage[compact]{titlesec}
\usepackage{enumitem}
\usepackage{lipsum}

\newlist{startitemize}{itemize}{1} \newlist{startenumerate}{enumerate}{1} \setlist[startitemize]{ label=\textbullet, before=\leavevmode\vspace{-\baselineskip}\vspace{-\topsep}, } \setlist[startenumerate]{ label=\arabic., before=\leavevmode\vspace{-\baselineskip}\vspace*{-\topsep}, }

\titleformat{\paragraph}[leftmargin] {\normalfont \bfseries\filleft} {}{0pt}{} \titlespacing{\paragraph} {4pc}{1.5ex plus .1ex minus .2ex}{1pc}

\begin{document} \section{Section} \paragraph{first paragraph with title} \begin{startitemize} \item item one \item item two \item item three \end{startitemize} \lipsum[1]

\paragraph{second paragraph with title} \lipsum[1]

\end{document}

Vincent
  • 20,157
  • Is there any way to make this happen automatically, so that if the paragraph begins with an itemize/enumerate, the so-called blank line gets deleted? After all, I have not entered any blank line between the heading and the itemize. – noxewa May 03 '23 at 17:54
  • @noxewa I don't know if it's possible to have LaTeX detect everything automatically, but you can certainly make the process half automatic by defining new list environments with enumitem to remove the space. I updated my example with such environments. – Vincent May 03 '23 at 18:13
  • Thanks, that's quite good enough! – noxewa May 03 '23 at 18:16