\tableofcontents 错误-页码错误-章节编号错误

\tableofcontents 错误-页码错误-章节编号错误

我必须使用大学指定的 documentclass。它有三个错误。首先\tableofcontents

! missing numbers, treated as zero.

第二:页码是罗马数字(i、ii、...),而不是数字。最后一点,所有不同章节的编号都从 1 开始。

\documentclass[12pt,oneside,letterpaper,chapterprefix=on,numbers=noenddot]{scrbook}
%%%page set-up
\setcounter{secnumdepth}{4}
\usepackage[margin=1in,includefoot,heightrounded]{geometry}%1 inch margins
\usepackage{mathptmx} %times new roman
\usepackage{setspace}%double spacing in text, not captions or footnotes
\usepackage{indentfirst} %indent first paragraph 
\setlength{\parindent}{2em} %adjust indentation
\usepackage[document]{ragged2e} %ragged right
\setlength{\RaggedRightParindent}{\parindent}
\usepackage{comment}% a convenient package
\pagestyle{plain}%remove headers
\usepackage[justification=raggedright,singlelinecheck=false,labelsep=period]{caption}
%captions left justify
\setkomafont{captionlabel}{\bfseries}%make caption label bold
\setkomafont{caption}{\bfseries}%make caption bold
\setcapindent{0pt}%removes hanging indent from captions
\usepackage{caption}
\captionsetup{figurename=FIGURE,tablename=TABLE}


%%% bibliography modifications
\usepackage[square,sort,comma,numbers]{natbib}
\setlength{\bibsep}{\baselineskip}%line spacing between citations
\setlength{\bibhang}{2em}%%%hanging identation
\makeatletter
\renewcommand\NAT@bibsetnum[1]{\settowidth\labelwidth{\@biblabel{#1}}%
   \setlength{\leftmargin}{\bibindent}\addtolength{\leftmargin}%
{\dimexpr\labelwidth+\labelsep\relax}%
 \setlength{\itemindent}{-\bibindent}%
 \setlength{\listparindent}{\itemindent}

   \setlength{\itemsep}{\bibsep}\setlength{\parsep}{\z@}%
   \ifNAT@openbib
     \addtolength{\leftmargin}{\bibindent}%
     \setlength{\itemindent}{-\bibindent}%
     \setlength{\listparindent}{\itemindent}%
     \setlength{\parsep}{0pt}%
   \fi
}
\makeatother

%%% extra code for getting the correct line spacing after references title
\let\oldbibliography\bibliography %store \bibliography in \oldbibliography
\renewcommand{\bibliography}[1]{{ %
 \let\chapter\section %copy\ section over\ chapter
 \oldbibliography{#1}}} %old\ bibliography

%%% uppercase chapters
\makeatletter
%\renewcommand\sectionlinesformat[4]{%
% \@hangfrom{\hskip#2 #3}{\MakeUppercase{#4}}%
%}
\renewcommand\chapterlinesformat[3]{%
 \@hangfrom{#2}{\MakeUppercase{#3}}%
}
\makeatother
\renewcommand\chapterlineswithprefixformat[3]{%
 \MakeUppercase{#2#3}%
}
%%% continuous table and figure numbering
\usepackage{chngcntr}
\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}

%%% chapter titles
\let\raggedchapter\centering
\RedeclareSectionCommand[
  beforeskip=0pt,
  afterskip=0pt]{chapter}
\setkomafont{disposition}{\bfseries\normalsize}
\setkomafont{chapter}{\normalsize}

%%% section titles
\let\raggedsection\centering
\setkomafont{section}{\normalsize}
\RedeclareSectionCommand[
  beforeskip=0pt,
  afterskip=0.01pt]{section}
%%% subsection title
\let\raggedsubsection\centering
\setkomafont{subsection}{\normalsize}
\RedeclareSectionCommand[
  beforeskip=0pt,
  afterskip=0.01pt]{subsection}
%%% subsubsection titles
\let\raggedsubsubsection\centering
\setkomafont{subsubsection}{\normalsize}
\RedeclareSectionCommand[
  beforeskip=0pt,
  afterskip=0pt]{subsubsection}
%%% remove identation from captions
\usepackage{etoolbox}
\AtBeginEnvironment{figure}{\setlength{\RaggedRightParindent}{0em}}
\AtBeginEnvironment{table}{\setlength{\RaggedRightParindent}{0em}}
\patchcmd{\thebibliography}{\chapter*}{}{}


%%%modify table of contents 
\usepackage{tocloft}
\renewcommand{\cftchapaftersnum}{.} %place a period after chapter numbers
\setlength{\cftbeforetoctitleskip}{0pt} %keep at 1 inch margin
\setlength{\cftaftertoctitleskip}{0pt} % keep the double spacing
\renewcommand*\contentsname{TABLE OF CONTENTS} % rename contents
\renewcommand{\cfttoctitlefont}{\hspace*\fill}{\normalsize\bfseries}%keep consistent font size
\renewcommand{\cftaftertoctitle}{\hspace*{fill}} %center title
\KOMAoptions{toc=chapterentrydotfill} %dotted chapter entries
\setkomafont{chapterentry}{} %make chapter titles not bold
\addtokomafont{chapterentrypagenumber}{\mdseries} %make page numbers not bold
%%% indents numbered chapters
\RedeclareSectionCommand[tocnumwidth=3.5em]{chapter}
\renewcommand\addchaptertocentry[2]{%
  \ifstr{#1}{}{%
    \addtocentrydefault{chapter}{#1}{#2}%
  }{%
    \addtocentrydefault{chapter}{\hspace*{2em}#1}{#2}%
}}

%%% list of tables
\setlength{\cftbeforelottitleskip}{0pt} % keep at 1 inch margin
\setlength{\cftafterlottitleskip}{0pt} %keep the double spacing
\renewcommand*\listtablename{LIST OF TABLES} %rename contents
\renewcommand{\cftlottitlefont}{\hspace*{\fill}\normalsize\bfseries} %keep consistent font size
\renewcommand{\cftafterlottitle}{\hspace*{\fill}}%center title
\setlength{\cfttabindent}{0pt} % remove indentation from tables in lot 

%%% list of figures
\setlength{\cftbeforeloftitleskip}{0pt} % keep at 1 inch margin
\setlength{\cftafterloftitleskip}{0pt} %keep the double spacing
\renewcommand*\listfigurename{LIST OF FIGURES} % rename contents
\renewcommand{\cftloftitlefont}{\hspace*{\fill}\normalize\bfseries}% keep consistent font size
\renewcommand{\cftafterloftitle}{\hspace*{\fill}} %center title
\setlength{\cftfigindent}{0pt} % remove identation from figures in 1of


%%% set up appendix
%\ usepackage[page,toc,title]{appendix}
%\renewcommand{\appendixtocname}{APPENDICES}
\usepackage[toc,title]{appendix}
\renewcommand{\appendixtocname}{APPENDIX: EXAMPLE OF AN APPENDIX}
\renewcommand{\appendixpagename}{\vspace*{\fill}\centering\normalsize
APPENDICES\vspace*{\fill}}



%%% Figure packages
\usepackage{graphicx}
\graphicspath{{figures/}}
\usepackage{wrapfig}
\usepackage{pdfpages}
\usepackage{subcaption} % allows side by side figures

\usepackage{amsmath}
\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=black,
    linkcolor=black,
    urlcolor=black}
%%%---------------------------------------------------------------------

%%%-----------------------------------------------------------

%%%------------------------------------------------------------
\begin{document}
\frontmatter

\input{title}

\setcounter{page}{2} % start page number with 2




\chapter{ABSTARCT}

\chapter{Acknowledgement}
\tableofcontents
\chapter{ONE}
\input{chapters/chapter01}
\chapter{TWO}
\input{chapters/chapter02}

\end{document}

你能告诉我如何解决这个问题吗?谢谢。

答案1

您缺少\mainmatter来获取阿拉伯语页码。此外,缺少 导致的数字错误也是由于缺少 造成的\。以下代码确实修复了这些问题。还有其他问题吗?

\documentclass[12pt,oneside,letterpaper,chapterprefix=on,numbers=noenddot]{scrbook}
%%%page set-up
\setcounter{secnumdepth}{4}
\usepackage[margin=1in,includefoot,heightrounded]{geometry}%1 inch margins
\usepackage{mathptmx} %times new roman
\usepackage{setspace}%double spacing in text, not captions or footnotes
\usepackage{indentfirst} %indent first paragraph 
\setlength{\parindent}{2em} %adjust indentation
\usepackage[document]{ragged2e} %ragged right
\setlength{\RaggedRightParindent}{\parindent}
\usepackage{comment}% a convenient package
\pagestyle{plain}%remove headers
\usepackage[justification=raggedright,singlelinecheck=false,labelsep=period]{caption}
%captions left justify
\setkomafont{captionlabel}{\bfseries}%make caption label bold
\setkomafont{caption}{\bfseries}%make caption bold
\setcapindent{0pt}%removes hanging indent from captions
\usepackage{caption}
\captionsetup{figurename=FIGURE,tablename=TABLE}


%%% bibliography modifications
\usepackage[square,sort,comma,numbers]{natbib}
\setlength{\bibsep}{\baselineskip}%line spacing between citations
\setlength{\bibhang}{2em}%%%hanging identation
\makeatletter
\renewcommand\NAT@bibsetnum[1]{\settowidth\labelwidth{\@biblabel{#1}}%
   \setlength{\leftmargin}{\bibindent}\addtolength{\leftmargin}%
{\dimexpr\labelwidth+\labelsep\relax}%
 \setlength{\itemindent}{-\bibindent}%
 \setlength{\listparindent}{\itemindent}

   \setlength{\itemsep}{\bibsep}\setlength{\parsep}{\z@}%
   \ifNAT@openbib
     \addtolength{\leftmargin}{\bibindent}%
     \setlength{\itemindent}{-\bibindent}%
     \setlength{\listparindent}{\itemindent}%
     \setlength{\parsep}{0pt}%
   \fi
}
\makeatother

%%% extra code for getting the correct line spacing after references title
\let\oldbibliography\bibliography %store \bibliography in \oldbibliography
\renewcommand{\bibliography}[1]{{ %
 \let\chapter\section %copy\ section over\ chapter
 \oldbibliography{#1}}} %old\ bibliography

%%% uppercase chapters
\makeatletter
%\renewcommand\sectionlinesformat[4]{%
% \@hangfrom{\hskip#2 #3}{\MakeUppercase{#4}}%
%}
\renewcommand\chapterlinesformat[3]{%
 \@hangfrom{#2}{\MakeUppercase{#3}}%
}
\makeatother
\renewcommand\chapterlineswithprefixformat[3]{%
 \MakeUppercase{#2#3}%
}
%%% continuous table and figure numbering
\usepackage{chngcntr}
\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}

%%% chapter titles
\let\raggedchapter\centering
\RedeclareSectionCommand[
  beforeskip=0pt,
  afterskip=0pt]{chapter}
\setkomafont{disposition}{\bfseries\normalsize}
\setkomafont{chapter}{\normalsize}

%%% section titles
\let\raggedsection\centering
\setkomafont{section}{\normalsize}
\RedeclareSectionCommand[
  beforeskip=0pt,
  afterskip=0.01pt]{section}
%%% subsection title
\let\raggedsubsection\centering
\setkomafont{subsection}{\normalsize}
\RedeclareSectionCommand[
  beforeskip=0pt,
  afterskip=0.01pt]{subsection}
%%% subsubsection titles
\let\raggedsubsubsection\centering
\setkomafont{subsubsection}{\normalsize}
\RedeclareSectionCommand[
  beforeskip=0pt,
  afterskip=0pt]{subsubsection}
%%% remove identation from captions
\usepackage{etoolbox}
\AtBeginEnvironment{figure}{\setlength{\RaggedRightParindent}{0em}}
\AtBeginEnvironment{table}{\setlength{\RaggedRightParindent}{0em}}
\patchcmd{\thebibliography}{\chapter*}{}{}


%%%modify table of contents 
\usepackage{tocloft}
\renewcommand{\cftchapaftersnum}{.} %place a period after chapter numbers
\setlength{\cftbeforetoctitleskip}{0pt} %keep at 1 inch margin
\setlength{\cftaftertoctitleskip}{0pt} % keep the double spacing
\renewcommand*\contentsname{TABLE OF CONTENTS} % rename contents
\renewcommand{\cfttoctitlefont}{\hspace*\fill}{\normalsize\bfseries}%keep consistent font size
\renewcommand{\cftaftertoctitle}{\hspace*{\fill}} %center title
\KOMAoptions{toc=chapterentrydotfill} %dotted chapter entries
\setkomafont{chapterentry}{} %make chapter titles not bold
\addtokomafont{chapterentrypagenumber}{\mdseries} %make page numbers not bold
%%% indents numbered chapters
\RedeclareSectionCommand[tocnumwidth=3.5em]{chapter}
\renewcommand\addchaptertocentry[2]{%
  \ifstr{#1}{}{%
    \addtocentrydefault{chapter}{#1}{#2}%
  }{%
    \addtocentrydefault{chapter}{\hspace*{2em}#1}{#2}%
}}

%%% list of tables
\setlength{\cftbeforelottitleskip}{0pt} % keep at 1 inch margin
\setlength{\cftafterlottitleskip}{0pt} %keep the double spacing
\renewcommand*\listtablename{LIST OF TABLES} %rename contents
\renewcommand{\cftlottitlefont}{\hspace*{\fill}\normalsize\bfseries} %keep consistent font size
\renewcommand{\cftafterlottitle}{\hspace*{\fill}}%center title
\setlength{\cfttabindent}{0pt} % remove indentation from tables in lot 

%%% list of figures
\setlength{\cftbeforeloftitleskip}{0pt} % keep at 1 inch margin
\setlength{\cftafterloftitleskip}{0pt} %keep the double spacing
\renewcommand*\listfigurename{LIST OF FIGURES} % rename contents
\renewcommand{\cftloftitlefont}{\hspace*{\fill}\normalize\bfseries}% keep consistent font size
\renewcommand{\cftafterloftitle}{\hspace*{\fill}} %center title
\setlength{\cftfigindent}{0pt} % remove identation from figures in 1of


%%% set up appendix
%\ usepackage[page,toc,title]{appendix}
%\renewcommand{\appendixtocname}{APPENDICES}
\usepackage[toc,title]{appendix}
\renewcommand{\appendixtocname}{APPENDIX: EXAMPLE OF AN APPENDIX}
\renewcommand{\appendixpagename}{\vspace*{\fill}\centering\normalsize
APPENDICES\vspace*{\fill}}



%%% Figure packages
\usepackage{graphicx}
\graphicspath{{figures/}}
\usepackage{wrapfig}
\usepackage{pdfpages}
\usepackage{subcaption} % allows side by side figures

\usepackage{amsmath}
\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=black,
    linkcolor=black,
    urlcolor=black}
%%%---------------------------------------------------------------------

%%%-----------------------------------------------------------

%%%------------------------------------------------------------
\begin{document}
\frontmatter

%\input{title}

\setcounter{page}{2} % start page number with 2




\chapter{ABSTARCT}

\chapter{Acknowledgement}
\tableofcontents
\mainmatter
\chapter{ONE}
\section{one.one}
\section{one.two}
%\input{chapters/chapter01}
\chapter{TWO}
\section{two.one}
\section{two.two}
%\input{chapters/chapter02}

\end{document}

答案2

不要将包tocloft与 KOMA-Script 类一起使用。至少不要混合使用它们的命令来格式化目录和列表。

这是仅使用 KOMA-Script 可能性的建议。但我不确定应该如何对章节进行编号,以及 ToC 和列表(LoT 和 LoF)是否真的应该在章节级别。请注意,我将删除与问题无关的包。

\documentclass[12pt,oneside,letterpaper,chapterprefix=on,numbers=noenddot,
  listof=leveldown% if lists like LoF and LoT should be on section level
]{scrbook}
\setuptoc{toc}{leveldown}% if ToC should be on section level

\usepackage[english]{babel}
\renewcaptionname{english}{\figurename}{FIGURE}
\renewcaptionname{english}{\tablename}{TABLE}
\renewcaptionname{english}{\listtablename}{List of Tables}
\renewcaptionname{english}{\listfigurename}{List of Figures}
\renewcaptionname{english}{\contentsname}{Table of Contents}

%%%page set-up
\usepackage[margin=1in,includefoot,heightrounded]{geometry}
\usepackage{mathptmx}
\usepackage{setspace}

\setlength{\parindent}{2em}
\usepackage[document]{ragged2e}
\setlength{\RaggedRightParindent}{\parindent}

\pagestyle{plain}

\usepackage[justification=raggedright,singlelinecheck=false,labelsep=period]{caption}
\usepackage{subcaption}
\setkomafont{captionlabel}{\bfseries}
\setkomafont{caption}{\bfseries}
\setcapindent{0pt}

\usepackage{xpatch}% lädt auch etoolbox
\AtBeginEnvironment{figure}{\setlength{\RaggedRightParindent}{0em}}
\AtBeginEnvironment{table}{\setlength{\RaggedRightParindent}{0em}}

%%% no indent for the list entries in LoT and LoF
\DeclareTOCStyleEntry[indent=0pt]{tocline}{table}
\DeclareTOCStyleEntry[indent=0pt]{tocline}{figure}

%%% continuous table and figure numbering
\usepackage{chngcntr}
\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}

% settings for chapters and other section levels
\setcounter{secnumdepth}{4}
\let\raggedsection\centering
\setkomafont{disposition}{\bfseries\normalsize}
%%% chapter titles
\RedeclareSectionCommand[
  beforeskip=0pt,
  afterskip=0pt,
  font=\normalsize,
  tocnumwidth=3.5em,
  tocentrynumberformat=\tocchapnumformat,
  toclinefill=\TOCLineLeaderFill
  ]{chapter}
\newcommand*\tocchapnumformat[1]{\hspace*{2em}#1\autodot\hfil}
\addtokomafont{chapterentry}{\mdseries}
\addtokomafont{chapterentrypagenumber}{\mdseries}

%%% uppercase chapters
\makeatletter
%\renewcommand\sectionlinesformat[4]{%
% \@hangfrom{\hskip#2 #3}{\MakeUppercase{#4}}%
%}
\renewcommand\chapterlinesformat[3]{%
 \@hangfrom{#2}{\MakeUppercase{#3}}%
}
\makeatother
\renewcommand\chapterlineswithprefixformat[3]{%
 \MakeUppercase{#2#3}%
}
\xpatchcmd{\addchaptertocentry}
  {\addtocentrydefault{chapter}{#1}{#2}}
  {\addtocentrydefault{chapter}{#1}{\protect\chaptertocentryformat{#2}}}
  {}{\PatchFailed}
\newcommand*\chaptertocentryformat[1]{#1}
\AfterTOCHead[toc]{\renewcommand*\chaptertocentryformat[1]{\MakeUppercase{#1}}}

%%% section, subsection, subsubsection titles
\RedeclareSectionCommands[
  beforeskip=0pt,
  afterskip=0.01pt,
  font=\normalsize
  ]{section,subsection,subsubsection}

\usepackage{blindtext}% only for dummy text
\begin{document}
\frontmatter
\begin{titlepage}
Title
\end{titlepage}
\chapter{Abstract}
\blindtext
\chapter{Acknowledgement}
\blindtext
\tableofcontents
\listoffigures

\mainmatter
\blinddocument
\blinddocument
\begin{figure}
  \rule{2cm}{1cm}
  \caption{\blindtext}
\end{figure}
\end{document}

在此处输入图片描述

相关内容