1

Please see page 424 of the tcolorbox manual. How can I put text in front of the ribbon, but 45 degrees rotated?

See example enter image description here

Their code is

\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{patterns}
% \usetikzlibrary{patterns} % preamble
% \tcbuselibrary{skins} % preamble

\begin{document}
\tcbset{frogbox/.style={enhanced,colback=green!10,colframe=green!65!black,
enlarge top by=5.5mm,
overlay={\foreach \x in {2cm,3.5cm} {
\begin{scope}[shift={([xshift=\x]frame.north west)}]
\path[draw=green!65!black,fill=green!10,line width=1mm] (0,0) arc (0:180:5mm);
\path[fill=black] (-0.2,0) arc (0:180:1mm);
\end{scope}}}]}}
\tcbset{ribbon/.style={overlay app={%
\path[fill=blue!75!white,draw=blue,double=white!85!blue,
preaction={opacity=0.6,fill=blue!75!white},
line width=0.1mm,double distance=0.2mm,
pattern=fivepointed stars,pattern color=white!75!blue]
([xshift=-0.2mm,yshift=-1.02cm]frame.north east)
-- ++(-1,1) -- ++(-0.5,0) -- ++(1.5,-1.5) -- cycle;}}}
\begin{tcolorbox}[frogbox,title=My title]
This is a \textbf{tcolorbox}.
\end{tcolorbox}
\begin{tcolorbox}[frogbox,ribbon,title=My title]
This is a \textbf{tcolorbox}.\par
Here, we apply a second overlay.
\end{tcolorbox}
\end{document}
2
  • 5
    Let me insist in my comment to one of your previous questions
    – Ignasi
    Apr 23, 2018 at 7:40
  • 1
    Such fragments are not really useful! The text in front of the ribbon should be MWE not text only ;-)
    – user31729
    Apr 23, 2018 at 11:57

1 Answer 1

4

Just set a node on an appropriate part of the ribbons \path and shift it into the middle of the ribbon. The option slope takes care of the rotation. I also added a new option for the ribbon text. You can set a default text, the position is marked tin the source.

The result:

enter image description here

The code:

\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{patterns}
% \usetikzlibrary{patterns} % preamble
% \tcbuselibrary{skins} % preamble

\begin{document}
\tcbset{frogbox/.style={%
    enhanced,
    colback=green!10,
    colframe=green!65!black,
    enlarge top by=5.5mm,
    overlay={\foreach \x in {2cm,3.5cm} {
        \begin{scope}[shift={([xshift=\x]frame.north west)}]
            \path[draw=green!65!black,fill=green!10,line width=1mm] (0,0) arc (0:180:5mm);
            \path[fill=black] (-0.2,0) arc (0:180:1mm);
        \end{scope}}}}}

\tcbset{%
ribbon text/.store in=\ribbontext,
ribbon text={}, % <------ set default text here
ribbon/.style={overlay app={%
    \path[%
        fill=blue!75!white,
        draw=blue,
        double=white!85!blue,
        preaction={opacity=0.6,fill=blue!75!white},
        line width=0.1mm,
        double distance=0.2mm,
        pattern=fivepointed stars,
        pattern color=white!75!blue]
        ([xshift=-0.2mm,yshift=-1.02cm]frame.north east) --
            ++(-1,1) --
            ++(-0.5,0) -- node[sloped,yshift=1.76777mm,inner sep=0,node font=\footnotesize] {\ribbontext}
            ++(1.5,-1.5) -- cycle;}}}

\begin{tcolorbox}[frogbox,title=My title]
This is a \textbf{tcolorbox}.
\end{tcolorbox}

\begin{tcolorbox}[frogbox,ribbon,title=My title,ribbon text=Text]
This is a \textbf{tcolorbox}.\par
Here, we apply a second overlay.
\end{tcolorbox}
\end{document}

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.