2

I have some figures in my article. I want the figures to be framed. I managed to do this with the figure and floatrow packages. But I have a problem of changing the size of the frame, such that I have to reduce the figure size for it to fit in the frame. Then I cam across Colorbox under graphix hasn't the same width, from which I adapted the following mwe:

\documentclass[b5paper,11pt,fleqn,leqno,parskip=full]{article}
\usepackage{graphicx}
\usepackage[english,dutch]{babel}
\usepackage{multicol}
\usepackage{xcolor}
\graphicspath{ {../Images} }

\begin{document}
\begin{multicols}{3}
\noindent\parbox[t]{1.2\linewidth}{%
\fcolorbox{gray}{gray}{\includegraphics[width=2.5\linewidth]{../Images/precip_corr.jpg}
  \parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}{\color{white}%
  \raggedright{Areas of Significant El Nino-Related Precip Anomalies.\\ \small source: Ropelewski and Halpert.}
  }%
}%
}
\end{multicols}
\end{document}

This example works for me, except I want the caption below the figure. Moreover I do not understand the various arguments, changing by trial and error has not been useful, except:

1.2 in \noindent\parbox[t]{1.2 and \includegraphics[width=2.5.

I hope someone can help me:

a) get the caption below, if possible b) explain

{3} in \begin{multicols}{3}

[t] in \noindent\parbox[t]

-2 in \parbox{\dimexpr\linewidth-2\fboxsep-2

Thanks in anticipation.

Zilore Mumba
  • 1,087
  • Why are you using the multicols environment? I mean, why do you need it? – Alenanno Dec 26 '15 at 12:08
  • As I said with the figure/subcaption environment I cannot change the size of the frame. I will post another question, maybe I can be helped with the figure/subcaption environment. – Zilore Mumba Dec 26 '15 at 12:34

1 Answers1

3

I think you can safely switch to using mdframed for the background, the size can be easily changed, so if that's why you had the multicols package, you can remove it.

Below is an example with a \newcommand. The color of the background is optional (default white).

Regarding your questions:

  1. The number 3 in multicols denotes the number of columns the text splits into.
  2. The option [t] in parbox is the text alignment, that goes:

    • [t] — text is placed at the top of the box.
    • [c] — text is centered vertically.
    • [b] — text is placed at the bottom.
    • [s] — stretch vertically. Note that the text must contain vertically stretchable space for this to work.
  3. \linewidth-2 basically is removing 2 from the value of \linewidth.


Note: the margins have been altered to show the pages closer for this screenshot. Click the image to view it better.

Output

enter image description here

Code

\documentclass[b5paper,11pt,fleqn,leqno]{article} % parskip=full was unused
\usepackage{graphicx}
\usepackage[english,dutch]{babel}
\usepackage{cleveref} % clever referencing that adds "fig.", etc, automatically
\usepackage{xcolor}
\usepackage{mdframed} % required for drawing the background + line color
\usepackage{float} % needed to use [H]

\newcommand\bfig[4][white]{
  \begin{figure}[H]
    \begin{mdframed}[linecolor=#1,backgroundcolor=#1]
    \centering
    \includegraphics[width=\textwidth,height=\dimexpr\textheight-4\baselineskip-\abovecaptionskip-\belowcaptionskip\relax,keepaspectratio]{#2}
    \caption[caption]{#3}\label{#4}
    \vspace{10pt}
    \end{mdframed}
  \end{figure}
}

\begin{document}

\bfig{example-image-a}{Areas of Significant El Nino-Related Precip Anomalies.\\\hspace{\textwidth}\small Source: Ropelewski and Halpert.}{imagea}

As showed in \cref{imagea}, A is the best letter.

\bfig[gray]{example-image-b}{Areas of Significant El Nino-Related Precip Anomalies.\\\hspace{\textwidth}\tiny Source: Ropelewski and Halpert.}{imageb}

While \cref{imageb}, well, not really...
\end{document}
Alenanno
  • 37,338
  • Thanks very much @Alenanno, I will go with the mdframed it does what I want, and thanks for explaining the multicol options. – Zilore Mumba Dec 26 '15 at 13:46
  • @ZiloreMumba No problem! You can try pasting a very long Lorem Ipsum inside a multicols environment and try changing the number. :) – Alenanno Dec 26 '15 at 13:48
  • @ZiloreMumba Note that I used \small in the first example and \tiny in the second one. I think it's still readable. You could also use \scriptsize. – Alenanno Dec 26 '15 at 15:11
  • or others who may read this, I have worked with the code you gave me and it is fine for my purpose. I have been trying to figure out, how do I adjust the figure size? I will need this for some figures. – Zilore Mumba Dec 27 '15 at 10:02
  • @ZiloreMumba Have you tried changing the options for \includegraphics? Check between the square brackets. :) – Alenanno Dec 27 '15 at 18:45
  • the only change I tried is to put "[scale=num]" in place of "width=\textwidth". When I put scale<1 (say 0.5) the framed reduces but not the figure. scale >1 makes the figure too large to invisible on the right. Is there anything else I can change ,e.g. in "height=\dimexpr\textheight-4\baselineskip-\abovecaptionskip-\belowcaptionskip\relax"? – Zilore Mumba Dec 28 '15 at 07:55
  • Looks like I can no longer get @Alenanno to assist me. can anyone suggest to me how I can make the graphic in the above code scale down to less than 100%? Currently I can only get it to textwidth/linewidth or larger. Thanks in anticipation. – Zilore Mumba Dec 29 '15 at 19:30
  • @ZiloreMumba I think it's safe for you to ask a follow-up question, since it looks to me like a separate issue, you can also link to this one in the new one to provide some context. – Alenanno Dec 29 '15 at 19:39