Graphics, Figures & Tables\fbox with caption/subcaption packages

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
lauraf
Posts: 29
Joined: Tue Jan 13, 2009 12:44 pm

\fbox with caption/subcaption packages

Post by lauraf »

Hi all,

I am using the caption/subcaption packages and \fbox for the same float. This adds a little extra space on the left side of the images, relative to the caption. The extra space disappears after I remove the \fbox, as shown below. I could not work out why this is or how to fix it. Any ideas?

Many thanks,
Laura

PS Note that the example below is a "minimum quasi-working example": you need to replace "someImage" with the path to an image file that is on your system, obviously ;)

Code: Select all

\documentclass[a4paper, 11pt, final]{article}

\usepackage[english]{babel}

\usepackage{graphicx}
\usepackage[labelfont={rm,bf}, textfont=rm, font=small]{caption}
\usepackage[labelfont={rm,bf}, textfont=rm, font=small, list=true, listformat=subparens]{subcaption}
\captionsetup[table]{position=top} 
\captionsetup[subtable]{position=top} 

\title{Minimum (quasi-)working example} 

\date{\today}

\begin{document}
\maketitle

\begin{figure}%
\centering%
\subcaptionbox{Some text.}%
{%
\setlength\fboxsep{0pt}
\setlength\fboxrule{0.5pt}
\fbox{\includegraphics[width=0.45\textwidth]{./someImage}}}%
\hfill%
\subcaptionbox{Some text.}%
{%
\setlength\fboxsep{0pt}
\setlength\fboxrule{0.5pt}
\fbox{\includegraphics[width=0.45\textwidth]{./someImage}}}%
\caption[]{Some text.}%
\label{fig:someFig}%
\end{figure}


\begin{figure}%
\centering%
\subcaptionbox{Some text.}%
{\includegraphics[width=0.45\textwidth]{./someImage}}%
\hfill%
\subcaptionbox{Some text.}%
{\includegraphics[width=0.45\textwidth]{./someImage}}%
\caption[]{Some text.}%
\label{fig:someFig}%
\end{figure}

\end{document}
Last edited by lauraf on Fri Aug 13, 2010 10:15 pm, edited 1 time in total.

Recommended reading 2024:

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

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

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

\fbox with caption/subcaption packages

Post by localghost »

lauraf wrote:[…] Note that the example below is a "minimum quasi-working example": you need to replace "someImage" with the path to an image file that is on your system, obviously […]
Not necessary because there is the demo option for the graphicx package and the possibility to replace the images by \rule commands of equivalent size [1].

Somehow I can't comprehend the problem. Perhaps it's only a subjective impression. See my list of used files below (obtained by the \listfiles command in the very first line of the example).

Code: Select all

 *File List*
 article.cls    2007/10/19 v1.4h Standard LaTeX document class
  size11.clo    2007/10/19 v1.4h Standard LaTeX file (size option)
   babel.sty    2008/07/06 v3.8l The Babel package
 english.ldf    2005/03/30 v3.3o English support from the babel system
graphicx.sty    1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
  keyval.sty    1999/03/16 v1.13 key=value parser (DPC)
graphics.sty    2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg    2009/08/28 v1.8 graphics configuration of TeX Live
  pdftex.def    2009/08/25 v0.04m Graphics/color for pdfTeX
 caption.sty    2009/10/09 v3.1k Customizing captions (AR)
caption3.sty    2009/10/09 v3.1k caption3 kernel (AR)
subcaption.sty    2008/08/31 v1.0b Adding subcaptions (AR)
supp-pdf.mkii
 ***********
[1] View topic: Avoidable mistakes


Thorsten
lauraf
Posts: 29
Joined: Tue Jan 13, 2009 12:44 pm

\fbox with caption/subcaption packages

Post by lauraf »

Thank you Thorsten for the clarification, and apologies for not making the post clear.

This is the list of files used, it is identical to yours:

Code: Select all

*File List*
 article.cls    2007/10/19 v1.4h Standard LaTeX document class
  size11.clo    2007/10/19 v1.4h Standard LaTeX file (size option)
   babel.sty    2008/07/06 v3.8l The Babel package
 english.ldf    2005/03/30 v3.3o English support from the babel system
graphicx.sty    1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
  keyval.sty    1999/03/16 v1.13 key=value parser (DPC)
graphics.sty    2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg    2009/08/28 v1.8 graphics configuration of TeX Live
  pdftex.def    2009/08/25 v0.04m Graphics/color for pdfTeX
 caption.sty    2009/10/09 v3.1k Customizing captions (AR)
caption3.sty    2009/10/09 v3.1k caption3 kernel (AR)
subcaption.sty    2008/08/31 v1.0b Adding subcaptions (AR)
supp-pdf.mkii
 ***********
And here is a MWE:

Code: Select all

\documentclass[a4paper, 11pt, final]{article}

\usepackage[english]{babel}

\usepackage[demo]{graphicx}
\usepackage[labelfont={rm,bf}, textfont=rm, font=small]{caption}
\usepackage[labelfont={rm,bf}, textfont=rm, font=small, list=true, listformat=subparens]{subcaption}
\captionsetup[table]{position=top} 
\captionsetup[subtable]{position=top} 

\title{Minimum working example} 

\date{\today}

\begin{document}
\maketitle

\begin{figure}[!p]%
\centering%
\subcaptionbox{Some text.}%
{%
\setlength\fboxsep{0pt}
\setlength\fboxrule{0.5pt}
\fbox{\includegraphics[width=0.45\textwidth]{./img/someImage}}}%
\hfill%
\subcaptionbox{Some text.}%
{%
\setlength\fboxsep{0pt}
\setlength\fboxrule{0.5pt}
\fbox{\includegraphics[width=0.45\textwidth]{./img/someImage}}}%
\caption[]{Some text.}%
\label{fig:someFig}%
\end{figure}


\begin{figure}[!p]%
\centering%
\subcaptionbox{Some text.}%
{\includegraphics[width=0.45\textwidth]{./img/someImage}}%
\hfill%
\subcaptionbox{Some text.}%
{\includegraphics[width=0.45\textwidth]{./img/someImage}}%
\caption[]{Some text.}%
\label{fig:someFig}%
\end{figure}

\end{document}
What you should see is that Fig. 1a and 2a are not aligned on the left side --- there is some extra space on the left side of Fig. 1a. It seems that the problem lies with adding \fbox to Fig. 1, since the extra space is not there when the bit of code relating to \fbox is removed, as in Fig. 2.

I hope this is clearer --- I would be grateful for any input!

Many thanks,
Laura
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

\fbox with caption/subcaption packages

Post by sommerfee »

The extra space is caused by

Code: Select all

\setlength\fboxsep{0pt}
\setlength\fboxrule{0.5pt}
So use

Code: Select all

\setlength\fboxsep{0pt}%
\setlength\fboxrule{0.5pt}%
instead. (Note the percent characters.)
lauraf
Posts: 29
Joined: Tue Jan 13, 2009 12:44 pm

Re: \fbox with caption/subcaption packages

Post by lauraf »

Thank you Axel, this works :)
Post Reply