[Tex/LaTex] Formatting multiple references containing the same author

bibliographiesnatbib

I'm using natbib with a custom bibliography style and so would rather not change away from natbib if I can help it. I have one author with two citations and I just want the References section to list both citations properly under the one author. I cannot figure out how to do this as currently the output treats each citation as belonging to a different author (as a different entry). I have not provided a MWE as it does not seem necessary in this case but I can if need be.

\documentclass{article}
\usepackage{natbib}
\bibliographystyle{plainnat} 
\begin{document}
Here is text \citep[p.1]{authorA}.  And then more from same author \citep[p.1]{authorB}
\clearpage
\bibliography{bib}{}
\end{document}

And the bib file:

@book{authorA,
author={Smith, John},
title={Book},
}
@book{authorB,
author={Smith, John},
title={Other Book},
}

I would like the "References" section at the end of the article to look something like this:

Smith, John. Book
------Other Book

Instead of like this:

Smith, John. Book

Smith, John. Other Book

Best Answer

Note that the formatting of the bibliographic entries in the References section isn't actually governed by natbib; natbib is mainly a citation management system that can handle various numeric and authoryear citation styles. The formatting of the bib entries -- including the replacement of a repeated author (or authors) by a long dash -- is determined by the bibliography style you specify.

You mention in the first paragraph of your question that you use a custom bibliography style. However, in the MWE you state that you use the bibliography style plainnat. The following code assumes you're working with plainnat and shows how the file plainnat.bst may be modified to achieve your typesetting objectives. Hopefully, the bibliography style you're actually working with isn't too different from plainnat.

  1. Start by creating a copy of plainnat.bst; save the copy as, say, myplainnat.bst. (Never edit the original files.)

  2. Open the file myplainnat.bst with your favorite text editor.

  3. Locate the function article. (This function starts on lin 699 in my copy of plainnat.) Immediately before this function, insert the following lines of code:

    STRINGS {oldname}
    
    FUNCTION {name.or.dash}
    { 's :=
       oldname empty$
         { s 'oldname := s }
         { s oldname =
             { "---{}---{}---" }
             { s 'oldname := s }
            if$
         }
       if$
    }
    

    You didn't specify how long the dashes that replace the author's name (or authors' names) should be. In the code above, I use three consecutive em-dashes. Feel free to change this setup to suit your typographic needs and preferences.

  4. Next, locate each of the ten [10!] instances of the following line of code in myplainnat.bst:

      author format.key output
    

    and insert the instruction

      name.or.dash
    

    on a line by itself immediately following each of the author format.key output lines.

  5. Locate the two instances of the following five lines of code, in the functions book and inbook:

    { format.editors "author and editor" output.check
       editor format.key output
    }
    { format.authors output.nonnull
      crossref missing$
    

    and replace them with

    { format.editors "author and editor" output.check
      editor format.key output
      name.or.dash
     }
    { format.authors output.nonnull
      name.or.dash
      crossref missing$
    

    I.e., insert the instruction name.or.dash as indicated in each of two instances.

  6. In the function proceedings, locate the line

    editor format.key output
    

    and insert the line

    name.or.dash
    

    immediately following that line.

    If you've made all of these edits, you should have sixteen [16] instances of the string "name.or.dash" in your .bst file.

  7. Save the file myplainnat.bst either in the directory that contains your main .tex file or in a directory that's in the search path of your TeX distribution.

  8. Be sure to use the instruction \bibliographystyle{myplainnat} from now on.

Happy TeXing!

Related Question