%% Curriculum Vitae style file
%% Rob J Hyndman. Last updated 24 July 2013
%% This file may be modified, copied and redistributed without any further permission.
%% However, if you modify it, please add a note indicating it is a modification of the original.
%% The original file is available at http://robjhyndman.com/research/cv.sty

\usepackage{paralist,ragged2e,datetime}
\usepackage{fancyhdr,enumitem,color}
\usepackage[a4paper,text={17.5cm,25.5cm},centering]{geometry}
\usepackage[compact,small,sf,bf]{titlesec}
\usepackage{kpfonts,dsfont}

% CS
\usepackage[ocgcolorlinks,unicode,bookmarks]{hyperref}
\usepackage[usenames,dvipsnames]{xcolor}
\hypersetup{colorlinks=true,citecolor=NavyBlue,linkcolor=NavyBlue,urlcolor=NavyBlue}

\RaggedRight
\sloppy

% Header and footer
\pagestyle{fancy}
\lhead{\sf Curriculum Vitae: \@name}
\rhead{\sf\thepage}
\cfoot{}

% Date format
\newdateformat{rjh}{\monthname~\THEYEAR}
\rjh

% Header box
\def\name#1{\def\@name{#1}}
\def\info#1{\def\@info{#1}}
\newcommand{\shadebox}[3][.9]{\fcolorbox[gray]{0}{#1}{\parbox{#2}{#3}}}

\def\maketitle{
\thispagestyle{plain}
\vspace*{-1.4cm}
\shadebox[0.9]{17.3cm}{\sf\color[rgb]{0,0,0}
\hbox to 17cm{\begin{tabular}{p{7.4cm}}
\LARGE\textbf{\@name}\\[0.3cm]
\Large\textbf{Curriculum Vitae}\\[0.6cm]
\normalsize\today
\end{tabular}
\hfill\hbox{\fontsize{9}{12}\sf
\begin{tabular}{@{}rp{7.2cm}@{}}
\@info
\end{tabular}}}
}
\vspace*{0.2cm}}


% Section headings
\titlelabel{}
\titlespacing{\section}{0pt}{2ex}{1ex}
\titleformat*{\section}{\color[rgb]{0,0,0}\large\sf\bfseries}
\titlespacing{\subsection}{0pt}{1ex}{0.5ex}

% Miscellaneous dimensions
\setlength{\parskip}{0ex}
\setlength{\parindent}{0em}
\setlength{\headheight}{15pt}
\setlength{\tabcolsep}{0.15cm}
\clubpenalty = 10000
\widowpenalty = 10000
\setlist{itemsep=1pt}
\setdescription{labelwidth=1.2cm,leftmargin=1.5cm,labelindent=1.5cm,font=\rm}

% Bibliography formatting

\usepackage[sorting=ynt,bibstyle=authoryear-comp,defernumbers=true,maxnames=20,firstinits=true, uniquename=init,dashed=false,doi=false,isbn=false,backend=biber]{biblatex}

\DeclareNameAlias{sortname}{first-last}
\DeclareNameAlias{default}{first-last}


\DeclareFieldFormat{url}{\url{#1}}
\DeclareFieldFormat[article]{pages}{#1}
\DeclareFieldFormat[inproceedings]{pages}{\lowercase{pp.}#1}
\DeclareFieldFormat[incollection]{pages}{\lowercase{pp.}#1}
\DeclareFieldFormat[article]{volume}{\mkbibbold{#1}}
\DeclareFieldFormat[article]{number}{\mkbibparens{#1}}
\DeclareFieldFormat[article]{title}{\MakeCapital{#1}}
\DeclareFieldFormat[article]{url}{}
\DeclareFieldFormat[inproceedings]{title}{#1}
\DeclareFieldFormat{shorthandwidth}{#1}
\DeclareFieldFormat{extrayear}{}

% No dot before number of articles
\usepackage{xpatch}
\xpatchbibmacro{volume+number+eid}{\setunit*{\adddot}}{}{}{}

% Remove In: for an article.
\renewbibmacro{in:}{%
  \ifentrytype{article}{}{%
  \printtext{\bibstring{in}\intitlepunct}}}

% Bibliography categories
\def\makebibcategory#1#2{\DeclareBibliographyCategory{#1}\defbibheading{#1}{\section*{#2}}}
\makebibcategory{books}{Books}
\makebibcategory{papers}{Refereed research papers}
\makebibcategory{chapters}{Book chapters}
\makebibcategory{conferences}{Papers in conference proceedings}
\makebibcategory{techreports}{Unpublished working papers}
\makebibcategory{bookreviews}{Book reviews}
\makebibcategory{editorials}{Editorials}
\makebibcategory{phd}{PhD thesis}
\makebibcategory{subpapers}{Submitted papers}
\makebibcategory{curpapers}{Current projects}

\setlength{\bibitemsep}{2.5pt}
\setlength{\bibhang}{.8cm}
%\renewcommand{\bibfont}{\fontsize{12}{14}}

\renewcommand*{\bibitem}{\addtocounter{papers}{1}\item \mbox{}\hskip-0.85cm\hbox to 0.85cm{\hfill\arabic{papers}.~~}}
\defbibenvironment{bibliography}
{\list{}
  {\setlength{\leftmargin}{\bibhang}%
   \setlength{\itemsep}{\bibitemsep}%
   \setlength{\parsep}{\bibparsep}}}
{\endlist}
{\bibitem}

\newenvironment{publications}{\section{\LARGE Publications}\label{papersstart}\vspace*{0.2cm}
\titlespacing{\section}{0pt}{1.5ex}{1ex}\itemsep=0.00cm
}{\label{papersend}\addtocounter{sumpapers}{-1}\refstepcounter{sumpapers}\label{sumpapers}}

\def\printbib#1{\printbibliography[category=#1,heading=#1]\lastref{sumpapers}}
\renewcommand{\bibfont}{\normalfont\fontsize{11}{13.4}\rmfamily}
% Counters for keeping track of papers
\newcounter{papers}\setcounter{papers}{0}
\newcounter{sumpapers}\setcounter{sumpapers}{0}
\def\lastref#1{\addtocounter{#1}{\value{papers}}\setcounter{papers}{0}}

% Add all papers in the bib file.
\nocite{*}
