我需要一些帮助来订购这些导入,以便 hyperref 包正常工作

我需要一些帮助来订购这些导入,以便 hyperref 包正常工作

我正在编写我的第一份 Latex 文档。我的文档现在有 140 页长,我认为将目录设为可点击是一个好主意。我使用 ShareLatex 来编译我的代码。我导入了 hyperref 包,但发现我的代码无法编译。具体来说,ShareLatex 告诉我:

“超时。抱歉,您的编译运行时间过长,已超时。这可能是由于存在大量高分辨率图像或复杂图表所致。”

如果我转到日志选项卡,我只会看到一些过满和不足的警告。现在,我使用大约 20 张正常大小的照片和一个不太复杂的图表。当然,如果我评论,整个\usepackage{hyperref}文档将在不到 7 秒的时间内加载。我搜索了很多,发现导入超链接时需要考虑很多事情。我读手册以及问题哪些包应该在 hyperref 之后而不是之前加载?但我无法让它工作。这是我的导入标头的样子:

%\documentclass[draft]{report}
\documentclass{report}
\usepackage[noend]{algpseudocode}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage{calculator}
\usepackage[spanish]{babel}
\usepackage{csquotes}
\usepackage{verbatimbox}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{moreverb}
\usepackage{fancyhdr}
\usepackage{fancyvrb}
\usepackage{enumitem}
\usepackage{textcomp}
\usepackage{wrapfig}
\usepackage[headheight=110pt]{geometry}
\AtBeginDocument{%
\let\AtBeginDvi\OrgAtBeginDvi
}

\usepackage{subfiles}
\usepackage{multicol}
\usepackage[toc,page]{appendix}
\usepackage{url}
\usepackage{tikz}
\usepackage{framed}
\usepackage{xcolor}
\usepackage{booktabs}
\usepackage{longtable}
%% Set some local commands and colors
\usepackage{colortbl}
\definecolor{green}{rgb}{0.1,0.1,0.1}
\usepackage[
backend=biber,
style=alphabetic,
sorting=ynt,
maxnames=99,
maxalphanames=5
]{biblatex}
\addbibresource{bibliografia.bib}
\graphicspath{{images/}{../images/}}
\newcommand{\specialcell}[2][c]{
    \begin{tabular}[#1]{@{}c@{}}#2\end{tabular}
}
\renewcommand{\figurename}{Figura}
\renewcommand{\lstlistingname}{Código}
\renewcommand\lstlistlistingname{Listado de Códigos}

\usepackage{lastpage}
\usepackage{pgfgantt}

%\usepackage{hyperref} %WHERE SHOULD I PUT THIS LINE?

\usepackage{tabularx}
\usepackage{algorithm}
\renewcommand{\listofalgorithms}{ 
  \begingroup 
    \listof{algorithm}{Listado de Pseudocódigos} 
  \endgroup 
}

\begin{document}

我按照 runartrollet 的建议更新了我的 main.tex。但是它仍然无法编译。这就是我的所有的main.tex 现在看起来像:

\documentclass[%
%draft,%
]{report}

\usepackage[noend]{algpseudocode}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[headheight=110pt]{geometry}
\usepackage[toc,page]{appendix}
\usepackage[
backend=biber,
style=alphabetic,
sorting=ynt,
maxnames=99,
maxalphanames=5
]{biblatex}
\usepackage{%
blindtext,
calculator,
csquotes,
verbatimbox,
graphicx,
mathtools, %(replaces amsmath, and fixes a few errors in it)
listings,
moreverb,
fancyhdr,
fancyvrb,
enumitem,
textcomp,
wrapfig,
subfiles,
multicol,
url,
tikz,
framed,
xcolor,
booktabs,
longtable,
colortbl,
lastpage,
pgfgantt,
tabularx,
algorithm,
hyperref
}
\AtBeginDocument{%
\let\AtBeginDvi\OrgAtBeginDvi
}
%% Set some local commands and colors
\definecolor{green}{rgb}{0.1,0.1,0.1}
\addbibresource{bibliografia.bib}
\graphicspath{{images/}{../images/}}
\newcommand{\specialcell}[2][c]{
    \begin{tabular}[#1]{@{}c@{}}#2\end{tabular}
}
\renewcommand{\figurename}{Figura}
\renewcommand{\lstlistingname}{Código}
\renewcommand\lstlistlistingname{Listado de Códigos}


\renewcommand{\listofalgorithms}{ 
  \begingroup 
    \listof{algorithm}{Listado de Pseudocódigos} 
  \endgroup 
}
\begin{document}


\begin{titlepage}
\begin{center}
\vspace*{-1in}
\begin{figure}[htb]
\begin{center}
\vspace*{1.6in}
\includegraphics[width=8cm]{uc3m.png}
\vspace*{0.6in}
\end{center}
\end{figure}
\begin{large}
Trabajo de Fin de Grado\\
\end{large}
\vspace*{0.2in}
\begin{Large}
\textbf{Valoración de startups\\con\\ Aprendizaje Automático} \\
\end{Large}
\vspace*{0.3in}
\vspace*{0.3in}
\rule{80mm}{0.1mm}\\
\vspace*{0.1in}
\begin{large}

\end{large}
\end{center}

\end{titlepage}
\pagestyle{fancy}
\lhead{\includegraphics[scale=1]{encabezado.jpg}}

\subfile{ackstract}

\tableofcontents

\listoffigures
\listoftables
\lstlistoflistings
\begingroup
\let\clearpage\relax
\listofalgorithms
\endgroup
\clearpage
\part{Introduction}
    \chapter{Presentation, motivation and objectives}
    \subfile{chapters/intro}
\part{Teoría y Estado del Arte}
    \chapter{Valoración}
    \subfile{chapters/ea_valoracion}
    \chapter{Aprendizaje Automático}
    \subfile{chapters/ea_inf}    
    \chapter{Metodologías}
    \subfile{chapters/metodologia}
    \chapter{Herramientas}
    \subfile{chapters/herramientas}
\part{Contrucción del modelo}
    \chapter{Determinando la actividad de la empresa}
    \subfile{chapters/p_sectores_industrias}
    \chapter{Tasa descuento y riesgo}
    \subfile{chapters/rwg}
    \chapter{Flujos de caja libres}
    \subfile{chapters/p_flujos}
    \chapter{Aplicación del modelo}
    \subfile{chapters/aplicacion}
    \chapter{Despliegue}
    \subfile{chapters/integrate}
\part{Conclusiones}
    \subfile{chapters/conclusiones}
\printbibliography[
heading=bibintoc,
title={Referencias}
]
\begin{appendices}
\chapter{Listado de frecuencias de industrias}
\subfile{appendices/listado_frecuencias_industrias}
\chapter{Distribuciones estadísticas}
\subfile{appendices/distribuciones}
\chapter{Planificación}
\subfile{appendices/planificacion}
\end{appendices}
\clearpage
\end{document}

我将我的项目导出到 Overleaf,这给了我更多的反馈:

./main.out:92:
Missing \endcsname inserted.
<to be read again> 
                   \unhbox 
l.92 ...tor \futurelet \textbf  ndice.alph1.Alph3}

我也可以获得日志档案

答案1

修复编译问题(问题已编辑,并出现了新问题)

在查看完您的代码后,我重命名了这些行(子文件被注释掉,只是因为我没有它们,所以只对它们进行注释):

\begin{appendices}
\chapter{Listado de frecuencias de industrias}
%\subfile{appendices/listado_frecuencias_industrias}
\chapter{Distribuciones estadísticas}
%\subfile{appendices/distribuciones}
\chapter{Planificación}
%\subfile{appendices/planificacion}
\end{appendices}

进入以下几行,环境appendices更改为\appendix

\appendix
\chapter{Listado de frecuencias de industrias}
%\subfile{appendices/listado_frecuencias_industrias}
\chapter{Distribuciones estadísticas}
%\subfile{appendices/distribuciones}
\chapter{Planificación}
%\subfile{appendices/planificacion}

之后,它可以在这里编译成功(删除我没有的图形代码,插入\documentclass并注释掉我没有的所有其他子文件后)。

我注意到您使用了\begin{center}, \end{center},您应该用简单的 \centering 替换它,以避免一些间距问题。请参阅何时应使用 \begin{center} 而不是 \centering?

另外,评论中提到,您有一些代码不再记得它们的用途,并且发现删除它们并不会真正改变任何东西。您应该多注释您的代码。尤其是像这样的特殊代码,我不知道它是做什么的。添加新的和不熟悉的包时也要注释。从长远来看,这确实可以为您节省大量时间和麻烦。

修复 hyperref 问题(首先提到)

以下是包含您代码的工作示例。目录如下可点击的。

您的代码似乎运行良好,只需进行一些修改即可。我并没有在您的代码中添加太多内容,只是添加了一个简单的和\section。此外,我取消了\tableofcontents\end{document}\usepackage{hyperref}。正如您已经阅读的哪些包应该在 hyperref 之后加载而不是之前加载?,您可能知道哪些包会干扰。大多数情况下它应该放在最后,只有少数包应该放在后面,例如cleverref。链接的帖子可以详细说明。

此外,在顶部,您使用了一个注释掉的\documentclass选项,我猜是为了在draft和之间final快速切换。这可以通过对每个选项使用一行并,在末尾添加一个来简化,如下所示。然后您只需注释掉该行即可禁用该选项。您也可以对加载包执行此操作,我在这里进行了编辑以显示这一点。现在代码少了很多,信息更多,很容易注释掉。

\documentclass[%
%draft,%
]{report}

\usepackage[noend]{algpseudocode}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[headheight=110pt]{geometry}
\usepackage[toc,page]{appendix}
\usepackage[
backend=biber,
style=alphabetic,
sorting=ynt,
maxnames=99,
maxalphanames=5
]{biblatex}
\usepackage{%
blindtext,
calculator,
csquotes,
verbatimbox,
graphicx,
mathtools, %(replaces amsmath, and fixes a few errors in it)
listings,
moreverb,
fancyhdr,
fancyvrb,
enumitem,
textcomp,
wrapfig,
subfiles,
multicol,
url,
tikz,
framed,
xcolor,
booktabs,
longtable,
colortbl,
lastpage,
pgfgantt,
tabularx,
algorithm,
hyperref
}
\AtBeginDocument{%
\let\AtBeginDvi\OrgAtBeginDvi
}
%% Set some local commands and colors
\definecolor{green}{rgb}{0.1,0.1,0.1}
\addbibresource{bibliografia.bib}
\graphicspath{{images/}{../images/}}
\newcommand{\specialcell}[2][c]{
    \begin{tabular}[#1]{@{}c@{}}#2\end{tabular}
}
\renewcommand{\figurename}{Figura}
\renewcommand{\lstlistingname}{Código}
\renewcommand\lstlistlistingname{Listado de Códigos}


\renewcommand{\listofalgorithms}{ 
  \begingroup 
    \listof{algorithm}{Listado de Pseudocódigos} 
  \endgroup 
}

\begin{document}
\tableofcontents
\clearpage
\section{Foo}   
\end{document}

相关内容