此代码中的两个错误:原因和意义

此代码中的两个错误:原因和意义

Overleaf 告诉我此代码中有 2 个错误:

\documentclass{book}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,top=3cm,bottom=3cm,left=1.5cm,right=1.5cm]{geometry}
\usepackage{xcolor}
\usepackage{imakeidx}
\usepackage[tight, italian]{minitoc}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc}
\usepackage{hyperref}

%\newcommand*{\l@chapter}[2]{%
%\ifnum \c@tocdepth >\m@ne \addpenalty{-\@highpenalty}%
%\vskip 1.0em \@plus\p@}

\newif{\ifTOC}

\newcommand{\mytikzmark}[1]{\ifTOC\tikzmark{#1}\fi}

\setcounter{chapter}{-1}

\setcounter{section}{-1}

\newcommand*{\arabicdec}[1]{\the\numexpr\value{#1}-1\relax}
%\renewcommand*{\thechapter}{\arabicdec{chapter}}
\renewcommand*{\thesection}{\thechapter.\arabicdec{section}}

\setcounter{secnumdepth}{3}

\setcounter{tocdepth}{4}

\makeatletter
% copied from book
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil
      \nobreak\hb@xt@\@pnumwidth{\hss #2%
                                 \kern-\p@\kern\p@}\par
      \penalty\@highpenalty
\vspace{-10pt}% or whatever
    \endgroup
  \fi
}
\makeatother

\begin{document}

\title{\color{red}{\Huge{\textbf{ALGEBRA LINEARE}}}}
\author{\color{blue}{\Huge{\textbf{???}}}}
\date{27 Febbraio 2021 $-$ xx Mese Anno}

\frontmatter

\maketitle

\dominitoc

\TOCtrue
\tableofcontents
\TOCfalse

\newpage

\section*{PREFAZIONE GENERALE}
\addcontentsline{toc}{section}{\protect\numberline{}PREFAZIONE GENERALE}

\mainmatter

\chapter{NOTAZIONI PRELIMINARI}
\minitoc %\minilof\minilot
\mtcskip
\pagestyle{plain}

\addtocontents{toc}{\string\mytikzmark{TOCboxa}}%
\section[??\string\hspace{80pt}]{??}
\subsection[???\string\hspace{48pt}]{???}
\subsubsection[????\string\mytikzmark{TOCboxb}]{????}
\addtocontents{toc}{\vspace{5pt}\string\tikz[overlay,remember picture]% make sure on same apge
  {\string\draw ($(pic cs:TOCboxa)+(-2pt,3pt-\the\dp\strutbox)$) rectangle 
      ($(pic cs:TOCboxb)+(3pt,0pt-\the\dp\strutbox)$);}}
      

\part[FONDAMENTI DELL'ALGEBRA LINEARE]%
{\huge\color{red}{FONDAMENTI DELL'ALGEBRA LINEARE}}

\section*{Prefazione alla Prima Parte}

\addcontentsline{toc}{section}{Prefazione alla Prima Parte}
%\Large{Inserire una Prefazione}

\chapter{One}
\minitoc %\minilof\minilot
\mtcskip


\addtocontents{toc}{\string\mytikzmark{TOCboxA}}%
\section[One.One\string\hspace{130pt}]{One.One}
\subsection[One.One.One\string\hspace{78pt}]{One.One.One}
\subsubsection[Very long Expression\string\mytikzmark{TOCboxB}]{One.One.One.One}
\addtocontents{toc}{\string\tikz[overlay,remember picture]% make sure on same apge
  {\string\draw ($(pic cs:TOCboxA)+(-2pt,3pt-\the\dp\strutbox)$) rectangle 
      ($(pic cs:TOCboxB)+(3pt,0pt-\the\dp\strutbox)$);}}%
  
\addtocontents{toc}{\string\mytikzmark{TOCboxC}}%
\section[One.One\string\hspace{116pt}]{One.One}
\subsection[One.One.One\string\hspace{64pt}]{One.One.One}
\subsubsection[One.One.One.One\string\mytikzmark{TOCboxD}]{One.One.One.One}
\addtocontents{toc}{\string\tikz[overlay,remember picture]% make sure on same apge
  {\string\draw ($(pic cs:TOCboxC)+(-5pt,3pt-\the\dp\strutbox)$) rectangle 
      ($(pic cs:TOCboxD)+(3pt,0pt-\the\dp\strutbox)$);}}%
      
\addtocontents{toc}{\string\mytikzmark{TOCboxE}}%
\section[One.One\string\hspace{116pt}]{One.One}
\subsection[One.One.One\string\hspace{64pt}]{One.One.One}
\subsubsection[One.One.One.One\string\mytikzmark{TOCboxF}]{One.One.One.One}
\addtocontents{toc}{\string\tikz[overlay,remember picture]% make sure on same apge
  {\string\draw ($(pic cs:TOCboxE)+(-5pt,3pt-\the\dp\strutbox)$) rectangle 
      ($(pic cs:TOCboxF)+(3pt,0pt-\the\dp\strutbox)$);}}%
      

\end{document}

错误如下:

(双重)LaTeX 错误:出现问题 - 可能缺少 \item。(output.toc,9),这是:

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.9 ...FONDAMENTI DELL'ALGEBRA LINEARE}{3}{part.1}
                                                  %
Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

为什么?这是什么意思?

(尽管如此,我还是得到了该代码的编译)

(如果您需要汇编照片,我会编辑我的问题并添加一张照片)

太感谢了

第一次编辑:阅读注释,此代码产生:

4支撑架

没有这部分

\addtocontents{toc}{\vspace{5pt}
\string\tikz[overlay,remember picture]% make sure on same page
{\string\draw ($(pic cs:TOCboxa)+(-2pt,3pt-\the\dp\strutbox)$) rectangle ($(pic cs:TOCboxb)+(3pt,0pt-\the\dp\strutbox)$);}}

我有这个我不喜欢的汇编(尽管如此,我没有更多的错误)

3支撑架

strutbox(请注意 的第一部分没有toableofcontents

答案1

我发现沃纳罗宾·赫尔默帮助一个更好的解决方案:

\documentclass{book}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,top=3cm,bottom=3cm,left=1.5cm,right=1.5cm]{geometry}
\usepackage{xcolor}
\usepackage{imakeidx}
\usepackage[tight, italian]{minitoc}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc}
\usepackage{hyperref}

%\newcommand*{\l@chapter}[2]{%
%\ifnum \c@tocdepth >\m@ne \addpenalty{-\@highpenalty}%
%\vskip 1.0em \@plus\p@}

\newif{\ifTOC}

\newcommand{\mytikzmark}[1]{\ifTOC\tikzmark{#1}\fi}

\setcounter{chapter}{-1}

\setcounter{section}{-1}

\newcommand*{\arabicdec}[1]{\the\numexpr\value{#1}-1\relax}
%\renewcommand*{\thechapter}{\arabicdec{chapter}}
\renewcommand*{\thesection}{\thechapter.\arabicdec{section}}

\setcounter{secnumdepth}{3}

\setcounter{tocdepth}{4}

\makeatletter
% copied from book
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil
      \nobreak\hb@xt@\@pnumwidth{\hss #2%
                                 \kern-\p@\kern\p@}\par
      \penalty\@highpenalty
\vspace{-10pt}% or whatever
    \endgroup
  \fi
}
\makeatother

\begin{document}

\title{\color{red}{\Huge{\textbf{ALGEBRA LINEARE}}}}
\author{\color{blue}{\Huge{\textbf{???}}}}
\date{27 Febbraio 2021 $-$ xx Mese Anno}

\frontmatter

\maketitle

\dominitoc

\TOCtrue
\tableofcontents
\TOCfalse

\newpage

\section*{PREFAZIONE GENERALE}
\addcontentsline{toc}{section}{\protect\numberline{}PREFAZIONE GENERALE}

\mainmatter

\chapter{NOTAZIONI PRELIMINARI}
\minitoc %\minilof\minilot
\mtcskip
\pagestyle{plain}

\addtocontents{toc}{\string\mytikzmark{TOCboxa}}%
\section[??\string\hspace{80pt}]{??}
\subsection[???\string\hspace{48pt}]{???}
\subsubsection[????\string\mytikzmark{TOCboxb}]{????}
\addtocontents{toc}{\vspace{-25pt}
\string\tikz[overlay,remember picture]% make sure on same page
{\string\draw ($(pic cs:TOCboxa)+(-2pt,3pt-\the\dp\strutbox)$) rectangle ($(pic cs:TOCboxb)+(3pt,0pt-\the\dp\strutbox)$);}\string\par}
      

\part[FONDAMENTI DELL'ALGEBRA LINEARE]%
{\huge\color{red}{FONDAMENTI DELL'ALGEBRA LINEARE}}

\section*{Prefazione alla Prima Parte}

\addcontentsline{toc}{section}{Prefazione alla Prima Parte}
%\Large{Inserire una Prefazione}

\chapter{One}
\minitoc %\minilof\minilot
\mtcskip


\addtocontents{toc}{\string\mytikzmark{TOCboxA}}%
\section[One.One\string\hspace{130pt}]{One.One}
\subsection[One.One.One\string\hspace{78pt}]{One.One.One}
\subsubsection[Very long Expression\string\mytikzmark{TOCboxB}]{One.One.One.One}
\addtocontents{toc}{\string\tikz[overlay,remember picture]% make sure on same apge
  {\string\draw ($(pic cs:TOCboxA)+(-2pt,3pt-\the\dp\strutbox)$) rectangle 
      ($(pic cs:TOCboxB)+(3pt,0pt-\the\dp\strutbox)$);}}%
  
\addtocontents{toc}{\string\mytikzmark{TOCboxC}}%
\section[One.One\string\hspace{116pt}]{One.One}
\subsection[One.One.One\string\hspace{64pt}]{One.One.One}
\subsubsection[One.One.One.One\string\mytikzmark{TOCboxD}]{One.One.One.One}
\addtocontents{toc}{\string\tikz[overlay,remember picture]% make sure on same apge
  {\string\draw ($(pic cs:TOCboxC)+(-5pt,3pt-\the\dp\strutbox)$) rectangle 
      ($(pic cs:TOCboxD)+(3pt,0pt-\the\dp\strutbox)$);}}%
      
\addtocontents{toc}{\string\mytikzmark{TOCboxE}}%
\section[One.One\string\hspace{116pt}]{One.One}
\subsection[One.One.One\string\hspace{64pt}]{One.One.One}
\subsubsection[One.One.One.One\string\mytikzmark{TOCboxF}]{One.One.One.One}
\addtocontents{toc}{\string\tikz[overlay,remember picture]% make sure on same apge
  {\string\draw ($(pic cs:TOCboxE)+(-5pt,3pt-\the\dp\strutbox)$) rectangle 
      ($(pic cs:TOCboxF)+(3pt,0pt-\the\dp\strutbox)$);}}%
      

\end{document}

这是解决我的两个错误的主要部分:

\addtocontents{toc}{\vspace{-25pt}
\string\tikz[overlay,remember picture]% make sure on same page
{\string\draw ($(pic cs:TOCboxa)+(-2pt,3pt-\the\dp\strutbox)$) rectangle ($(pic cs:TOCboxb)+(3pt,0pt-\the\dp\strutbox)$);}\string\par}

再次感谢你

答案2

更新答案:

这似乎是编译过程的一个问题,因为当使用 进行编译时latexmk,我收到错误:

在此处输入图片描述

并且文件中的错误.toc无法解释为什么会发生:

在此处输入图片描述

pdflatex同时,经过几次编译就会得到您想要的结果,并且没有任何错误。

上一个答案:

你的那点小\addtocontents内容tikz给你带来了麻烦。

\addtocontents{toc}{\vspace{5pt}\string\tikz[overlay,remember picture]% make sure on same apge
  {\string\draw ($(pic cs:TOCboxa)+(-2pt,3pt-\the\dp\strutbox)$) rectangle 
      ($(pic cs:TOCboxb)+(3pt,0pt-\the\dp\strutbox)$);}}

删除它,您的问题就解决了。但我不确定为什么会有这行代码,因为它无法正常工作,因为它不会向实际文档添加任何内容。

相关内容