[Tex/LaTex] Citation in parentheses (author outside of it)

citingnatbib

I am using the bibliographystle 'apalike' and I want to change the citation output. Given a citation

\cite[p.1]{citekey}

which til now gives "(author, year, p.1)" , I want to have something like "author (year, p.1)". This can be done by

\citeauthor{citekey} (\citeyear{citekey}, p.3)

However, there must be a better way.

Best Answer

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@book{citekey,
    address = {Nowhere land},
    author = {Nowhere Man},
    publisher = {University of Void Press},
    title = {On the Nothing of Nothingness},
    year = {9999}
}
\end{filecontents*}

\newif\ifnatbib
\natbibtrue

\documentclass{article}

\ifnatbib
  \usepackage{natbib}
\else
  \usepackage[style=numeric,backend=bibtex]{biblatex}
  \addbibresource{\jobname.bib}
\fi

\makeatletter
\providecommand\citet[2][]{%
  \edef\@tempa{#1}
  \citeauthor{#2} (%
    \citeyear{#2}%
    \ifx\@empty\@tempa\else,~#1\fi
  )
}
\makeatother

\begin{document}
As first example citation here is \cite[p.1]{citekey}. 
Here is another example citation \citet[p.1]{citekey}.

\ifnatbib
  \bibliographystyle{apalike}
  \bibliography{\jobname}
\else
  \printbibliography
\fi
\end{document}

output_crop

Related Question