5

I want to put the section title in the left margin using titlesec. However, it results to a superfluous empty line when using list environment. How should I remove it without using vspace?

Minimal example:

\documentclass{article}

\usepackage{geometry}
\geometry{
  a4paper,
  top=2cm,
  bottom=2cm,
  left=4.5cm,
  right=1.5cm,
}

\usepackage{titlesec}
\titleformat{\section}[leftmargin]{\large\scshape\sffamily}{}{0cm}{}
\titlespacing{\section}{2.5cm}{2ex}{0.5cm}

\usepackage{enumitem}

\usepackage{mwe}

\begin{document}

\section{Section A}

This line is aligned with the section title.

\blindtext

\section{Section B}

\begin{itemize}[nosep]
  \item This line is not aligned with the section title.
\end{itemize}

\end{document}

result

5
  • The space comes most likely from the itemize environment. You could have a look at the enumitem package which controles the shape of this kind of environment: ctan.org/pkg/enumitem?lang=de
    – AndiW
    Feb 27, 2019 at 8:07
  • Sorry, overseen it's already in... Early morning...
    – AndiW
    Feb 27, 2019 at 8:08
  • Did you try [nosep,topsep=0pt] or some other value?
    – AndiW
    Feb 27, 2019 at 8:15
  • @AndiW, [nosep,topsep=0pt] does not work. Neither does any other enumitem option I have tested.
    – xucheng
    Feb 27, 2019 at 8:25
  • the problem is that environments change the mode LaTeX is in - vertical or horizontal. The most easy "workaround" - but no real solution - is to add text before the itemize environment if you can. If you can't there still is \vspace which is not good practice. Since I have no running LaTeX at the moment I can't really test... Searching itemize leavevmode on text.SE looks promising to me - you should find similar questions
    – AndiW
    Feb 27, 2019 at 8:34

2 Answers 2

3

You can change the beginning of itemize like this:

\begin{itemize}[nosep,before=\leavevmode\vspace*{-1\baselineskip}] 

I added option showframe and a little bit text to get rid of possible problems caused by \blindtext direct before \begin{itemize}.

Please see the following MWE

\documentclass{article}

\usepackage{geometry}
\geometry{%
  a4paper,
  top=2cm,
  bottom=2cm,
  left=4.5cm,
  right=1.5cm,
  showframe % <=========================================================
}

\usepackage{titlesec}
\titleformat{\section}[leftmargin]{\large\scshape\sffamily}{}{0cm}{}
\titlespacing{\section}{2.5cm}{2ex}{0.5cm} 

\usepackage{enumitem}
\usepackage{blindtext}


\begin{document}

\section{Section A}

This line is aligned with the section title.

\blindtext

Some text to get rid of blindtext.

\section{Section B}
%This is some text. 

\begin{itemize}[nosep,before=\leavevmode\vspace*{-1\baselineskip}] % [nosep]
  \item This line is not aligned with the section title.
  \item second item. second item. second item. second item. second item. 
     second item. second item. second item. second item. second item. second item. 
\end{itemize}

\end{document}

and the result:

enter image description here

2

Here is a solution with enumitem:

\documentclass{article}

\usepackage{geometry}
\geometry{
  a4paper,
  vmargin=2cm,
  left=4.5cm,
  right=1.5cm,
}

\usepackage{titlesec}
\titleformat{\section}[leftmargin]{\large\scshape\sffamily}{}{0cm}{}
\titlespacing{\section}{2.5cm}{2ex}{0.5cm}

\usepackage{enumitem}

\usepackage{mwe}

\begin{document}

\section{Section A}

This line is aligned with the section title.

\blindtext

\section{Section B}

\begin{itemize}[topsep=0pt, before =\leavevmode\vspace*{-\baselineskip}]
  \item This line is aligned with the section title.
\end{itemize}

\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .