1

Loved bookdown. However, I'm porting my book from LaTeX into bookdown, and would like some help with headers/footers.

I have a custom code that generates headers and footers in my LaTeX:

% HEADER AND FOOTER MANIPULATION
 % for normal pages
 \nouppercaseheads
 \headsep = 0.16in
 \makepagestyle{mystyle}
 \setlength{\headwidth}{\dimexpr\textwidth+\marginparsep+\marginparwidth\relax}
 \makerunningwidth{mystyle}{\headwidth}
 \makeevenhead{mystyle}{}{\textls[100]{\textsf{\small\scshape\thetitle}}}{}
 \makeoddhead{mystyle}{}{\textls[100]{\textsf{\small\scshape\leftmark}}}{}
 \makeevenfoot{mystyle}{}{\textls[100]{\textsf{\small\thepage}}}{}
 \makeoddfoot{mystyle}{}{\textls[100]{\textsf{\small\thepage}}}{}
 \clearmark{section} % removing section in the headers
 \makeatletter
 \makepsmarks{mystyle}{%
 \createmark{chapter}{left}{nonumber}{\@chapapp\ }{.\ }}
 \makeatother

 % for pages where chapters begin
 \makepagestyle{plain}
 \makerunningwidth{plain}{\headwidth}
 \makeevenfoot{plain}{}{}{}
 \makeoddfoot{plain}{}{}{}
 \pagestyle{mystyle}
% END HEADER AND FOOTER MANIPULATION

I placed my entire LaTeX preamble in preamble.tex (and I've not added content to the book just yet). It renders the following:

How bookdown renders the LaTeX

The render should actually look like this:

The actual LaTeX render

Also, here's what's in the YAML in index.Rmd.

documentclass: memoir
papersize: smalldemyvo
indent: yes
microtypeoptions:
  - protrusion
  - tracking
fontfamily: Alegreya
fontfamilyoptions:
  - osf
fontsize: 11pt
output:
  bookdown::pdf_book:
    template: null

I'm new to bookdown, but I did read the documentation. I feel I need help with two things.

  1. How do I remove the auto-generated headers and footers?
  2. How do I make "Contents" disappear from the ToC table?

Thank you!

1
  • 1
    I guess you might have to use not only the preamble.tex file but also a template.tex file. Maybe a before_body.tex file as well. See a demo.
    – pzhao
    Nov 3, 2017 at 8:51

2 Answers 2

1

By default, bookdown uses some built-in template(s). If you need more adjustments, you could make your own .tex files (preamble.tex, before_body.tex, after_body.tex, template.tex) and specify them in the yaml part of index.Rmd like this:

bookdown::pdf_book:
  includes:
    in_header: preamble.tex
    before_body: before_body.tex
    after_body: after_body.tex
template: template.tex

bookdown merges preamble.tex, before_body.tex, and after_body.tex with the main body (marked as $body$ in template.tex) of your book into one .tex file in the structure under the control of template.tex, and compile it into a pdf book with pandoc and LaTex.

In your case, you have to insert your custom code into template.tex in the right way. @yihui's demo shows a good example.

For more examples to customize these .tex files, I would suggest that you could either look into the 'bookdownplus' package I developed, which gives you 19 examples showing how to tailor a LaTeX template into bookdown's frame, or read Chapter 8.3 Create Your Own Templates in the bookdownplus textbook.

3
  • Ah, the TeX/LaTeX thing repeats! :) I'm marking this as the answer since the tutorial provides more information to users looking for it.
    – Ram Iyer
    Nov 11, 2017 at 10:19
  • Glad it helps. BTW, could you kindly change the citation of my nickname 'dapeng' as my real name 'pzhao'? I changed it in my profile and found the citation was not updated automatically. But it cannot be changed back in 30 days.
    – pzhao
    Nov 11, 2017 at 10:55
  • Done! It still doesn't link you, though.
    – Ram Iyer
    Nov 11, 2017 at 11:46
-1

Edited answer

bookdown has built-in templates (decided mostly by documentclass and/or Pandoc). Refer the Theming and Templates sections of bookdown documentation.

An example to learn from, as @pzhao suggested, is the template in the bookdown-chinese repo. Observe the variables that bring in data from the Rmd files. They're enclosed between $$, such as $body$. _output.yml has a reference to this template. This way, you override the default template, thereby eliminating duplicate headers/footers. Your LaTeX template decides what forms part of your headers/footers. An example is the LaTeX code in my question.

The appearance of Contents in the ToC table can also be controlled by tweaking your custom LaTeX template. I use the memoir class, and help to remove self-reference can be found here. My custom LaTeX template already took care of it, so it fixed itself as soon as I figured out how to use my custom template.

5
  • Can you share any information about this template? It would help make the question more useful to other people who may encounter the same problem. Nov 10, 2017 at 17:23
  • 1
    That's not an answer for the 2 questions asked. Just recommend a tutorial.
    – tremendows
    Nov 10, 2017 at 17:52
  • Edited. Thank you!
    – Ram Iyer
    Nov 10, 2017 at 18:27
  • @MikeyHarper I will try giving an answer with more information which might help.
    – pzhao
    Nov 11, 2017 at 8:51
  • @MikeyHarper, here's the repo with the customized code. Hope it helps.
    – Ram Iyer
    Nov 11, 2017 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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