请参阅第 424 页tcolorbox
手动的。如何将文本放在功能区前面,但旋转 45 度?
他们的代码是
\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}
答案1
只需在丝带的适当部分设置一个节点\path
,然后将其移至丝带的中间即可。该选项slope
负责旋转。我还为丝带文本添加了一个新选项。您可以设置默认文本,位置在源中标记。
结果:
代码:
\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}