2

I want to style my figures and I found a way to do so with tcolorbox.

\newtcolorbox[blend into=figures]{myfigure}[2][]{float=htb,capture=hbox,blend before title=colon hang,title={#2},every float=\centering,#1,sharp corners,colback=white,colbacktitle=blue!30!black}

\begin{myfigure}{Title}
\includegraphics[width=0.6\textwidth]{Graphic} 
\end{myfigure}

Is there a possibility to add some text besides the graphic?


Thank you for your answers.

So here's the MWE showing one standard figure with a subtext and a tcolorbox-figure. What I want to do is adding some text inside the tcolorbox, too. This text should be under (maybe the best way) or on one side the graphic - but inside the colorbox.

\documentclass{article}
\usepackage{graphicx}
\usepackage{ngerman}
\usepackage[theorems,skins,breakable]{tcolorbox}

\newtcolorbox[blend into=figures]{myfigure}[2][]{float=htb,capture=hbox, blend before title=colon hang,title={#2},every float=\centering,#1,sharp corners,colback=white,colbacktitle=blue!30!black}

\begin{document}

\begin{figure}[h]
\centering \includegraphics[width=0.6\textwidth]{Graphic} 
\caption{Title}
\footnotesize{Subtext Line 1 \\ Subtext Line 2}
\end{figure}

\begin{myfigure}{Title}
\includegraphics[width=0.6\textwidth]{Graphic} 
\end{myfigure}

\end{document}

enter image description here

  • 3
    Welcome to TeX.SX! Please make your code compilable (if possible) to form a complete minimal working example (MWE), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Dai Bowen Nov 25 '16 at 17:12
  • What does besides the graphics mean? Inside the colorbox? Outside it? – Ignasi Nov 25 '16 at 17:30
  • 1
    Does 'besides' mean 'in addition to' or 'to one side of' the graphic? – jon Nov 25 '16 at 17:55
4

There's no problem adding any text to a myfigure contents. So OP could use something like:

\begin{myfigure}{Title}
\centering \includegraphics[width=0.6\textwidth]{Graphic} 

\footnotesize{Subtext Line 1 \\ Subtext Line 2}
\end{myfigure}

but the result is not as desired because OP's myfigure contains option capture=hbox which means:

This is the default <mode> for \tcbox. The content cannot have a lower part and cannot be broken. The colored box is sized according to the dimensions of the content. A shortcut to set this mode is /tcb/hbox.

We have two solutions, use capture=hbox and include and manually format image and contents or change to capture=minipage (the default mode) and let tcolorbox do the work for us. With the second solution,

  • it's still possible (although manually) to adjust box width: width=...
  • it's possible to use the lower part of a tcolorbox for comments
  • option sidebyside moves comments from lower part to figure side

Following code shows a possible declaration for myfigure and how particular options change the defined behaviour.

\documentclass[a4paper]{article}
\usepackage[vmargin={2cm,2cm}]{geometry}
\usepackage[most]{tcolorbox}

\newtcolorbox[blend into=figures]{myfigure}[2][]{%
    float=htb,
    blend before title=colon hang,
    sharp corners,
    colback=white,
    colbacktitle=blue!30!black,
    title={#2},
    every float=\centering,
    halign=flush center,
    halign lower=flush center,
    lower separated=false,
    #1}

\begin{document}

\begin{myfigure}{A tcolorbox figure}
\includegraphics[height=4cm]{example-image}
\tcblower
This is a comment to the figure placed inside the colored box
\end{myfigure}

\begin{myfigure}[sidebyside]{A tcolorbox figure}
\includegraphics[height=4cm]{example-image}
\tcblower
This is a comment to the figure placed inside the colored box
\end{myfigure}

\begin{myfigure}[width=8cm]{A tcolorbox figure}
\includegraphics[height=4cm]{example-image}
\tcblower
This is a comment to the figure placed inside the colored box
\end{myfigure}
\end{document}

enter image description here

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.