如何删除列表环境前的多余的空行?

如何删除列表环境前的多余的空行?

我想使用 将章节标题放在左边距titlesec。但是,使用环境时会导致多余的空行list。我应该如何在不使用的情况下将其删除vspace

最小示例:

\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}

结果

答案1

itemize您可以像这样更改开头:

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

我添加了选项showframe和一些文本来消除\blindtext之前直接引起的可能问题\begin{itemize}

请参阅以下 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}

结果:

在此处输入图片描述

答案2

这是一个解决方案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} 

在此处输入图片描述

相关内容