Graphics, Figures & TablesIssues with subfloats and brackets

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
siekosunfire
Posts: 3
Joined: Fri Apr 03, 2009 1:10 pm

Issues with subfloats and brackets

Post by siekosunfire »

There seems to be an issue with how the subfloat package parses brackets (either in math mode or not). For instance, the following:

Code: Select all

\subfloat[][$[0,1]$]{ ... }
produces the ensuing error under pdfTeX, version 3.1415926-1.40.9, and MiKTeX, version 2.7:
! Extra }, or forgotten $. <recently read> }
l.94 \subfloat[][$[0,1]$]{
Does anyone know of a fix for this?

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Issues with subfloats and brackets

Post by localghost »

In the subfloat manual I can't find any hint that this package deals with the command that causes the error you described. Build a minimal working example (MWE) to clarify that.


Best regards
Thorsten
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Issues with subfloats and brackets

Post by gmedina »

Hi,

the OP was talking about the \subfloat command provided by the subfig package. Here's a MWE showing the problem mentioned:

Code: Select all

\documentclass{aricle}
\usepackage{subfig}

\begin{document}

\begin{figure}[!ht]
  \centering
  \subfloat[][$[0,1]$]{\label{fig:rect1}\rule{2cm}{1cm}}\qquad
  \subfloat[][$[2,3]$]{\label{fig:rect2}\rule{2cm}{1cm}}           
  \caption{two rectangles}
  \label{fig:rect}
\end{figure}

\end{document}
the compilation of that code will produce 10 errors and 4 bad boxes! The fix: use the good ol' curly braces:

Code: Select all

\documentclass{article}
\usepackage{subfig}

\begin{document}

\begin{figure}[!ht]
  \centering
  \subfloat[][${[0,1]}$]{\label{fig:rect1}\rule{2cm}{1cm}}\qquad
  \subfloat[][${[2,3]}$]{\label{fig:rect2}\rule{2cm}{1cm}}           
  \caption{two rectangles}
  \label{fig:rect}
\end{figure}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply