0

I am compiling a different documents of article class type and I am using a main tex file of report class to compile it into one pdf file. I used subfile{} to do so but the \maketitle{} page in documents are not showing up. How can I make it so without complicating anything? My main tex file say Lab_Report.tex looks like

\documentclass[12pt]{report} %article also works
\usepackage{subfiles}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{float}
\usepackage{parskip}
\usepackage{siunitx}
\title{}
\begin{document}



\maketitle 
\subfile{report1}
\subfile{report2}



\end{document}

my report.tex looks like

\documentclass{article}
\usepackage{amsmath} 
%assume all necessary packages included


\title{Report 1 - Make something}
\date{1st April 2022}
\begin{document}
\maketitle
\newpage
\subsection*{Aim:}
To do something
\subsection*{Apparatus:}
Whatever you have now
\end{document}

The end result is that all included files are present but without the \maketitle page. I am quite new to Latex so my code might seem silly.

5
  • Welcome to TeX.SE! Please show us a short compilable tex code resulting in your issue ....
    – Mensch
    Apr 10, 2022 at 16:11
  • Are you using the subfiles package? If so, don't the subfiles need to be of the subfiles class rather than the article class? In any case, don't make us guess. Provide a minimal working example.
    – frabjous
    Apr 10, 2022 at 16:14
  • @Mensch There are many files involved in this. The code is error free just that it doesn't show the title page. Am I missing something?
    – Vaishnav
    Apr 10, 2022 at 16:14
  • @Vaishnav How are we supposed to know when you provide us with such little information? We are not clairvoyant. You didn't even answer my first question. Please click the link in my previous comment and learn how to make a MWE.
    – frabjous
    Apr 10, 2022 at 16:43
  • @frabjous I'm really sorry. However, I made my work by merging pdfs. It was quite urgent so I couldn't provide the MWE. However, I will soon update the details with the MWE for the sake of learning so that I can apply it in future. To answer your Question, The 'subfiles' I used were of the class article and they did work but only left out the title page. The main tex was of class report. It would take too much time to change thedoc class and change the code for 6 other documents in short time so I had to resort to merging PDFs using pdfpages package and using \includepdf[]{}.
    – Vaishnav
    Apr 11, 2022 at 7:41

1 Answer 1

1

The subfiles package is not meant to be used the way you were trying to use it. The included files are meant to be parts of the main document, not separate documents with a different document class. In fact, I'm surprised you didn't just get errors when you tried to use it with the subfiles having the "article" document class. All subfiles are supposed to use the "subfiles" document class.

See its documentation, which reads:

The subfiles have to start with the line:

\documentclass[main file name]{subfiles}

which loads the class subfiles. Its only ‘option’, which is actually mandatory, gives the name of the main file. This name follows TEX conventions: .tex is the default extension, the path has to be provided if the main file is in a different directory, and directories in the path have to be separated by / (not ). Thus, we have the following structure.

If LATEX is run on the subfile, the line \documentclass[..]{subfiles} is replaced by the preamble of the main file (including its \documentclass command). The rest of the subfile is processed normally.

As you can see, the subfiles are not supposed to have their own preambles. The package replaces their preambles with the preamble of the main document. Their own preambles are ignored. So the \title and \date commands in your example preambles are just being ignored when the main file is compiled.

Moreover, a single document doesn't usually have multiple \maketitle commands in it. If you need to have multiple \maketitle commands, you would need to load the titling package.

As I see it, you have three options.

Option A

This is closest to what you were trying. Load the titling package in the main file, to allow for multiple \maketitle commands.

\documentclass[12pt]{report}
\usepackage{subfiles}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{float}
\usepackage{parskip}
\usepackage{siunitx}
\usepackage{titling}

\title{Main title}
\author{Author}
\date{Main date}
\begin{document}

\maketitle
\subfile{report1}
\subfile{report2}

\end{document

Move the \title and \date commands in the subfiles to after \begin{document} so they are actually registered (remember the premable is ignored). You can remove any \usepackage commands; they are ignored too. Just make sure the packages you needed are loaded in the main file.

\documentclass[main]{subfiles}
\begin{document}
\title{Report 1 - Make something}
\date{1st April 2022}
\maketitle
\subsection*{Aim:}
To do something
\subsection*{Apparatus:}
Whatever you have now
\end{document}

Of course, the article class is not used at all here, so the titles will be in the style of report (that is, they will be title pages rather than just a heading) by default. The titling package however does let you change the style of the titles. See its documentation.

Option B

Treat the subfiles as "chapters" of the report, since the report class supports chapters, and indeed, expects them. (Your \subsections are not numbered, but if they were, you would notice the numbering starts with 0.0 for the chapter/section as no chapter or section commands were given.) This option actually makes more sense to me, since it uses the report class more the way it was intended.

The subfiles would then be simpler:

\documentclass[main]{subfiles}
\begin{document}
\chapter*{Report 1 - Make something} % remove the * if you want it numbered
\subsection*{Aim:}
To do something
\subsection*{Apparatus:}
Whatever you have now
\end{document}

Then instead of new \maketitle commands, you could just use the chapter heading. If you need to style the chapter headings, or put them on their own pages, something like the titlesec package would allow for that (including adding a date if you needed that).

Option C

You can do what you did. Prepare many separate article class documents, and combine with a main file that uses the pdfpages package, or use a similar tool. This option makes more sense to me if your separate documents really are separate "articles" and not chapters of a single work, and you just need them in a single PDF for some reason

3
  • Thank you for the detailed answer. Will I be able to run the subfiles individually or I'll have to load it in the main report tex and then debug?? Also Will I be able to add chapters and Number the pages continuously using pdfpages?
    – Vaishnav
    Apr 12, 2022 at 14:12
  • You can run the files individually with the subfiles package, yes. That's the main point of the package as opposed to using \include or \input instead. You can add page numbers with pdfpages, yes: see here. If you go that route and need correct chapter numbers, you may need to set them manually with setcounter{chapter}{4} right before \chapter{..} for Chapter 5, for example.
    – frabjous
    Apr 12, 2022 at 14:19
  • Thank you so much
    – Vaishnav
    Apr 12, 2022 at 16:58

You must log in to answer this question.

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