2

I'm trying to fit two figures side by side (with the same size) in the width of the text, using the floatrow package. I use the showframe option and the \fbox in mwe for better visualization. how to fit perfectly on text width?

\documentclass[]{report}
\usepackage[a4paper,showframe]{geometry}
\usepackage{subcaption}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{floatrow} 

\begin{document}


\lipsum[1]
\begin{figure}[htb!]
\ffigbox[\textwidth]
{\begin{subfloatrow}[2]\setlength\fboxsep{0pt}\setlength\fboxrule{0.75pt}\fbox{\ffigbox[0.49\textwidth]
{
    \caption{sidewalk perforation}
    \label{subfig:furadeira}
}
{   \setlength\fboxsep{0pt}
    \setlength\fboxrule{0.75pt}
    \fbox{\includegraphics[width=0.48\textwidth]{image1.jpg}}}
    \setlength\fboxsep{0pt}
    \setlength\fboxrule{0.75pt}}
    \fbox{\ffigbox[0.49\textwidth]
{
\caption{volatile organic compounds measurement}
\label{subfig:medicaomalha}
}
{
    \setlength\fboxsep{0pt}
    \setlength\fboxrule{0.75pt}
    \fbox{\includegraphics[width=0.48\textwidth]{image2.jpg}}
}}
\end{subfloatrow}
}
{
    \caption{Hot spot investigation}
    \label{fig:hotspot}
}
\end{figure}%
\lipsum[1]
\end{document}

enter image description here

  • Possible duplicate of Too wide subfigures? – cslstr Mar 7 '14 at 22:40
  • "You have fixed the with of \includegraphics exactly as big as \ffigbox." but in my case, the \includegraphics is already smaller than \ffigbox. – leonardo cesar Mar 7 '14 at 22:55
2

You need to change the default floatseparator (\columnsep) used. None of the predefined separators will be of use here given the widths of your figures, but you can easily define one using \DeclareFloatSeparators:

\documentclass[]{report}
\usepackage[a4paper,showframe]{geometry}
\usepackage{subcaption}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{floatrow} 

\DeclareFloatSeparators{myfill}{\hskip.013\textwidth plus1fill}

\begin{document}

\lipsum[1]
\floatsetup[subfloat]{floatrowsep=myfill}
\begin{figure}[htb!]
\setlength\fboxsep{0pt}\setlength\fboxrule{0.75pt}
\ffigbox[\textwidth]
{
\begin{subfloatrow}[2]
%\fbox{
\ffigbox[.49\textwidth]
  {
    \caption{sidewalk perforation}
    \label{subfig:furadeira}
  }
  {
    \includegraphics[width=\linewidth]{example-image-a}%
  }
%}
%\fbox{
\ffigbox[.49\textwidth]
  {
    \caption{volatile organic compounds measurement}
    \label{subfig:medicaomalha}
  }
  {
    \includegraphics[width=\linewidth]{example-image-b}%
  }
%}
\end{subfloatrow}%
}
{
    \caption{Hot spot investigation}
    \label{fig:hotspot}
}
\end{figure}%
\lipsum[1]

\end{document}

enter image description here

Notice that there's still some spurious blank space to the left of the first subfligure; I suspect this is a bug in floatrow.sty (most probably a missing % to kill a surious space).

To have the subfigures perfectly flushed to the margins, I'd suggest you a work-around using floatrow instead of subfloatrow and using \captionof{subfigure}{text...} to provide the captions:

\documentclass[]{report}
\usepackage[a4paper,showframe]{geometry}
\usepackage{subcaption}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{floatrow} 

\captionsetup[subfigure]{labelformat=parens,labelsep=space}

\begin{document}

\lipsum[1]

\begin{figure}[htb!]
\ffigbox[\textwidth]
  {
    \begin{floatrow}
    \ffigbox[\linewidth]
      {\captionof{subfigure}{sidewalk perforation}
      \label{subfig:furadeira}}
      {\includegraphics[width=\linewidth]{example-image-a}}
    \ffigbox[\linewidth]
      {\captionof{subfigure}{volatile organic compounds measurement}
      \label{subfig:medicaomalha}}
      {\includegraphics[width=\linewidth]{example-image-b}}
    \end{floatrow}%
  }
  {\caption{Hot spot investigation}\label{fig:hotspot}}
\end{figure}
\lipsum[1]

\end{document}

enter image description here

  • the second solution works perfectly!!! thanks!! – leonardo cesar Mar 8 '14 at 3:48
  • i tryed to use \DeclareFloatSeparators{myfill}{\hfill} \floatsetup[subfigure]{subfloatrowsep=myfill} but it didnt work. I agree with you: may be there is a bug in floatrow. – leonardo cesar Mar 8 '14 at 3:52
  • i've found a error!!i'm using \usepackage{subcaption} \renewcommand{\thesubfigure}{Fig. \thefigure.\arabic{subfigure}}. in preamble and the captionof show a wrong numbering. in the case of this mwe: (Fig. 0.1) and (Fig. 0.2) – leonardo cesar Mar 8 '14 at 4:06
  • @user42634 well, that's the expected result with your settings. You are prepending the figure counter to subfigures, but place captions for subfigures before the caption for the figure, so the figure counter has not yet stepped and the wrong number is picked. Why do you need the counter of the figure for the subfigures? – Gonzalo Medina Mar 8 '14 at 16:07
  • 1
    @user42634 If the captions for subfigures will always be before the caption for the figure, with your current settings you'll need to step the counter as in \renewcommand{\thesubfigure}{Fig. \number\numexpr\thefigure+1\relax.\arabic{subfigure}}. – Gonzalo Medina Mar 8 '14 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.