Thursday, August 20, 2009

Chapterbib and Float with Latex

Writing my thesis I had some trouble finding out how to allow separate bibliography and figure/tables lists per chapter, so at the end of each chapter I would show only the list of references and figures from that chapter, not the whole thesis.
My thesis is quite large, and consequently a unique bibliography would be uncomfortable.

In case it could help, here is the code:

%%%%Main File%%%%%%
\usepackage[sectionbib]{chapterbib}
\usepackage{float}
\newfloat{figurechapter1}{htpb}{a}[chapter] %creates a new float named figurechapter1
\floatname{figurechapter1}{Figure} %Sets the name of the float when shown by a caption command.
\newfloat{figurechapter2}{htpb}{b}[chapter]
\floatname{figurechapter2}{Figure} %the same for chapter2
\begin{document}
\include{Chapter1}
\include{Chapter2}
\end{document}

%%%Example Chapter1%%%%
\chapter{This is the chapter 1}
\begin{figurechapter1} %example of figure
\includegraphics{..}{..} %as usual
\caption{..} %as usual
\end{figurechapter1} %the same for tables

\addcontentsline{toc}{section}{Bibliography} %Bibliography to toc
\bibliography{Bibliography/Chapter1} %adding the bibliography
\addcontentsline{toc}{section}{List of Figures} %List of figures to toc
\listof{figurechapter1}{This is Chapter1 List of Figures} %adding list of figures

%%%Howto Compile:%%%%%%%
latex Main.tex (this will show warning, don't panic >.<)
bibtex Chapter1
bibtex Chapter2
latex Main.tex (2 times)

%%Note I have my .bib files in a folder named Bibliography, like this:
MyThesis/Main.tex
MyThesis/Chapter1.tex
MyThesis/Chapter2.tex
MyThesis/Bibliography/Chapter1.bib
MyThesis/Bibliography/Chapter2.bib

1 comment:

  1. Edit: if you get an error like "chapterbib.sty not found" use (under debian/ubuntu):
    #sudo aptitude install --without-recommends texlive-latex-extra texlive-latex-recommended texlive-fonts-recommended

    ReplyDelete