5

I want to use an outline to my figures using tcolorbox. everything works fine until I add the command "\caption" in the title. Someone could help me fix the error.

\documentclass[openany,spanish,10pt, letterpaper]{memoir}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{anysize}
\marginsize{3cm}{2cm}{2cm}{2cm}
\usepackage{amsmath}
\usepackage{float}
\usepackage{polyglossia}
\setdefaultlanguage{spanish}
\usepackage{pgfgantt}
\usepackage[many]{tcolorbox}
\usepackage{varwidth}
\usepackage{xcolor}

\begin{document}
\begin{figure}

\begin{tcolorbox}[enhanced,title={\caption{TEST.\caption{a}}},
colframe=red,colback=white,colbacktitle=white,
fonttitle=\bfseries,coltitle=black,attach boxed title to top center=
{yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},         boxed title style={boxrule=0.5mm,
frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west)
-- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east)
-- (frame.south east) -- (frame.south west) -- cycle; },
interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west)
-- (interior.north west) -- (interior.north east)
-- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west)
-- cycle;}  }]
 \centering
 \includegraphics{example-image-a}
 \end{tcolorbox}    
 \end{figure}

 TEST \ref{a}

 \end{document}
  • Besides containing \par, \caption requires maximum width, which \tcolorbox does not provide. – John Kormylo Mar 10 '16 at 5:14
4

One of solutions is to emulate caption, something like this:

title={\refstepcounter{figure}
       Fig. \thefigure: TEST TEST TEST TEST
       \label{fig:a}
       },% <---
       % or Figure or whatever emulate
       % your figure captions style

With this you will obtain:

enter image description here

4

Another solution is to use the blend into=figures option for new tcolorbox environments.

For example:

\documentclass[openany,spanish,10pt, letterpaper]{memoir}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{anysize}
\marginsize{3cm}{2cm}{2cm}{2cm}
\usepackage{amsmath}
\usepackage{float}
\usepackage{polyglossia}
\setdefaultlanguage{spanish}
\usepackage{pgfgantt}
\usepackage[many]{tcolorbox}
\usepackage{varwidth}
\usepackage{xcolor}

\newtcolorbox[blend into=figures]{myfigure}[2][]{enhanced,
  float=tbp,title={#2},
  colframe=red,colback=white,colbacktitle=white,
  fonttitle=\bfseries,coltitle=black,
  attach boxed title to top center={yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},
  boxed title style={boxrule=0.5mm,
    frame code={\path[tcb fill frame] ([xshift=-4mm]frame.west)
    -- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east)
    -- (frame.south east) -- (frame.south west) -- cycle; },
    interior code={\path[tcb fill interior] ([xshift=-2mm]interior.west)
    -- (interior.north west) -- (interior.north east)
    -- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west)
    -- cycle;}  },#1}

\begin{document}

  \begin{myfigure}[label=a,center upper]{Test}
    \includegraphics{example-image-a}
  \end{myfigure}

  TEST \ref{a}

\end{document}

This gives:

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.