7

The reason why I need this modification is that I want to have a general 'Bibliography' section in which all the bibliographies created with multibib are included. At the moment my code (narrowed down to a minimal working example) looks like this:

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
  @BOOK{Doe2013,
  title = {The concept of anonymity},
  author = {Doe, John},
  publisher = {Void},
  year = {2013}
  }
\end{filecontents*}

\documentclass{article}
\usepackage{multibib}
\newcites{ads}{Advertisments}

\begin{document}
\tableofcontents
\nocite{Doe2013}
\nociteads{Doe2014}
\clearpage
\section*{Bibliography}
\bibliographystyleads{plain}
\bibliographyads{ads}
\renewcommand{\refname}{Books and Articles}
\bibliographystyle{plain}
\bibliography{\jobname}
\end{document}

This (obviously) will create three sections in the end, which is not what I intended for I wish to have one section ("References") with two subsections ("Advertisements" and "Books and Articles"). How can I obtain that the \bibliography'ish macros call \subsection* instead of \section*?

Addendum

Here is a sample ads.bib:

@BOOK{Doe2014,
  title = {The concept of anonymity 2},
  author = {Doe, John},
  publisher = {Void},
  year = {2014}
  }

Edit

I forgot to mention that I want the bibliographies both automatically added to the TOC.

3

Add this to your example preamble:

\usepackage{etoolbox}

\ifdefined\chapter
  \newcommand{\refname}{References}
  \patchcmd{\thebibliography}{\chapter*{\bibname}}{%
    \section*{\refname}
    \addcontentsline{toc}{section}{\refname}
    }{}{}
  \newcommand{\bibliographies}{%
    \chapter*{\bibname}
    \addcontentsline{toc}{chapter}{\bibname}
  }
\else
  \newcommand{\bibname}{Bibliography}
  \patchcmd{\thebibliography}{\section*{\refname}}{%
    \subsection*{\refname}
    \addcontentsline{toc}{subsection}{\refname}
    }{}{}
  \newcommand{\bibliographies}{%
    \section*{\bibname}
    \addcontentsline{toc}{section}{\bibname}
  }
\fi

and \bibliographies (which is defined in my code snippet) right before the bibliographies start.

As you can see I expanded the functionality to classes with \chapters.

Edit

You can't use the above solution with natbib because it redefines the thebibliography environment so that the etoolbox patch won't be able to find what he is looking for. This code should do the job:

\usepackage{etoolbox}

\makeatletter
\providecommand{\bibname}{Bibliography}
\providecommand{\refname}{References}
\@ifpackageloaded{natbib}
  {\renewcommand{\bibsection}{%
    \@ifundefined{chapter}
    {\subsection*{\refname \markboth{\refname}{\bibname}%
    \addcontentsline{toc}{subsection}{\refname}}
    }
    {\section*{\refname \markboth{\refname}{\bibname}%
    \addcontentsline{toc}{section}{\refname}}
    }
  }}
  {\@ifundefined{chapter}
    {\patchcmd{\thebibliography}{\section*{\refname}}{%
      \subsection*{\refname}
      \addcontentsline{toc}{subsection}{\refname}
      }{}{}
    }
    {\patchcmd{\thebibliography}{\chapter*{\bibname}}{%
      \section*{\refname}
      \addcontentsline{toc}{section}{\refname}
      }{}{}
    }
  }
\@ifundefined{chapter}
  {\newcommand{\bibliographies}{%
  \section*{\bibname}
  \if@FMB@addtotoc\addcontentsline{toc}{section}{\bibname}\fi}}
  {\newcommand{\bibliographies}{%
  \chapter*{\bibname}
  \if@FMB@addtotoc\addcontentsline{toc}{chapter}{\bibname}\fi}}
\makeatother
  • 1
    Little additional request: What if I want to use this with natbib? (LaTeX yields some error messages if I add it...) – Krb Nov 30 '13 at 0:26
4

Here an alternativ suggestion:

load the package tocbibind and redefine section local:

\bgroup
\let\section\subsection
\bibliographystyleads{plain}
\bibliographyads{ads}
\renewcommand{\refname}{Books and Articles}
\bibliographystyle{plain}
\bibliography{\jobname}
\egroup

Here the complete code:

% arara: pdflatex
% arara: bibtex
% arara: bibtex: {  files:[ads.aux] }
% arara: pdflatex
% arara: pdflatex
\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
  @BOOK{Doe2013,
  title = {The concept of anonymity},
  author = {Doe, John},
  publisher = {Void},
  year = {2013}
  }
\end{filecontents*}
\begin{filecontents*}{ads.bib}
@BOOK{Doe2014,
  title = {The concept of anonymity 2},
  author = {Doe, John},
  publisher = {Void},
  year = {2014}
  }
\end{filecontents*}

\documentclass{article}
\usepackage[]{tocbibind}
\usepackage{multibib}
\newcites{ads}{Advertisments}

\begin{document}
\tableofcontents
\nocite{Doe2013}
\nociteads{Doe2014}
\clearpage
\section*{Bibliography}
\bgroup
\let\section\subsection
\bibliographystyleads{plain}
\bibliographyads{ads}
\renewcommand{\refname}{Books and Articles}
\bibliographystyle{plain}
\bibliography{\jobname}
\egroup
\end{document}
  • \let\section\subsection alone did the trick for me – Tom Mar 12 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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