0

I'm using titlesec to put section titles on the margin. I'd like to start one section with a list but the first item in the list is not aligned with the section title. See the MWE below.

Adding something like \vspace{-7mm} after \begin{itemize} works, but it's a kludge at best, made worse by the magical number -7mm, which was chosen visually.

Is there a better solution?

\documentclass{article}
\usepackage{titlesec}

\titleformat{\section}[leftmargin]{\filleft}{\thesection}{.5em}{}
\titlespacing{\section}{4pc}{1.5ex plus .1ex minus .2ex}{1pc}

\def\LOREM{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.}

\begin{document}

\section*{first section}
\LOREM\LOREM

\section*{second section}
\begin{itemize}
\item 
\LOREM\LOREM
\end{itemize}

\end{document}

enter image description here

1

enter image description here

The space above a first level list is \topsep so if you add \mbox{} to make a hidden line to hold the section heading you can back up by that amount.

\documentclass{article}
\usepackage{titlesec}

\titleformat{\section}[leftmargin]{\filleft}{\thesection}{.5em}{}
\titlespacing{\section}{4pc}{1.5ex plus .1ex minus .2ex}{1pc}

\def\LOREM{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.}

\begin{document}

\section*{first section}
\LOREM\LOREM

\section*{second section}
\mbox{}\vspace{-\dimexpr\topsep+\baselineskip\relax}
\begin{itemize}
\item 
\LOREM\LOREM
\end{itemize}

\end{document}

Of course the document markup would look better if you defined some command rather than having this inline.

  • Thanks for telling me how to avoid magic numbers in \vspace! But is using \vspace the only solution? – lhf Nov 12 '17 at 14:00
  • @lhf it depends how you define "only solution" it would be possible to patch the definition of \begin{itemize} to detect that it is immediately after a marginal section head and so add the fix I suggest above without needing to add it to the document. That may or may not be better depending on how often you need to do it and the likelihood of such patches breaking some other use somewhere or some other package that is redefining lists. – David Carlisle Nov 12 '17 at 14:07

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.