6

I followed Natbib reference sheet and \citet works as expected. I would like the author's name to appear in small caps, how can I do that?

I guess I should do:

Define \citenumfont to be a font declaration or command like \itshape or [...] \textit.

but I have no idea what it means.

Before you upvote lockstep's answer: it does not work, the authors name are not in small cap, the renewcommand has no effect. His example code does not compile as it is now.

UPDATE: Here is a minimum working example.

smallcap.tex

\documentclass[fleqn]{article}
\usepackage[numbers]{natbib}
\makeatletter
%\renewcommand*{\NAT@nmfmt}[1]{\textsc{#1}}
\def\NAT@nmfmt#1{\textsc{#1}}
\makeatother
\begin{document}
As mentioned in \citet{Biegler97}~\dots
\bibliographystyle{plainnat}
\bibliography{dummy}
\end{document}

dummy.bib

@BOOK{biegler97,
  AUTHOR = {Lorenz T. Biegler and Ignacio E. Grossmann and Arthur W. Westerberg},
  TITLE = {Systematic Methods of Chemical Process Design},
  YEAR = {1997},
  PUBLISHER = {Prentice Hall PTR, Upper Saddle River, NJ}
}
lockstep
  • 250,273
Ali
  • 883

3 Answers3

9

To cite authors in small caps, it is not necessary to create a new .bst file -- instead, redefine the \NAT@nmfmt macro which is responsible for formating the author's name. (See this answer for other areas of application for \NAT@nmfmt.)

\documentclass{article}

\usepackage{natbib}

\makeatletter
\renewcommand*{\NAT@nmfmt}[1]{\textsc{#1}}
\makeatother

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@article{Bli74,
  author = {Blinder, Alan S.},
  year = {1974},
  title = {The economics of brushing teeth},
  journal = {Journal of Political Economy},
  volume = {82},
  number = {4},
  pages = {887--891},
}
\end{filecontents}

\begin{document}

As mentioned in \citet[99]{Bli74}~\dots

\bibliographystyle{plainnat}
\bibliography{\jobname}

\end{document}

enter image description here

lockstep
  • 250,273
  • @AlanMunn: \citenumfont only works for numbers in numerical citations. – lockstep Dec 05 '11 at 17:07
  • 1
    Is it necessary to load the etoolbox package and use that package's \patchcmd macro? The command \def\NAT@nmfmt#1{{\textsc{#1}}} should work equally well, right (if embedded between \makeatletter and \makeatother, naturally)? – Mico Dec 05 '11 at 22:05
  • @Mico: Actually, it isn't. Stupid me. Answer corrected. – lockstep Dec 05 '11 at 22:20
  • @lockstep Please check your answer, it does not work, nothing happens to the author name, it is not in small cap. Your example code does not compile as it is now :( – Ali Dec 06 '11 at 09:34
  • @Ali: Works for me. – lockstep Dec 06 '11 at 17:21
  • This doesn't work if you load natbib with the numbers option, which (now that there's a minimal example) is what Ali is doing. @Ali You can see now the importance of posting minimal examples with your question. – Alan Munn Dec 06 '11 at 19:37
  • @lockstep As Alan says, it does not work because of the numbers option. – Ali Dec 06 '11 at 21:17
  • @AlanMunn Yes, I just did not expect this to be so difficult. I though there would be a 1 line answer. – Ali Dec 06 '11 at 21:18
  • 1
    @Ali: I can confirm this, and have already tried to find a solution. The natbib code internals are a real pain, though. Have you considered to switch to biblatex? – lockstep Dec 06 '11 at 21:19
  • @lockstep OK, thanks for your efforts. I have to collaborate with others using latex and natbib. If I switch to biblatex there will be compatibility issues, right? – Ali Dec 06 '11 at 21:28
  • @Ali: Right. :-( – lockstep Dec 06 '11 at 21:29
  • Thank oul, @lockstep. I, for one, can live with this solution :-). As one tiny improvement, could you add how to exclude "et al." from the capitalization? – Ingo Nov 03 '14 at 20:42
7

With the numbers option the patch is slightly more complicated:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\NAT@test}{\else\NAT@nm}{\else\NAT@nmfmt{\NAT@nm}}{}{}
\let\NAT@up\scshape
\makeatother

Apparently natbib's author forgot to apply \NAT@nmfmt in the relevant place of \NAT@test

In order to get et al. in roman type,

\usepackage{etoolbox,xstring}
\makeatletter
\patchcmd{\NAT@test}{\else\NAT@nm}{\else\NAT@nmfmt{\NAT@nm}}{}{}
\renewcommand{\NAT@nmfmt}{\expandafter\aliNAT@nmfmt\expandafter}
\newcommand\aliNAT@nmfmt[1]{{%
  \noexpandarg
  \def~{}%
  \edef\temp#1\edef\temp{\detokenize\expandafter{\temp}}%
  \begingroup\edef\x{\endgroup
    \noexpand\StrSubstitute{\temp}{\detokenize{etal}}}\x
    {\textnormal{et\nobreakspace al}}[\tempa]%
  \textsc{\tempa}}}
\makeatother
egreg
  • 1,121,712
  • Thanks. Unfortunately it turns et al. also in small cap but it shouldn't do so... :( See my example code. – Ali Dec 06 '11 at 12:54
  • +1 and thanks, it works. Is it really the simplest solution? I could not have figured that out myself. :( – Ali Dec 06 '11 at 21:23
  • @Ali I haven't figured out a simpler solution. Unfortunately, beside the already mentioned oversight, also et~al. is hard coded instead of being buried in a macro. :( – egreg Dec 06 '11 at 22:55
4

From p. 15 of the natbib manual:

Numerical citations may be printed in a different font. Define \citenumfont to be a font declaration like \itshape or even a command taking arguments like \textit. [The command] \renewcommand{\citenumfont}[1]{\textit{#1}} ... is better than \itshape since it automatically adds italic correction.

Hence, changing \citenumfont will not affect the font used by LaTeX for typesetting authors' names in either citations or the bibliography. For that, you need to create a bibliography style file (extension .bst), probably from scratch. Have a look at the file makebst.tex (created by the author of the natbib package, by the way). It can be run under either TeX or LaTeX; when you run it, it'll ask you a lot of questions (with predefined options for answers) about the desired bibliography style -- including some about special fonts for authors' names -- and then builds a .bst file with this information.

Addendum: As @lockstep notes in his answer and in a comment to my answer, if you only want to use small-caps for the names of authors/editors in citations, it is not strictly necessary to create a new .bst file: one could, instead, redefine the \NAT@nmfmt macro. However, you must still create a new .bst file if you want the names of authors and editors be typeset in small-caps in the bibliography section as well -- plus you'll have to remember to insert instructions such as

\makeatletter
\def\NAT@nmfmt#1{\textsc{#1}}
\makeatother

from now on in the preamble of every document you write that features this citation format. You might as well simply tell the makebst.tex program about this preference and be done with it once and for all, right?

Mico
  • 506,678
  • At least for formatting the author's name in citations, one doesn't need to create a .bst file -- see my answer. – lockstep Dec 05 '11 at 16:56
  • @lockstep -- good news that one doesn't have to created or modify a .bst file, though the alternative does require extra work as well. – Mico Dec 05 '11 at 17:16
  • @Mico +1 and thanks for the response! – Ali Dec 05 '11 at 21:30
  • @Mico Your last suggestion does not work :( I am already using similar \def-s in the preamble so another one is no problem. Could you check your last suggestion, please? – Ali Dec 06 '11 at 08:55
  • @Ali: Could you be a bit more specific about what "does not work"? I've added a pair of curly braces to the \def; please try the new code. – Mico Dec 06 '11 at 09:00
  • @Mico It still does not work. By "does not work" I mean it has no effect, the author names are not in small cap. – Ali Dec 06 '11 at 09:04
  • @Ali: Hmm, it works for me. :-) Could you recheck the code you use -- there are quite a few braces. – Mico Dec 06 '11 at 09:27
  • No it gives a compile error, the error is at \def{: ! Missing control sequence inserted. \inaccessible l.22 \def{ \NAT@nmfmt}[1]{\textsc{#1}} – Ali Dec 06 '11 at 09:31
  • @Ali: I've changed the (re)definition of \NAT@nmfmt slightly -- please try to rerun the code. Remember to run latex/bibtex/latex/latex on your main file. – Mico Dec 06 '11 at 10:39
  • @Mico Done. It still has no effect. I deleted everything except the my_file.tex and recompiled everything. Your redefiniton has no effect :( – Ali Dec 06 '11 at 10:50
  • @Ali: OK, you should really post a MWE (minimum working example) of your code that replicates the error/no effect you observe. There must be something in your setup that keeps interfering with the commands \makeatletter \def\NAT@nmfmt#1{\textsc{#1}} \makeatother. (You do execute this code after loading natbib, right?) – Mico Dec 06 '11 at 10:57
  • @Mico Done, please check my update. – Ali Dec 06 '11 at 11:39