![\lstlistoflistings 删除 \documentclass{article} 中的缩进](https://linux22.com/image/380808/%5Clstlistoflistings%20%E5%88%A0%E9%99%A4%20%5Cdocumentclass%7Barticle%7D%20%E4%B8%AD%E7%9A%84%E7%BC%A9%E8%BF%9B.png)
在我的\documentclass[12pt,a4paper,oneside]{文章}我想删除\lstlistoflistings。可以像下面这样删除 LOF 和 LOT 的缩进。是否有类似方法可以删除 Listings 的缩进?如果问题需要 MWE,我很乐意这么做。
\setlength{\cftfigindent}{0pt} % remove indentation from figures in lof
\listoffigures
\addcontentsline{toc}{section}{List of Figures}
\lstlistoflistings
\addcontentsline{toc}{section}{Code Listings}
\setlength{\cfttabindent}{0pt} % remove indentation from tables in lot
\listoftables
\addcontentsline{toc}{section}{List of Tables}
答案1
将以下几行添加到序言末尾。
\usepackage{xpatch}
\makeatletter
\xpatchcmd\l@lstlisting{1.5em}{0em}{}{}
\makeatother
这是一个例子。
\documentclass{article}
\usepackage{tocloft}
\usepackage{listings}
\usepackage{xpatch}
\makeatletter
\xpatchcmd\l@lstlisting{1.5em}{0em}{}{}
\makeatother
\begin{document}
\setlength{\cftfigindent}{0pt} % remove indentation from figures in lof
\listoffigures
\addcontentsline{toc}{section}{List of Figures}
\lstlistoflistings
\addcontentsline{toc}{section}{Code Listings}
\setlength{\cfttabindent}{0pt} % remove indentation from tables in lot
\listoftables
\addcontentsline{toc}{section}{List of Tables}
\begin{lstlisting}[caption={A listing}]
(Listing content)
\end{lstlisting}
\begin{table}
\caption{Some table}
\end{table}
\begin{figure}
\caption{Some figure}
\end{figure}
\end{document}