3

I'd like to define a tcolorbox that write a title on the top of a picture below. However, I can't manage to put the title on top of the content, it's always behind:

What I get: enter image description here

What I want: enter image description here

MWE:

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\begin{document}
\begin{tcolorbox}[enhanced,skin=enhanced jigsaw,attach boxed title to bottom center,title=Hello,
attach boxed title to bottom center={yshift=\tcboxedtitleheight}]
  \lipsum[4]
\end{tcolorbox}
\end{document}
2
  • 1
    Just curiosity, why do you want to cover part of your text with the title?
    – Ignasi
    Commented Nov 7, 2017 at 8:43
  • Because in real life, I want to put a banner on top of a picture. And for now the banner is behind the picture...
    – tobiasBora
    Commented Nov 8, 2017 at 1:53

1 Answer 1

5

I think you'll have to use finish option to draw a node like the title over the text.

Look at section "9.4 drawing scheme" in tcolorbox documentation to see in which order are all box elements drawn. The text is always the last one, even over overlays. The only option is finish code (section 10.9).

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\begin{document}
\begin{tcolorbox}[enhanced,skin=enhanced jigsaw,attach boxed title to bottom center,title=Hello,
attach boxed title to bottom center={yshift=\tcboxedtitleheight},
finish={\node[draw=red, rounded corners, fill=red!30, anchor=south, minimum size=2cm] at (frame.south) {Hello};}]
  \lipsum[4]
\end{tcolorbox}
\end{document}

enter image description here

5
  • 2
    i wonder what is advantage that title box cover part of box content :-)
    – Zarko
    Commented Nov 7, 2017 at 8:40
  • @Zarko I also don't understand it, we should ask OP.
    – Ignasi
    Commented Nov 7, 2017 at 8:42
  • Hum interesting, thank you ! Here it's not really the title that you move up, but you just add on top of it a block, but I like the idea. I guess that if I want to use a tcolor box, I can also put a tcolorbox in the tikz node to simulate the title shape. Thank you! And I want to use that because in my project behind it's not a text, but a picture, that I want to cover with a picture.
    – tobiasBora
    Commented Nov 8, 2017 at 2:04
  • @Ignasi : by the way, do you know how to get the tcolor full box width to that the title fill the whole box? I tried to use \tcbtextwidth, but it's a bit smaller than the box.
    – tobiasBora
    Commented Nov 8, 2017 at 3:31
  • @tobiasBora How to obtain a framed image with a banner partially covering it is a different question because no text is involved. I think there exist others solutions with tcolorbox or tikz so, please, open a new question clearly explaining what you would like to obtain.
    – Ignasi
    Commented Nov 8, 2017 at 8:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .