Is it possible to compile a LaTeX document but only include one section and its associated tables and figures?

I have two cases for which this would be useful:

  1. I would like to provide the Methods section of a paper to colleagues.

  2. I would like to have multiple versions of a document that contain different combinations of the sections of a master document.

I know that I could place each section in a separate file and then have separate master files - likely what I will do for case 2 since it is integral to the final document structure, but at least for case 1, I am hoping that there is a way to only compile one section.



I'd have a look at the Subfiles LaTeX package for Part 1. It provides a lot of flexibility, and saves having to alter files prior to building them.

Essentially, you could have your main document Paper.tex:

% Preamble
% More preamble

And then each other section would look a bit like this:


You could then either run LaTeX on the individual sections (for example Methods.tex) and it will be compiled with the preamble from the main root document.

To solve Part 2, I'd do something like the following which I've just tested with the examples above.


This means you only have to maintain one preamble, and stops you having lots and lots of root files, even though you will have a minimised root file for each version of your document involving more than one subfile.

  • I've just checked it does work for the second scenario, and it does, so I've edited my answer accordingly. – Edd Dec 14 '10 at 15:58
  • Can you recommend some TOC method/pkg to have unique TOCs with each subfile? I moved this question here. – hhh Dec 26 '15 at 17:54

To q.1: If you don't want to change the structure of your document putting each section into a separate file, you may use

\excludecomment{toexclude} % you can name the comment as you wish

in the preamble, and mark up any temporary unnecessary part of the document with


Once you want again to compile everything together, just replace




For case 1:

Make a file methods.tex and put your methods in it:


The methods employed here...

Put the rest of the document into a file rest.tex.

In place of the text in the main document put


Finally, in your preamble put


A disadvantage to this solution is that the methods section will start a new page.

You could also just delete the non-Methods pages from the PDF with a PDF utility. Or you could send them the whole paper and tell them just to read the Methods section. :-)

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.