Graphics, Figures & TablesGetting Extra \fi error for using subcaption package

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
gmbokoma_94
Posts: 4
Joined: Tue Oct 28, 2025 9:30 am

Getting Extra \fi error for using subcaption package

Post by gmbokoma_94 »

Hi

Kindly, assist with !Extra \fi error for subcaption package. The package is working perfectly for other projects but not working for this specific one. This error is rising from having \subcaptionbox inside the figure enviroment.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10387
Joined: Mon Mar 10, 2008 9:44 pm

Re: Getting Extra \fi error for using subcaption package

Post by Stefan Kottwitz »

Hi,

welcome to the forum!

There may be an error in your code. Perhaps post your code here as a small, reduced copy (complete with relevant preamble like \documentclass, etc.). That code should bring the error when we test it.

Once we can test the code and see the error, we can fix it most of the time. Without code, a hint is rarely possible.

Stefan
LaTeX.org admin
User avatar
Stefan Kottwitz
Site Admin
Posts: 10387
Joined: Mon Mar 10, 2008 9:44 pm

Re: Getting Extra \fi error for using subcaption package

Post by Stefan Kottwitz »

A quick example to show that it's usually working:

Code: Select all

\documentclass{article}
\usepackage{subcaption,lipsum}
\begin{document}
\section*{Demo of subcaption with subcaptionbox}
\lipsum[1]
\begin{figure}[htbp!]
  \centering
  \subcaptionbox{First dummy image}[.45\linewidth]{%
    \fbox{\rule{0pt}{3cm}\rule{5cm}{0pt}}%
  }\hfill
  \subcaptionbox{Second dummy image (longer caption
    to show wrapping)}[.45\linewidth]{%
    \fbox{\rule{0pt}{3cm}\rule{5cm}{0pt}}%
  }
  \caption{Two subfigures created with subcaptionbox}
  \label{fig:main-fig}
\end{figure}
\lipsum[2]
\end{document}
Stefan
LaTeX.org admin
gmbokoma_94
Posts: 4
Joined: Tue Oct 28, 2025 9:30 am

Re: Getting Extra \fi error for using subcaption package

Post by gmbokoma_94 »

Hi Stefan

Thank you so much.

Kindly, see attached the attached file. I literally just cut the parts that is giving problem.
Attachments
Test.zip
(885.83 KiB) Downloaded 1815 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10387
Joined: Mon Mar 10, 2008 9:44 pm

Re: Getting Extra \fi error for using subcaption package

Post by Stefan Kottwitz »

You have this line here:

Code: Select all

\caption{ Numerical, exact solution and absolute error at $T = 5$, with $\Delta t = 0.1$, $\Delta x = 0.12 $ for %Eq.~(\ref{eq-27}).}
Eq.~(\ref{eq-27}).} is commented out by that percent sign, so the closing brace is missing. Remove that % symbol.

Also, I think better move

Code: Select all

\usepackage{BSPMsample}
to the end of the preamble, right before \begin{document}, because it seems to interfere with the other packages otherwise.

Stefan
LaTeX.org admin
gmbokoma_94
Posts: 4
Joined: Tue Oct 28, 2025 9:30 am

Re: Getting Extra \fi error for using subcaption package

Post by gmbokoma_94 »

Thank you Stefan

The \usepackage{BSPMsample} is a special package for journal submission that I am trying to submit my article too. I can not by pass it. Maybe their package does not support \subcaptionbox, otherwise everything else is good.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10387
Joined: Mon Mar 10, 2008 9:44 pm

Re: Getting Extra \fi error for using subcaption package

Post by Stefan Kottwitz »

Sure, that's why I suggested keeping it, but moving it to a later place. If you have it on the top, first loaded, the other packages are not only interfering but can also change the journal's settings. If you move it to the end, it applies its settings later, when another package's settings cannot overwrite them. But if you don't have another error, you can keep that, the errors I got may be related to my local LaTeX version.

Stefan
LaTeX.org admin
gmbokoma_94
Posts: 4
Joined: Tue Oct 28, 2025 9:30 am

Re: Getting Extra \fi error for using subcaption package

Post by gmbokoma_94 »

Dear Stefan

Thank you very much. I have tried re-positioning \usepackage{BSPMsample} but I am still getting the same error. I will probably try to avoid subcaption at all cost. Or is there anyway I can do it?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10387
Joined: Mon Mar 10, 2008 9:44 pm

Re: Getting Extra \fi error for using subcaption package

Post by Stefan Kottwitz »

I get 0 errors. Perhaps post your updated code and the .log file you get with that code to see the exact error message and related information. I don't get an !Extra \fi error.

Stefan
LaTeX.org admin
Post Reply