Search code examples
latextexbibtexbiblatex

Citation not getting displayed - instead the alias is getting displayed in the pdf


I am trying to use \cite to cite items from bibliography.bib. However, my citations are not working properly.

The environment, code and output are as below:

\documentclass[12pt]{article}

\usepackage{amssymb,amsmath,amsfonts,eurosym,geometry,ulem,graphicx,caption,color,setspace,sectsty,comment,footmisc,caption,pdflscape,subfigure,array,hyperref,booktabs,dcolumn,threeparttable, adjustbox,apacite,dirtytalk,multirow,tabularx,booktabs,longtable,lscape,placeins,tikz}

\usepackage[backend=biber,natlib,style=author-year,citestyle=authoryear]{biblatex}

\usepackage{ulem}

\usepackage{float}
\restylefloat{table}

\usepackage{pgfplots}
\pgfplotsset{width=12cm,compat=1.9}
\usepackage{pst-func}
\psset{unit=2cm}
\usepackage{hyperref}
\hypersetup{colorlinks=true,urlcolor=blue,citecolor=blue,linkcolor=red}
\usepackage[center]{caption}
\usepackage{setspace}
\usepackage{epsfig}
\usepackage{graphics}
\usepackage{lscape}
\usepackage[english]{babel}
\usepackage{color}

\addbibresource{bibfile.bib}

\begin{document}

This is a \cite{sample}.

\end{document}

The cite takes reference from my .bib file, which is in the same folder. Here I have attached a sample citation.

@article{sample,
  title={What is the price elasticity of housing demand?},
  author={Hanushek, Eric A and Quigley, John M},
  journal={The Review of Economics and Statistics},
  pages={449--454},
  year={1980},
  publisher={JSTOR}
}

The output that I am getting looks like

Author Year with year linking to the bibliography section. However, I want it like Author, Year with the entire phrase linking to the bibliography section

Could you please help me with this issue?

Thank You :)

P.S. : I know my environment is not perfect. It has some packages repeated twice. :)


Solution

  • NEVER IGNORE ERROR MESSAGES! After an error, latex only recovers enough to syntax check the rest of the document. There is no point at even looking at what might or might not be valid output while there are still errors!

    There are several major problems:

    • don't load packages multiple times and in particular don't load them multiple times with different options. An error message in the log file will explicitly tell you about the option clash

    • don't load incompatible package like apacite and biblatex in the same document. An error message in the log file with explicitly tell you that these two packages are not compatible

    • the biblatex option is called natbib, not natlib. An error message will explicitly tell you that it does not know the option natlib

    • the biblatex style is called authoryear, not author-year. An explicit error message will tell you that author-year style is not found

    ... and then there are many other duplicate, unnecessary or obsolete packages. You should clean up your preamble and only load the packages you need. Also hyperref should be loaded after the other packages.

    \documentclass[12pt]{article}
    
    \usepackage{amssymb,amsmath,amsfonts,eurosym,geometry,ulem,graphicx,caption,color,setspace,sectsty,comment,footmisc,caption,pdflscape,subfigure,array,
    %hyperref,
    booktabs,dcolumn,threeparttable, adjustbox,
    %apacite,
    dirtytalk,multirow,tabularx,booktabs,longtable,
    %lscape,
    placeins,tikz}
    
    \usepackage[backend=biber,natbib,style=authoryear,citestyle=authoryear]{biblatex}
    
    %\usepackage{ulem}
    
    \usepackage{float}
    \restylefloat{table}
    
    \usepackage{pgfplots}
    \pgfplotsset{width=12cm,compat=1.9}
    \usepackage{pst-func}
    \psset{unit=2cm}
    %\usepackage{hyperref}
    
    %\usepackage[center]{caption}
    %\usepackage{setspace}
    %\usepackage{epsfig}
    %\usepackage{graphics}
    %\usepackage{lscape}
    \usepackage[english]{babel}
    %\usepackage{color}
    
    \usepackage{hyperref}
    \hypersetup{colorlinks=true,urlcolor=blue,citecolor=blue,linkcolor=red}
    
    \begin{filecontents*}[overwrite]{\jobname.bib}
    @article{sample,
      title={What is the price elasticity of housing demand?},
      author={Hanushek, Eric A and Quigley, John M},
      journal={The Review of Economics and Statistics},
      pages={449--454},
      year={1980},
      publisher={JSTOR}
    }
    \end{filecontents*}
    
    \addbibresource{\jobname.bib}
    
    \begin{document}
    
    This is a \cite{sample}.
    
    \end{document}