Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to use bibtex+natbib to deal with the citations in my thesis. Some citations are of the style \citet{author_year} and work as expected.

However, when I use \citet[pXX]{author_year}, then I get Author (Year, pXX) instead of the desired Author (Year), pXX

How can I achieve the desired style for this second kind of citations with additional information like page number etc.

Based on the first answer from @Audrey I made this MWE:

%this documents is compiled with xetex
\documentclass[11pt,british,english,ngerman,footnotes=multiple]{scrreprt}
\usepackage{fontspec}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=3cm,rmargin=3cm}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{array}
\usepackage{rotfloat}
\usepackage{booktabs}
\usepackage{footmisc}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage[authoryear]{natbib}
\PassOptionsToPackage{normalem}{ulem}
\usepackage{ulem}
\onehalfspacing

\usepackage{babel}
%\usepackage{hyperref}
\usepackage{apacite}
\usepackage{makerobust}
\DeclareRobustCommand{\citep}[2][]{\cite[#1]{#2}}
\DeclareRobustCommand{\citealp}[2][]{\citeNP[#1]{#2}}
\DeclareRobustCommand{\citet}[2][]{\citeA[#1]{#2}}

\usepackage{chngcntr}
\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}
\counterwithout{footnote}{chapter}

\bibpunct[, ]{(}{)}{,}{a}{,}{,}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\NAT@citex}
  {\ifNAT@swa\else\if*#2*\else\NAT@cmt#2\fi
   \if\relax\NAT@date\relax\else\NAT@@close\fi\fi}
  {\ifNAT@swa\else\if*#2*\else\ifNAT@par\else\NAT@cmt#2\fi\fi
   \if\relax\NAT@date\relax\else\NAT@@close%
   \if*#2*\else\ifNAT@par\NAT@cmt#2\fi\fi\fi\fi}{}{}
\makeatother

\begin{filecontents}{\jobname.bib}
@Book{companion,
  author = {Goossens, Michel and Mittelbach, Frank and Samarin, Alexander},
  title = {The LaTeX Companion},
  edition = {1},
  publisher = {Addison-Wesley},
  location = {Reading, Mass.},
  year = {1994}}
@Book{adams,
  title = {The Restaurant at the End of the Universe},
  author = {Douglas Adams},
  series = {The Hitchhiker's Guide to the Galaxy},
  publisher = {Pan Macmillan},
  year = {1980}}
\end{filecontents}

\begin{document}
\noindent
\cmd{citet}: \citet[e.g.][100]{adams}, \citet[pp. 1--10]{companion,adams} \\
\cmd{Citet}: \Citet[pp. 1--10]{adams}, \Citet[pp. 1--10]{companion} \\
\cmd{citet*}: \citet*[pp. 1--10]{companion,adams} \\
\cmd{Citet*}: \Citet*[p. 10]{companion} \\
\cmd{cite}: \cite[e.g.][100]{adams}, \cite{companion} \\
\cmd{citep}: \citep[e.g.][p. 20]{adams}, \citep[1--10]{companion,adams} \\
\cmd{citetext}, \cmd{citealp}:
\citetext{see \citealp{companion}, or even better \citealp{adams}} \\
\cmd{citeauthor}: \citeauthor{adams}, \citeauthor{companion} \\
\cmd{citeyear}: \citeyear{adams}, \citeyear{companion} \\
\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}

Does anyone understand how to tame the apacite beast in combination with natbib?

share|improve this question
4  
If you do not want the postnote inside the parentheses why don't you simply write \citet{author_year},~pXX? –  cgnieder Nov 1 '12 at 20:07
    
this is because I (regrettably) used LyX to produce the document. There was an option to feed an optional argument to the cite command. Now that this was done, I do not want to change 400 footnotes by hand to in the way you suggest. This would be very much against the style of using latex at all. –  juri Nov 1 '12 at 21:01
add comment

1 Answer

With etoolbox you can patch the command natbib uses to set all non-numeric citation labels: \NAT@citex. The postnote is passed to \NAT@citex as the second argument (#2). For \citet and its variants \ifNAT@swa will expand <false>, \ifNAT@par expands <true> and \NAT@date is defined.

\documentclass{article}
\usepackage{natbib}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\NAT@citex}
  {\ifNAT@swa\else\if*#2*\else\NAT@cmt#2\fi
   \if\relax\NAT@date\relax\else\NAT@@close\fi\fi}
  {\ifNAT@swa\else\if*#2*\else\ifNAT@par\else\NAT@cmt#2\fi\fi
   \if\relax\NAT@date\relax\else\NAT@@close%
   \if*#2*\else\ifNAT@par\NAT@cmt#2\fi\fi\fi\fi}{}{}
\makeatother

\begin{filecontents}{\jobname.bib}
@Book{companion,
  author = {Goossens, Michel and Mittelbach, Frank and Samarin, Alexander},
  title = {The LaTeX Companion},
  edition = {1},
  publisher = {Addison-Wesley},
  location = {Reading, Mass.},
  year = {1994}}
@Book{adams,
  title = {The Restaurant at the End of the Universe},
  author = {Douglas Adams},
  series = {The Hitchhiker's Guide to the Galaxy},
  publisher = {Pan Macmillan},
  year = {1980}}
\end{filecontents}

\newcommand{\cmd}[1]{\textbackslash\texttt{#1}}
\begin{document}
\noindent
\cmd{citet}: \citet[e.g.][100]{adams}, \citet[pp. 1--10]{companion,adams} \\
\cmd{Citet}: \Citet[pp. 1--10]{adams}, \Citet[pp. 1--10]{companion} \\
\cmd{citet*}: \citet*[pp. 1--10]{companion,adams} \\
\cmd{Citet*}: \Citet*[p. 10]{companion} \\
\cmd{cite}: \cite[e.g.][100]{adams}, \cite{companion} \\
\cmd{citep}: \citep[e.g.][p. 20]{adams}, \citep[1--10]{companion,adams} \\
\cmd{citetext}, \cmd{citealp}:
\citetext{see \citealp{companion}, or even better \citealp{adams}} \\
\cmd{citeauthor}: \citeauthor{adams}, \citeauthor{companion} \\
\cmd{citeyear}: \citeyear{adams}, \citeyear{companion} \\
\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}

enter image description here

share|improve this answer
    
many thanks for your input! that looks very complicated. I thought the 'bibpunc' command could do that. I will try the proposed solution tonight. –  juri Nov 2 '12 at 6:08
    
Unfortunately this does not work for me. Could it be because I use the 'apacite' package? The inserted citations remained unchanged after adding your code to the preamble. Can you help further? –  juri Nov 2 '12 at 22:06
    
Unfortunately this does not work for me. Could it be because I use the 'apacite' package? More specifically, this is what is loaded in the preamble: \documentclass[11pt,british,english,ngerman,footnotes=multiple]{scrreprt} \usepackage[authoryear]{natbib} \usepackage{apacite} \usepackage{makerobust} \DeclareRobustCommand{\citep}[2][]{\cite[#1]{#2}} \DeclareRobustCommand{\citealp}[2][]{\citeNP[#1]{#2}} \DeclareRobustCommand{\citet}[2][]{\citeA[#1]{#2}} The inserted citations remained unchanged after adding your code to the preamble. Can you help further? –  juri Nov 2 '12 at 22:14
1  
@juri Obviously, yes. The patch only applies to natbib. It has no effect on \citet defined with apacite. I could take a look at patching apacite, but you'll have to improve your MWE. It is neither minimal nor working. The existing patch will work with apacite if you conform to the recommended use with natbib commands in the manual: load only \usepackage[natbibapa]{apacite} and drop your definitions for \citet and friends. –  Audrey Nov 2 '12 at 23:19
    
thank you very much for offering more help, but it seems now that it is not needed: I could not make your tip work with apacite (the apacite package does not have the natbibapa option you recommend) and I returned to natbib with author-year style and then your tip works. I know nobody wants to read it here, but the bibliography is manually typeset anyway based on the broken+incomplete apacite bibliography. The reason, in short, is that way too many packages are incompatible with each other and a new user has to think carefully how many hours he can spend on finding these. –  juri Nov 3 '12 at 1:18
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.