3

I'm trying to recreate a figure and caption effect from a journal. An example of it can be seen on PDF version of Figure 1 from this article:

enter image description here

It's basically a large grey bordered box that goes around the image and caption, and the bottom section, where the caption is filled in grey.

I'm currently using

\usepackage{xcolor}
\usepackage{mdframed}
\mdfdefinestyle{mystyle1}{
    backgroundcolor=white!20
}
\mdfdefinestyle{mystyle2}{
    backgroundcolor=lightgray!20
}

in the preamble, and

\begin{figure}[htb!]
\centering
    \begin{mdframed}[style=mystyle1]
        \includegraphics[width=1.0\textwidth]{foo.pdf}
        \begin{mdframed}[style=mystyle2]
            \caption[foo]{foo}
        \end{mdframed}
    \end{mdframed}
\label{fig:foo}
\end{figure}

This creates a box around the whole figure and caption, and then a subbox around the caption, but they don't lineup, and I can't figure out how to change the border colour.

Any help would be appreciated.

  • Welcome to TeX.SX! The question would be improved by including a complete compilable minimal example, so that those trying to help do have to put such a file together, see minimal working example (MWE). – Andrew Swann Jan 21 '15 at 17:40
4

Below I present one option using tcolorbox to define a figurebox environment. This environment has an optional argument to specify placement options (just as for the standard figure environment).

Instead of using two boxes, I just used one box; the upper part is used for the image and the lower one, for the caption. Use \tcblower just before \caption.

The caption package was used to easily change the color for the caption labels. Change the settings according to your needs:

\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{lipsum}

\definecolor{captioncol}{RGB}{46,86,145}

\newtcolorbox{mycaptionbox}{
  freelance,
  enhanced,
  colframe=gray,
  arc=0pt,
  middle=2pt,
  outer arc=0pt,
  boxrule=0.7pt,
  enlarge left by=-5mm,
  enlarge right by=-5mm,
  text width=\textwidth-1.4pt,
  nobeforeafter,
  segmentation hidden=true,
  interior code={
  \path[draw=none,fill=gray!30]
    (interior.south west) rectangle (segmentation.north east);
  \path[draw=none,fill=white]
    (segmentation.west) rectangle (interior.north east);
  \draw[draw=gray,line width=0.7pt]
    (segmentation.west) -- (segmentation.east);
  },
}

\newenvironment{figurebox}[1][tbp]
  {\begin{figure}[#1]\begin{mycaptionbox}}
  {\end{mycaptionbox}\end{figure}}

\DeclareCaptionFormat{colorlabel}{\textcolor{captioncol}{#1#2}#3}
\captionsetup{format=colorlabel}

\begin{document}

\lipsum[4]
\begin{figurebox}
\includegraphics[height=3cm,width=.6\linewidth]{example-image-a}
\tcblower
\caption{\protect\lipsum[2]}
\end{figurebox}

\end{document}

The output:

enter image description here

| improve this answer | |
1

What do you mean by lining up? To change the border color please look at the answer from this link: How to change the border of mdframed? Here is the result on my computer

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{pgfplots}
\usepackage{xcolor}
\usepackage{mdframed}
\mdfdefinestyle{mystyle1}{
    backgroundcolor=white!20,
    linecolor=red
}
\mdfdefinestyle{mystyle2}{
    backgroundcolor=lightgray!20,
    linecolor=blue
}
\begin{document}

\begin{figure}[htb!]
\begin{mdframed}[style=mystyle1]
\centering
\begin{tikzpicture}
  \begin{axis}
    \addplot[domain=-1:1] {x^2};
  \end{axis}
\end{tikzpicture}
  \begin{mdframed}[style=mystyle2]
    \caption{Caption.}
  \end{mdframed}
\end{mdframed}
\label{fig:foo}
\end{figure}
\end{document}

Here is what the result on my computer using pdflatex

| improve this answer | |

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.