3

I got it from overleaf that the subfiles package is best loaded last in the preamble.

Besides, it is known that hyperref is recommended to loaded last too. In another answer, I got that

Load varioref first, then hyperref, then cleveref

so what's the best or recommended order to load these packages mentioned above?

1 Answer 1

2

Recommended order for the packages you mentioned:

Subfiles - This package should be loaded first. It is designed to help manage multi-file LaTeX documents by allowing you to compile each file individually as well as the main document as a whole. So it's generally a good idea to load the subfiles package first so that it can properly handle any subfiles included in the document.

In addition, subfiles doesn't typically interact with the other packages you mentioned (cleveref, hyperref, and varioref), so its position in the loading order should not affect their behavior.

If you are using subfiles to manage a multi-file document, it is important to load it before any packages that modify the way files are included or referenced, such as xr or import.

Varioref - This package should be loaded first, as it modifies the way LaTeX handles cross-referencing.

Hyperref - This package should be loaded after varioref, as it also modifies cross-referencing and creates hyperlinks in the document. It is normally loaded last, but due to cleveref it is not.

Cleveref - This package should be loaded last, as it depends on both varioref and hyperref. It provides additional features for cross-referencing, such as automatic formatting of reference types.

If you look at the cleveref guide:

The following are not bugs. They are either intentional behaviour, unavoidable behaviour, or are caused by LATEX misunderstandings: • If you are using both varioref and hyperref, make sure you are loading them in the correct order, otherwise cross-references will reference completely the wrong thing without any warning in the LATEX output or log! The packages must be loaded in the following order: varioref, hyperref, cleveref.

1
  • +1. However, I don't think it's quite right to say that cleveref "depends on both varioref and hyperref". It's a lot more subtle than that. The issue is that hyperref and cleveref both modify the \label macro. Now, cleveref is programmed to check during load time if the \label macro has been modified by hyperref and to proceed in a way that doesn't interfere with hyperref. hyperref, OTOH, isn't quite as courteous; if it's loaded after instead of before cleveref, it'll clobber the \label macro that's there in a way that makes cleveref unable to do its own job.
    – Mico
    Mar 31 at 3:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .