When using the subfiles package, each subfile starts numbering sections with 1. How can I get consecutive numbering for the entire document?

  • 2
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Mar 7 '15 at 15:49
  • 1
    I think you may want to use either input or include instead of subfiles: tex.stackexchange.com/questions/246/… – U.Martinez-Corral Mar 7 '15 at 23:13
  • We are still waiting for a MWE ;-) – user31729 Mar 9 '15 at 22:32

Using the refcount and xstring package in the main file, you could automatically retrieve the correct chapter (or whatever counter you want) number from the main document.






|improve this answer|||||

This method is not fully advisable as it can break things.

You can specify what numbering you want to use within your subfile by using \setcounter{chapter}{*insert-number-here*}

For example, as you say, the default is for subfiles to always start with 1. If you want it to start the numbering at 2, then before \chapter{Your Chapter} write \setcounter{chapter}{1}.

For more info on this see this post - Chapter number starts at 2 not 1

|improve this answer|||||
  • Generally, you shouldn't manually adjust the counters unless you need to. Otherwise, when you change things, your numbering will be all wrong. Since the original didn't include a MWE, we can't really figure out why the section numbering restarts at 1, which shouldn't happen by default. – Teepeemm Jun 17 '17 at 23:35
  • Yes I agree, it is unclear from the question what the problem really was. However, I think it was this. Say I am using subfiles, when I separately compile an individual subfile (a single chapter say), the default chapter numbering is 1. Obviously, when I go back to main file and compile all the subfiles together, the chapter numbering is in the correct order. But if I am just working with an individual subfile the numbering always starts at 1. Therefore, sometimes it is useful to have a way to force the subfile numbering to change to what you want. – Milo Mar 5 '18 at 16:15
  • There is likely to be a better solution to this problem somewhere, but so far I haven't found it! – Milo Mar 5 '18 at 16:16
  • I'm not terribly experienced with using subfiles, but my impression is that it's designed for when you want to tweak a small section. If you're wanting section and other numbering to stay correct while you work, you might be better off using \include and \includeonly. But without the MWE, who knows. – Teepeemm Mar 5 '18 at 19:56

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.