无法编译并给出 LaTeX 错误:包 inputenc 的选项冲突

无法编译并给出 LaTeX 错误:包 inputenc 的选项冲突

我没有将 inputenc 写入两次。至少我的主要 tex 文件中没有它。我不确定是什么导致了这个错误,并且可以使用一些帮助来对其进行故障排除。

这是我在文档开始之前写的所有内容:

% -----------------------------------Initialize Document----------------------------------------
\documentclass[12pt]{article}  
\usepackage{textcomp}  
\usepackage[headheight=12pt, headsep=0pt, nohead, nofoot]{geometry}  
\usepackage{graphicx}  
\usepackage{subcaption}  
\usepackage{subfig}  
\usepackage{multicol}  
\usepackage{siunitx}  
\usepackage{wrapfig}  
\usepackage{amsmath}  
\usepackage[colorlinks]{hyperref}  
\usepackage[utf8]{inputenc}  
\usepackage{lipsum}  

\setlength{\footskip}{40pt}  

\DeclareSIUnit\gauss{G}  
\input{style/common.tex}  
\input{style/scala.tex}  
\lstset{frame=, basicstyle={\footnotesize\ttfamily}}  
\graphicspath{ {images/} }  


%-----------------------------------------Cover Page----------------------------------------  

这是我得到的错误:

 LaTeX Error: Option clash for package inputenc.  

See the LaTeX manual or LaTeX Companion for explanation.  
Type  H <return>  for immediate help.  
 ...                                                

l.2 \usepackage  
               [british,UKenglish]{babel}  
The package inputenc has already been loaded with options:  
  [utf8]  
There has now been an attempt to load it with options  
  [utf8x]  
Adding the global options:  
  utf8,utf8x  
to your \documentclass declaration may fix this.  
Try typing  <return>  to proceed.  

(/usr/share/texlive/texmf-dist/tex/generic/babel/babel.sty  
Package: babel 2016/04/23 3.9r The Babel package  
(/usr/share/texlive/texmf-dist/tex/generic/babel-english/english.ldf  
Language: english 2012/08/20 v3.3p English support from the babel system  
(/usr/share/texlive/texmf-dist/tex/generic/babel/babel.def  
File: babel.def 2016/04/23 3.9r Babel common definitions  
\babel@savecnt=\count173  
\U@D=\dimen190  
)  
\l@canadian = a dialect from \language\l@american   
\l@australian = a dialect from \language\l@british   
\l@newzealand = a dialect from \language\l@british   
) (/usr/share/texlive/texmf-dist/tex/generic/babel-english/english.ldf  
Language: english 2012/08/20 v3.3p English support from the babel system  
)) (/usr/share/texlive/texmf-dist/tex/latex/graphics/color.sty  
Package: color 2016/07/10 v1.1e Standard LaTeX Color (DPC)  
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg  
File: color.cfg 2016/01/02 v1.6 sample color configuration  
)  
Package color Info: Driver file: pdftex.def on input line 147.  
) (/usr/share/texlive/texmf-dist/tex/latex/fancyref/fancyref.sty  
Package: fancyref 1999/02/03 v0.9c Fancy cross-referencing  
(/usr/share/texlive/texmf-dist/tex/latex/tools/varioref.sty  
Package: varioref 2016/02/16 v1.5c package for extended references (FMi)  
\c@vrcnt=\count174  
)) (/usr/share/texlive/texmf-dist/tex/latex/float/float.sty  
Package: float 2001/11/08 v1.3d Float enhancements (AL)  
\c@float@type=\count175  
\float@exts=\toks25  
\float@box=\box78  
\@float@everytoks=\toks26  
\@floatcapt=\box79  
) (/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrextend.sty  
Package: scrextend 2016/06/14 v3.21 KOMA-Script package (extend other classes   with features of KOMA-Script classes)  
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrkbase.sty  
Package: scrkbase 2016/06/14 v3.21 KOMA-Script package (KOMA-Script-dependent   basics and keyval usage)  
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrbase.sty  
Package: scrbase 2016/06/14 v3.21 KOMA-Script package (KOMA-Script-independent   basics and keyval usage)  
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrlfile.sty  
Package: scrlfile 2016/06/14 v3.21 KOMA-Script package (loading files)  
Package scrlfile, 2016/06/14 v3.21 KOMA-Script package (loading files)  
                  Copyright (C) Markus Kohm  

所以我把范围缩小到这一行。回滚到项目运行时并慢慢添加回更改后,这一行导致代码无法编译。


% -----------------------------------Initialize Document----------------------------------------
\documentclass[12pt]{article}
\usepackage{textcomp}
\usepackage[headheight=12pt, headsep=0pt, nohead, nofoot]{geometry}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{subfig}
\usepackage{multicol}
\usepackage{siunitx}
\usepackage{wrapfig}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage[colorlinks]{hyperref}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}

\setlength{\footskip}{40pt}

\DeclareSIUnit\gauss{G}
\input{style/common.tex}
\input{style/scala.tex}
\lstset{frame=, basicstyle={\footnotesize\ttfamily}}
\graphicspath{ {images/} }


%-----------------------------------------Cover Page----------------------------------------
\begin{document}

%-----------------------------------------ABSTRACT-------------------------------------
\begin{center}
{\large\bf{Abstract}}
\end{center}
\begin{enumerate}

%this line
\item click on "\textbf{\textit{Manage Passwords}". 

\end{enumerate}

\end{document}



答案1

您的文档代码存在几个常见问题:

  • 加载hyperref最后的。 有很少此规则有例外。(cleveref包是这些例外之一:它必须在之后加载hyperref。)

  • 不要同时加载subfigsubcaption。它们不兼容。只能选择其中一个,但并非两者兼而有之

  • 指令

    \lstset{frame=, basicstyle={\footnotesize\ttfamily}
    

    是错误的。除了必须加载listings包(您的代码无法做到这一点)才能激活\lstset宏之外,指令应该是

    \lstset{frame=, basicstyle={\footnotesize\ttfamily}}
    

    才能正常工作。你能发现不同之处吗?

  • 不要\bf在 LaTeX 文档中使用 Plain-TeX 指令。请\bfseries改用。

  • 不要不必要地使用{and }—— 这只会造成代码混乱。因此,

    \begin{center}
    {\large\bf{Abstract}}
    \end{center}
    

    写吧

    \begin{center}
    \large\bf Abstract
    \end{center}
    

    或者更好的是,

    \begin{center}
    \large\bfseries Abstract
    \end{center}
    
  • 请检查是否确实需要加载所有这些包。我总觉得有些包的加载毫无理由。

实施上述建议后,将获得以下结果:

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc} % it's usually a good idea to load this package early

\usepackage{textcomp}
\usepackage[headheight=12pt, headsep=0pt, nohead, nofoot]{geometry}
\usepackage{graphicx}

\usepackage{subcaption}
%\usepackage{subfig}

\usepackage{multicol}
\usepackage{siunitx}
\DeclareSIUnit\gauss{G}

\usepackage{wrapfig}
\usepackage{amsmath}

\usepackage{lipsum} % filler text

\setlength{\footskip}{40pt} % why??

% Commented out since I don't have the files 'common.tex' and 'scala.tex':
%\input{style/common.tex} 
%\input{style/scala.tex}

\usepackage{listings} % previously missing
\lstset{frame=, basicstyle={\footnotesize\ttfamily}}
\graphicspath{ {images/} }

\usepackage[colorlinks]{hyperref} % load this package LAST

\begin{document}

%--------------------------ABSTRACT---------------------
\begin{center}
\large\bfseries Abstract 
\end{center}

\begin{enumerate}

\item Click on ``\textbf{\textit{Manage Passwords}}''

\end{enumerate}

\end{document}

相关内容