
我想使用 將節標題放在左邊距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
直接 before可能造成的問題\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}