更新:

更新:

我可以完美地编译main.tex下面的文件并在 OverLeaf 上生成 pdf,但无法在我的 PC 上的 TeXworks 上执行此操作。所以我无法有参考部分。

\documentclass[11pt,a4paper,oneside]{article}
\usepackage{natbib}
\usepackage{url}
\usepackage[utf8x]{inputenc}
\usepackage{siunitx}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{listings}
\usepackage{color}
\usepackage[colorlinks]{hyperref}
\usepackage{graphicx}
\graphicspath{{images/}}
\usepackage{hyperref}
\usepackage{parskip}
\usepackage{cite}
\usepackage{fancyhdr}
\usepackage{vmargin}
\setmarginsrb{3 cm}{2.5 cm}{3 cm}{2.5 cm}{1 cm}{1.5 cm}{1 cm}{1.5 cm}


\title{Life is too short to learn LaTeX}    % Title
\author{Rageful}    % Author
\date{01.01.2019} % Date

\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\let\thedate\@date
\makeatother

\pagestyle{fancy}
\fancyhf{}
\rhead{\theauthor}
\lhead{\thetitle}
\cfoot{\thepage}


\renewcommand{\refname}{Referance}

\begin{document}

\begin{titlepage}
   \centering
\vspace*{0.5 cm}
\includegraphics[scale = 0.08]{latex.png}\\[1.0 cm] 
{\centering \textsc{\LARGE \ \ \ \ \ \ \ \ \ LATEX} \newline\newline \textsc{\LARGE PROJECT}\\[2.0 cm]} 
\textsc{\Large 17.01.2019}\\[0.5 cm]    
\rule{\linewidth}{0.2 mm} \\[0.4 cm]
{ \huge \bfseries \thetitle}\\
\rule{\linewidth}{0.2 mm} \\[3.5 cm]

\begin{minipage}{0.5\textwidth}
    \begin{flushleft} \large
        \emph{Person A}\\
        \end{flushleft}
        \end{minipage}~
        \begin{minipage}{0.4\textwidth}

        \begin{flushright} \large
        \emph{Person B :} \\
    \end{flushright}
\end{minipage}\\[2 cm]
\end{titlepage}

\section{Preface}

Why is LaTeX too hard? \cite{Human:1}

\newpage

\bibliographystyle{unsrt}
\bibliography{\water} % bibliography prints here

\end{document}

帖子太复杂,难以理解。不起作用。

这是water.bib文件:

\RequirePackage{filecontents}
\begin{filecontents}{\water.bib}
@BOOK{Human:1,
  title = {{R}ocket {P}ropulsion {E}lements},
  publisher = {John Wiley Sons},
  author = Name J.~E.},
  year = {2017},
  edition = {4th},
}

@ARTICLE{Person:2,
  author = {Jones, A.~B. and Smith, J.~M.},
  title = {{A}rticle {T}itle},
  journal = {{J}ournal {T}itle},
  year = {2013},
  volume = {13},
  pages = {123-456},
  number = {52},
  month = {March},
  publisher = {Publisher}
  }
\end{filecontents}

编辑:这是错误:

(c:/texlive/2018/texmf-dist/tex/latex/hyperref/nameref.sty
(c:/texlive/2018/texmf-dist/tex/generic/oberdiek/gettitlestring.sty))
(./main.out) (./main.out)
(c:/texlive/2018/texmf-dist/tex/latex/amsfonts/umsa.fd)
(c:/texlive/2018/texmf-dist/tex/latex/amsfonts/umsb.fd) [1{c:/texlive    /2018/texm
f-var/fonts/map/pdftex/updmap/pdftex.map} <./images/latex.png>]
Runaway argument?
]{NAME:1} 
! Paragraph ended before \@citex was complete.
<to be read again> 
               \par 
l.74 

答案1

你在这里混淆了两件事。

第一:零件

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib} % <===========================================
@BOOK{Human:1,
  title = {{R}ocket {P}ropulsion {E}lements},
  publisher = {John Wiley Sons},
  author = Name J.~E.},
  year = {2017},
  edition = {4th},
}

@ARTICLE{Person:2,
  author = {Jones, A.~B. and Smith, J.~M.},
  title = {{A}rticle {T}itle},
  journal = {{J}ournal {T}itle},
  year = {2013},
  volume = {13},
  pages = {123-456},
  number = {52},
  month = {March},
  publisher = {Publisher}
  }
\end{filecontents}

仅用于构建可编译的 MWE,包括 TeX 代码和bib文件。假设您有文件,mwe.tex则将\jobname.bib其更改为mwe.bib可从 MWE 访问。

通常您有一个mybib.bib可以发送给您的代码的文件(如果它在同一个目录中),\bibliography{mybib}请注意省略扩展名.bib

因此,对于你的情况,只需使用

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{Human:1,
  title = {{R}ocket {P}ropulsion {E}lements},
  publisher = {John Wiley Sons},
  author = Name J.~E.},
  year = {2017},
  edition = {4th},
}

@ARTICLE{Person:2,
  author = {Jones, A.~B. and Smith, J.~M.},
  title = {{A}rticle {T}itle},
  journal = {{J}ournal {T}itle},
  year = {2013},
  volume = {13},
  pages = {123-456},
  number = {52},
  month = {March},
  publisher = {Publisher}
  }
\end{filecontents}


\documentclass[11pt,a4paper,oneside]{article}

\usepackage{natbib}
\usepackage{url}
\usepackage[utf8x]{inputenc}
\usepackage{siunitx}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{listings}
\usepackage{color}

\usepackage{graphicx}
\graphicspath{{images/}}

\usepackage{parskip}
\usepackage{cite}
\usepackage{fancyhdr}
\usepackage{vmargin}
\setmarginsrb{3 cm}{2.5 cm}{3 cm}{2.5 cm}{1 cm}{1.5 cm}{1 cm}{1.5 cm}

\usepackage[colorlinks]{hyperref} % <===============================================


\title{Life is too short to learn LaTeX}    % Title
\author{Rageful}    % Author
\date{01.01.2019} % Date

\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\let\thedate\@date
\makeatother

\pagestyle{fancy}
\fancyhf{}
\rhead{\theauthor}
\lhead{\thetitle}
\cfoot{\thepage}


\renewcommand{\refname}{Referance}

\begin{document}

\begin{titlepage}
   \centering
\vspace*{0.5 cm}
\includegraphics[scale = 0.08]{latex.png}\\[1.0 cm] 
{\centering \textsc{\LARGE \ \ \ \ \ \ \ \ \ LATEX} \newline\newline \textsc{\LARGE PROJECT}\\[2.0 cm]} 
\textsc{\Large 17.01.2019}\\[0.5 cm]    
\rule{\linewidth}{0.2 mm} \\[0.4 cm]
{ \huge \bfseries \thetitle}\\
\rule{\linewidth}{0.2 mm} \\[3.5 cm]

\begin{minipage}{0.5\textwidth}
    \begin{flushleft} \large
        \emph{Person A}\\
        \end{flushleft}
        \end{minipage}~
        \begin{minipage}{0.4\textwidth}

        \begin{flushright} \large
        \emph{Person B :} \\
    \end{flushright}
\end{minipage}\\[2 cm]
\end{titlepage}

\section{Preface}

Why is LaTeX too hard? \cite{NAME:1}

\newpage

\bibliographystyle{unsrt}
\bibliography{\jobname} % bibliography prints here

\end{document}

向 MWE 展示您的问题。

第二:实际使用时

文件mybib.bib

@BOOK{Human:1,
  title = {{R}ocket {P}ropulsion {E}lements},
  publisher = {John Wiley Sons},
  author = Name J.~E.},
  year = {2017},
  edition = {4th},
}

@ARTICLE{Person:2,
  author = {Jones, A.~B. and Smith, J.~M.},
  title = {{A}rticle {T}itle},
  journal = {{J}ournal {T}itle},
  year = {2013},
  volume = {13},
  pages = {123-456},
  number = {52},
  month = {March},
  publisher = {Publisher}
  }

以及生产性的 tex 代码,例如test.tex (参见\bibliography{mybib}最后的命令):

\documentclass[11pt,a4paper,oneside]{article}

\usepackage{natbib}
\usepackage{url}
\usepackage[utf8x]{inputenc}
\usepackage{siunitx}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{listings}
\usepackage{color}

\usepackage{graphicx}
\graphicspath{{images/}}

\usepackage{parskip}
\usepackage{cite}
\usepackage{fancyhdr}
\usepackage{vmargin}
\setmarginsrb{3 cm}{2.5 cm}{3 cm}{2.5 cm}{1 cm}{1.5 cm}{1 cm}{1.5 cm}

\usepackage[colorlinks]{hyperref} % <===============================================


\title{Life is too short to learn LaTeX}    % Title
\author{Rageful}    % Author
\date{01.01.2019} % Date

\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\let\thedate\@date
\makeatother

\pagestyle{fancy}
\fancyhf{}
\rhead{\theauthor}
\lhead{\thetitle}
\cfoot{\thepage}


\renewcommand{\refname}{Referance}

\begin{document}

\begin{titlepage}
   \centering
\vspace*{0.5 cm}
\includegraphics[scale = 0.08]{latex.png}\\[1.0 cm] 
{\centering \textsc{\LARGE \ \ \ \ \ \ \ \ \ LATEX} \newline\newline \textsc{\LARGE PROJECT}\\[2.0 cm]} 
\textsc{\Large 17.01.2019}\\[0.5 cm]    
\rule{\linewidth}{0.2 mm} \\[0.4 cm]
{ \huge \bfseries \thetitle}\\
\rule{\linewidth}{0.2 mm} \\[3.5 cm]

\begin{minipage}{0.5\textwidth}
    \begin{flushleft} \large
        \emph{Person A}\\
        \end{flushleft}
        \end{minipage}~
        \begin{minipage}{0.4\textwidth}

        \begin{flushright} \large
        \emph{Person B :} \\
    \end{flushright}
\end{minipage}\\[2 cm]
\end{titlepage}

\section{Preface}

Why is LaTeX too hard? \cite{NAME:1}

\newpage

\bibliographystyle{unsrt}
\bibliography{mybib} % bibliography prints here <====================

\end{document}

请注意,我改变了调用的顺序hyperref:在你的情况下应该最后调用,并且不要调用包两次(我删除了hyperref上面代码中的第二次调用)...

更新:

现在让我们看一下您给出的代码。也存在一些问题:

  • 您调用了包,导致了您提到的错误。请在终端/控制台上键入 ,cite然后阅读 的文档。如果您想使用包,则需要删除 的调用(您不能同时使用两者)并使用。citetexdoc citecitenatbib\bibliographystyle{unsrt}

  • 如果您想要使用natbib(请在控制台/终端上阅读文档texdoc natbib),则需要删除 的调用cite并将使用的书目样式更改为\bibliographystyle{unsrtnat}。要获取编号的书目条目,请将选项添加numbersnatbib\usepackage[numbers]{natbib}。对于以下 MWE,我选择了此变体...

  • 您的 bib 条目中 Human:1缺少{作者:

    @BOOK{Human:1,
      title = {{R}ocket {P}ropulsion {E}lements},
      publisher = {John Wiley Sons},
      author = {Name J.~E.},
      year = {2017},
      edition = {4th},
    }
    
  • 在您的 bib 文件中,没有NAME:1您在 tex 代码中调用的 bib 条目。我将其更改为Human:1

现在请看以下可编译代码

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{Human:1,
  title = {{R}ocket {P}ropulsion {E}lements},
  publisher = {John Wiley Sons},
  author = {Name J.~E.},
  year = {2017},
  edition = {4th},
}

@ARTICLE{Person:2,
  author = {Jones, A.~B. and Smith, J.~M.},
  title = {{A}rticle {T}itle},
  journal = {{J}ournal {T}itle},
  year = {2013},
  volume = {13},
  pages = {123--456},
  number = {52},
  month = {March},
  publisher = {Publisher},
  }
\end{filecontents}


\documentclass[11pt,a4paper]{article}

\usepackage[numbers]{natbib} % <===================================
\usepackage{url}
\usepackage[utf8x]{inputenc}
\usepackage{siunitx}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\usepackage{caption}
%\usepackage{pgfplots} % <========================= not needed for issue
\usepackage{listings}
\usepackage{color}

\usepackage{graphicx}
\graphicspath{{images/}}

\usepackage{parskip}

\usepackage{fancyhdr}
\usepackage{vmargin}
\setmarginsrb{3 cm}{2.5 cm}{3 cm}{2.5 cm}{1 cm}{1.5 cm}{1 cm}{1.5 cm}

\usepackage[colorlinks]{hyperref} % <===============================================


\title{Life is too short to learn LaTeX}    % Title
\author{Rageful}    % Author
\date{01.01.2019} % Date

\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\let\thedate\@date
\makeatother

\pagestyle{fancy}
\fancyhf{}
\rhead{\theauthor}
\lhead{\thetitle}
\cfoot{\thepage}


\renewcommand{\refname}{Referance}

\begin{document}

\begin{titlepage}
   \centering
\vspace*{0.5 cm}
\includegraphics[scale = 0.08]{example-image}\\[1.0 cm] 
{\centering \textsc{\LARGE \ \ \ \ \ \ \ \ \ LATEX} \newline\newline \textsc{\LARGE PROJECT}\\[2.0 cm]} 
\textsc{\Large 17.01.2019}\\[0.5 cm]    
\rule{\linewidth}{0.2 mm} \\[0.4 cm]
{ \huge \bfseries \thetitle}\\
\rule{\linewidth}{0.2 mm} \\[3.5 cm]

\begin{minipage}{0.5\textwidth}
    \begin{flushleft} \large
        \emph{Person A}\\
        \end{flushleft}
        \end{minipage}~
        \begin{minipage}{0.4\textwidth}

        \begin{flushright} \large
        \emph{Person B :} \\
    \end{flushright}
\end{minipage}\\[2 cm]
\end{titlepage}

\section{Preface}

Why is LaTeX too hard? \cite{Human:1}

\newpage

\bibliographystyle{unsrtnat} % <==================================
\bibliography{\jobname} % bibliography prints here

\end{document}

以及生成的pdf:

在此处输入图片描述

最后要说的是:你用来\ \ \ \ \ \ \ \ \构建标题页的 used 是错误的。最好\vspace{3cm}根据需要使用和更改 used 值...

答案2

你需要跑

乳胶 bibtex 乳胶 乳胶

Overleaf 会帮你完成这些。在 Texworks 中,你需要手动完成。在用于编译的绿色按钮旁边,你可以选择要运行的内容 :)

相关内容