I really need help. Here is the problem:

I'm writing my dissertation using a LaTeX template (http://www.latextemplates.com/template/masters-doctoral-thesis). The template is a parent file with multiple chapters as children. For some of the chapters, I want to include objects and output from R, whereas for other chapters (e.g., Introduction) I don't want to use R. For the chapters without R, I've created the .TeX files as part of the template.

I'm using knitr to create .TeX files with R objects and output. I want the .Rnw files to be included as child .TeX files into another child .TeX file that belongs to the larger parent .TeX file. The parent-child structure works for my .TeX files as part of the template using \input{}. However, I'm having trouble getting the .TeX files created from the .Rnw files to be included as child .TeX file in an another child file.

I've seen resources for combining .Rnw files as child files of a larger parent .Rnw file, but they do not address my issue (unless I am reading them the wrong way).

I knitted the .Rnw file into .TeX, then copy the body of document generated in the child file, and copy the rest in LateX classfile (that is the document where you declare the packages that will be used in the main document), but I get the following error message:

you can't use '\spacefactor' in vertical mode \tableofcontents

​Additionally, my table of contents on the final outputs do not print properly at all.

  • without any example hard to say but the error you quote means that you have used a command such as \@something in a place where @ is not a letter. So you need to move that somewhere else or surround it with \makeatletter ... \@something.... \makeatother Nov 27, 2014 at 12:56
  • It's a bit hard to present an example like that because the problem involves 3 different files: .cls file, .teX file and .Rnw file.
    – Franckess
    Nov 27, 2014 at 16:02
  • Just make your master file a .Rnw file rather than a .tex file. Just because you don't have R code in some chapters doesn't mean that you can't still save it as an .Rnw file and process it with knitr. Doing so will just be vacuous. Then you can avoid copying and pasting stuff. My answer here should solve your use case.
    – Adam Liter
    Nov 27, 2014 at 23:53
  • @AdamLiter I read your post many many times, without being able to fix my problem. When using the template from the link, you would see that the files are all bundled up and nothing cannot be changed to the way you explained. What I ended up doing was to add \usepackage{listings} then adjust it according to the preamble of the .tex file when the .Rnw is knitted. Everything is looking good now :)
    – Franckess
    Nov 28, 2014 at 14:00
  • I just downloaded the template that you linked me to. If you change all of the .tex files to .Rnw files and replace all of the \input commands to, for example, <<child-demo, child='Chapters/Chapter1.Rnw'>>=@, then it will work just fine.
    – Adam Liter
    Nov 28, 2014 at 16:48


Your Answer

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

Browse other questions tagged or ask your own question.