Author-year natbib apalike and [1], [2], [3] like numbering in the references

natbibnumbering

My dear latex-community friends. I was just curious to know if it is at all possible to get serial numbering in the list of references when I am using an apalike style bibliography. My references are working fine, though. Thank you!

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[default,light,semibold]{sourceserifpro}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{babel}
\usepackage[authoryear]{natbib}
\usepackage{hyperref}
\usepackage{subfigure}
\usepackage{amscd}
\usepackage{tabularx}
\usepackage{graphicx}
\usepackage{epsfig}
\usepackage{titlesec}
\usepackage{a4,amsfonts,latexsym,amscd,amsopn,amssymb,amsmath, amsthm,bbm,stmaryrd,wasysym,mathbbol}
\usepackage{amstext}
\usepackage{verbatim}
\usepackage{catchfile}
\usepackage{autobreak}
\linespread{1.5}
\usepackage[ruled, noend, noline]{algorithm2e}
\usepackage[a4paper]{geometry}
\setlength{\topskip}{10mm}
\usepackage{comment}
\usepackage{lscape} 
\usepackage{titling}
\usepackage{blindtext}
\usepackage{lipsum}
\usepackage{microtype} 
\usepackage{xspace}
\usepackage[inactive]{srcltx}           
\usepackage{relsize}
\usepackage{booktabs} 
\usepackage{mathrsfs} 

\usepackage{placeins}
\usepackage[font=small,skip=0pt]{caption}
\usepackage{multirow}
\usepackage{xspace}
\usepackage[scale=.95,type1]{cabin}
\usepackage[cochineal,bigdelims,cmintegrals,vvarbb]{newtxmath}
\usepackage[zerostyle=c,scaled=.94]{newtxtt}
\usepackage{subfigure}
\usepackage{xcolor}
\usepackage{color}

\usepackage{acronym}
\usepackage{fullpage}
\usepackage[normalem]{ulem} 
\usepackage{makeidx}
\usepackage{wrapfig}
\usepackage{fancyhdr}
\usepackage{algpseudocode}
\usepackage{pifont}
\usepackage{calrsfs}

\newtheorem{theorem}{Theorem}
\theoremstyle{definition}
\newtheorem{definition}{Definition}
\newtheorem{assumption}{Assumption}
\newtheorem{remark}{Remark}
\newtheorem{proposition}{Proposition}
\newtheorem{lemma}{Lemma}
\newtheorem{example}{Example}
\textheight 235.0mm
\textwidth 155.0mm
\topmargin -15.0mm
\oddsidemargin 2.0mm
\footskip 15.0mm
\setlength{\parskip}{0mm}
\raggedbottom
\setlength\abovedisplayskip{2pt}
\setlength\belowdisplayskip{2pt}
\setlength{\parindent}{0em}
\setlength{\parskip}{0.5em}
\parindent0mm


\setlength{\headheight}{14pt}

\newcounter{mybibcounter}
\let\oldbibitem\bibitem
\RenewDocumentCommand{\bibitem}{om}{\oldbibitem[#1]{#2} \refstepcounter{mybibcounter}\themybibcounter. }


\newcommand{\inte}[1]{%
  {\kern0pt#1}^{\mathrm{o}}%
}
\newcommand\myatop[2]{\genfrac{}{}{0pt}{}{#1\hfill}{#2\hfill}}
\definecolor{myblue}{RGB}{0, 128, 128}
\renewcommand*{\acsfont}[1]{\textcolor{myblue}{#1}}
\hypersetup{colorlinks=true,linkcolor=myblue,urlcolor=myblue,citecolor=myblue,}
\newcommand{\eqnumcolor}{\color{myblue}}
\def\tagform@#1{\maketag@@@{\color{myblue}(#1)}}

\def\upmodels{\perp\!\!\!\perp}
    
    \bibliographystyle{apalike}
    \nocite{*}
    \bibliography{ref}
    \end{document}

Best Answer

You could try redefining the \bibitem command so that it does what the old one does, but also increases a counter, something like this (at the end of the preamble):

\newcounter{mybibcounter}
\let\oldbibitem\bibitem
\RenewDocumentCommand{\bibitem}{om}{\oldbibitem[#1]{#2} \refstepcounter{mybibcounter}\themybibcounter. }

It's hard to know if that will work properly without access to your complete document and bib file, however.

Unrelated suggestions: (1) you're loading multiple packages more than once (mathrsfs, caption with different options, setspace is loaded three different times!); you should clean out the duplicate entries, (2) you shouldn't load the cite package if you're also using natbib; natbib does everything cite does and more, and using it may cause conflicts; (3) the hyperref package should be loaded after other packages, so move it later in your preamble.