列表頁碼的自訂清單不起作用

列表頁碼的自訂清單不起作用

所以我已經使用這個特定的乳膠模板有一段時間了,並且我不斷添加和更改它以達到我想要的效果。最近,我嘗試重新格式化以刪除 TOC、LOF、LOT 和 LOL 中的前導點,並且我設法透過更新命令來刪除所有這些點,\cftdot但這似乎對 LOL 不起作用。

我使用套件\titlecontents中的命令titletoc來更改 LOL 的設置,但這會使頁碼與列表的其餘部分不一致。之前我已經嘗試過\hfill解決這個問題,但都沒有成功。\titlerule*[0.0em]{.}\contentspage

目前的工作範例正在使用 進行演示\hfill

\documentclass[12pt]{article}

\usepackage{geometry}
\geometry{letterpaper}
\geometry{margin = 1.0in}
 \usepackage[parfill]{parskip}
\usepackage{setspace}
\singlespacing

\usepackage[utf8x]{inputenc}
\usepackage{microtype}
\usepackage{listings}
\usepackage{graphicx}
\usepackage[justification = centering]{caption}
\usepackage[section]{placeins}
\usepackage{float}

\usepackage[nottoc,notlof,notlot]{tocbibind}
\usepackage[titles]{tocloft}
\usepackage{titletoc}
\renewcommand{\cftsecfont}{\rmfamily\mdseries\upshape}
\renewcommand{\cftsecpagefont}{\rmfamily\mdseries\upshape}
\renewcommand{\cftdot}{}
\renewcommand\lstlistlistingname{List of Scripts}
\renewcommand\lstlistingname{Script}
\contentsuse{lstlisting}{lol}
\titlecontents{lstlisting}[1.5em]
        {\hspace{2.3em}}
        {\contentslabel{2.3em}}
        {\hspace*{-2.3em}}
        {\hfill\contentspage}

\usepackage{hyperref}
\pdfoutput=1 
\hypersetup{
    unicode=false,
    pdftoolbar=true,
    pdfmenubar=true,
    pdffitwindow=true,
    pdfstartview={FitH},
    pdftitle={Title},
    pdfauthor={Author},
    pdfsubject={Subject},
    pdfcreator={Producer},
    pdfproducer={Producer},
    pdfdisplaydoctitle=true,
    pdfnewwindow=true,
    colorlinks=true,
    linkcolor=black,
    citecolor=black,
    filecolor=black,
    urlcolor=black
}

\begin{document}

\tableofcontents
\listoffigures
\listoftables
\lstlistoflistings


\section{Here is A Section}

\begin{figure}[H]
\centering
\includegraphics[width = 2cm]{boats}
\caption{A boat}
\end{figure}

\begin{table} [H]
\begin{center}
\begin{tabular}{ c | c }
Title 1 & Title 2 \\ \hline 
Stuff & More stuff 
\end{tabular}
\caption{A Table}
\end{center}
\end{table}

\begin{lstlisting}[language = Matlab, basicstyle = \scriptsize, numberstyle = \scriptsize, caption = A Listing]
%%
clear;clc;close all;format compact;
%%
x = 5;
y = 6;
x + y = z;
disp(z);
\end{lstlisting}

\end{document}

從下面的範例中可以看出,清單的頁碼由於某種我無法弄清楚的原因而縮排。我確信這很容易,但我只是還沒找到。
LaTeX 輸出範例

請注意,我使用的軟體包和修改比這多得多,但這些是最基本的,它仍然可以正確編譯。

答案1

tocloft僅掛鉤到標準ToCLoF命令LoT和文件以及使用\newlistof.

所有這些都沒有被覆蓋,它使用類似巨集LoL的傳統設定。\l@...

listings.sty我們發現

\def\l@lstlisting#1#2{\@dottedtocline{1}{1.5em}{2.3em}{#1}{#2}}

這是內容清單中行設定的相關巨集。再深入一層,我們發現\@dottedtocline它是一個 LaTeX 內核宏,用作\@dotsep兩個內容行點之間的分隔空間。預設值為4.5。透過將此數字增加到 5000(這確實很大),這些點很可能會在此處看不見。

我不想\@dotsep全域更改,所以我修補了該命令(使用群組來刪除使用\l@lstlisting後的設定)\l@lstlisting

\makeatletter % Patching to prevent interference
\xpatchcmd{\l@lstlisting}{\@dottedtocline{1}{1.5em}{2.3em}{#1}{#2}}{%
  \begingroup\renewcommand{\@dotsep}{5000}\@dottedtocline{1}{1.5em}{2.3em}{#1}{#2}\endgroup}{%
}{}
\makeatother

這是程式碼(titletoc相關內容已註解掉)

\documentclass[12pt]{article}

\usepackage{geometry}
\geometry{letterpaper}
\geometry{margin = 1.0in}
 \usepackage[parfill]{parskip}
\usepackage{setspace}
\singlespacing

\usepackage[utf8x]{inputenc}
\usepackage{microtype}
\usepackage[demo]{graphicx}
\usepackage[justification = centering]{caption}
\usepackage[section]{placeins}
\usepackage{float}

\usepackage[nottoc,notlof,notlot]{tocbibind}
\usepackage{listings}
\usepackage[titles]{tocloft}
\usepackage{xpatch}
%\usepackage{titletoc}
\renewcommand{\cftsecfont}{\rmfamily\mdseries\upshape}
\renewcommand{\cftsecpagefont}{\rmfamily\mdseries\upshape}
\renewcommand{\cftdotsep}{\cftnodots}

\renewcommand\lstlistlistingname{List of Scripts}
\renewcommand\lstlistingname{Script}


\makeatletter % Patching to prevent interference
\xpatchcmd{\l@lstlisting}{\@dottedtocline{1}{1.5em}{2.3em}{#1}{#2}}{%
  \begingroup\renewcommand{\@dotsep}{5000}\@dottedtocline{1}{1.5em}{2.3em}{#1}{#2}\endgroup}{%
}{}
\makeatother
%\contentsuse{lstlisting}{lol}
%\titlecontents{lstlisting}[1.5em]
%        {\hspace{2.3em}}
%        {\contentslabel{2.3em}}
%        {\hspace*{-2.3em}}
%        {\hfill\contentspage}

\usepackage{hyperref}
\pdfoutput=1 
\hypersetup{
    unicode=false,
    pdftoolbar=true,
    pdfmenubar=true,
    pdffitwindow=true,
    pdfstartview={FitH},
    pdftitle={Title},
    pdfauthor={Author},
    pdfsubject={Subject},
    pdfcreator={Producer},
    pdfproducer={Producer},
    pdfdisplaydoctitle=true,
    pdfnewwindow=true,
    colorlinks=true,
    linkcolor=black,
    citecolor=black,
    filecolor=black,
    urlcolor=black
}

\begin{document}

\tableofcontents
\listoffigures
\listoftables
\lstlistoflistings


\section{Here is A Section}

\begin{figure}[H]
\centering
\includegraphics[width = 2cm]{boats}
\caption{A boat}
\end{figure}

\begin{table} [H]
\begin{center}
\begin{tabular}{ c | c }
Title 1 & Title 2 \\ \hline 
Stuff & More stuff 
\end{tabular}
\caption{A Table}
\end{center}
\end{table}

\begin{lstlisting}[language = Matlab, basicstyle = \scriptsize, numberstyle = \scriptsize, caption = A Listing]
%%
clear;clc;close all;format compact;
%%
x = 5;
y = 6;
x + y = z;
disp(z);
\end{lstlisting}

\end{document}

在此輸入影像描述

相關內容