![titletoc:\addvspace 不起作用](https://linux22.com/image/474715/titletoc%3A%5Caddvspace%20%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8.png)
假设以下简单的代码:
\documentclass{article}
\usepackage{titletoc}
\titlecontents{section}
[2em]
{\addvspace{\baselineskip}}
{}
{}
{}
[\addvspace{\baselineskip}] % <----
\begin{document}
\tableofcontents
\section{A}
\section{B}
\end{document}
使用 时\addvspace
,我期望两个连续的s 只会在目录中的两个条目之间\section
增加一个垂直空间。然而,事实并非如此,通过注释掉标记的行可以看到:垂直空间不应该改变,但它减少了一半。\baselineskip
我该如何解决这个问题?这是一个错误吗?
编辑:也许这是相关的:titlesec 标题后 \addvspace。
答案1
我提议埃托克和枚举项。埃托克\etocnumber
通过、\etocname
或等命令提供目录内容\etocpage
。枚举项topsep
允许通过设置列表前( )和项目之间的空格( \itemsep
)来自定义列表。
\documentclass{article}
\usepackage{etoc}
\usepackage{enumitem}
\etocsetstyle{section}
{% before
\begin{itemize}
[label={}, topsep=\baselineskip, itemsep=\baselineskip, itemindent=2em]
}
{% label
\bfseries\item%
}
{% page
\etocifnumbered{\makebox[2.25ex][r]{\etocnumber.~}}{}\etocname{}%
~\dotfill\makebox[0pt][l]{\makebox[5.5ex][r]{~\etoclink{p.\hfill\etocpage}}}%
}
{% after
\end{itemize}
}
\etocsetstyle{subsection}
{% before
\begin{itemize}
[label={}, topsep=\baselineskip, itemsep=0.5\baselineskip, itemindent=2em]
}
{% label
\itshape{}\item%
}
{% page
\etocifnumbered{\makebox[2.25ex][r]{\etocnumber.~}}{}\etocname{}%
~\dotfill\makebox[0pt][l]{\makebox[5.5ex][r]{~\etoclink{p.\hfill\etocpage}}}%
}
{% after
\end{itemize}
}
\begin{document}
\tableofcontents
\begin{itemize}
\item \verb|\baselineskip| between two \verb|\sections|,
\item \verb|\baselineskip| between \verb|\section| and \verb|\subsection|,
\item \verb|.5\baselineskip| between two \verb|\subsections|.
\end{itemize}
\section{Section A}
\section{Section B}
\subsection{B1}
\subsection{B2}
\subsection{B3}
\section{Section C}
\section{Section D}
\section{Section E}
\end{document}