tcolorbox 角落中的节点,其周围有“环绕”的文本

tcolorbox 角落中的节点,其周围有“环绕”的文本

我使用 tcolorbox 包来制作带标题的框。我将标题节点放在框的右上角,但它覆盖了示例的文本。我怎样才能制作一个框,标题节点在右上角,文本“环绕”在它周围,这样示例的文本在到达节点时就会停止并进入换行符。我给出了一个最小的例子

\documentclass[14pt]{extbook}%
\usepackage[most]{tcolorbox}

\usepackage{array}

 \tikzstyle{titlenode} =
 [draw=black, thick, scale=.7, fill=red,% 
line width=0.1pt, text=black, rectangle,
font=\Large,
left, minimum height=1cm]

\newtcolorbox{boxexample}[2][]{%
enhanced,
%oversize,
colback=white,
boxrule=.5pt,
colframe=black,
top=6mm,
bottom=6mm,
enlarge top by=\baselineskip/2+1mm,
enlarge top at break by=0mm,pad at break=2mm,
fontupper=\normalsize,
overlay unbroken and first={%
\node[titlenode] (B)
at ([xshift=0cm,yshift=-.7cm]frame.north east)
  {\strut\setlength{\extrarowheight}{-30.5pt}\textbf{$\begin{array}{c}
\hline
\rule{0pt}{2ex}
\mbox{Example}
\\
\mbox{#2}
\rule{0pt}{1.5ex}
\end{array}$}};},
breakable,
arc=0pt,outer arc=0pt,
#1}%

\begin{document}

\begin{boxexample}{One}
The text of the example is overlayed by the node of the title in the right-corner...
The text of the example is overlayed by the node of the title in the right-corner
\end{boxexample} 

\end{document}

使用 xelatex 编译器获得的结果

在此处输入图片描述

更新

Thanks to @David Carlisle, I obtain boxed examples, with text wrapped around the title node,
with the command "0pt \dimexpr \hsize-3cm\relax", which is not very far from my aim. Clearly,
 I doesn'nt want to write the commands...
 "\parshape 4
    0pt \dimexpr \hsize-3cm\relax
    0pt \dimexpr \hsize-3cm\relax
    0pt \dimexpr \hsize-3cm\relax
    0pt \hsize" 
at every beginning of example. 
How can I write a macro which inserts automatically the command \parshape 4, 
and 3 lines with the command "0pt \dimexpr \hsize-3cm\relax" at the beginning of each
example ?...

I give the tex file I use

\documentclass[14pt]{extbook}%
\usepackage[most]{tcolorbox}

\usepackage{array}

 \tikzstyle{titlenode} =
 [draw=blue, thick, scale=.7, fill=red,% 
line width=1pt, text=black, rectangle,
font=\Large,
left, minimum height=1cm]

\newcounter{example}

    \newtcolorbox[auto counter,
        number within=section,
        number freestyle={\noexpand\arabic{section}\noexpand\alph{\tcbcounter}}]{example}[1][]{%
    enhanced,top=0mm,left=2pt,right=2pt,
    enlarge top by=\baselineskip/2+1mm,enlarge top at break by=0mm,pad at break=2mm,fontupper=\normalsize,
      overlay unbroken and first={%
at ([xshift=-6pt,yshift=-27pt]frame.north east)
      {\strut\setlength{\extrarowheight}{-30.5pt}\textbf{$\begin{array}}
    \hline
    \rule{0pt}{2ex}
    \mbox{Example}
    \\
    \mbox{\Large\thetcbcounter}
    \rule{0pt}{1.5ex}
    \end{array}$}};
    },
breakable,before=\par\smallskip\vspace{-10pt}\centering,arc=0pt,
outer arc=0pt,colframe=green,colback=white,
width=\textwidth, 
#1}

\begin{document}
\setcounter{section}{1}

\begin{example}
\parshape 4
0pt \dimexpr \hsize-3cm\relax
0pt \dimexpr \hsize-3cm\relax
0pt \dimexpr \hsize-3cm\relax
0pt \hsize
The text of the example is not overlayed by the node of the title   in      the right-corner...
The text of the example is not overlayed by the node of the title in the right-corner...
The text of the example is not overlayed by the node of the title in the right-corner
\end{example} 

\end{document}

它是用 xelatex 编译的 在此处输入图片描述

答案1

如果我运行您的示例,我不会得到顶线,但这会增加剪切:

\documentclass[14pt]{extbook}%
\usepackage[most]{tcolorbox}

\usepackage{array}

 \tikzstyle{titlenode} =
 [draw=black, thick, scale=.7, fill=red,% 
line width=0.1pt, text=black, rectangle,
font=\Large,
left, minimum height=1cm]

\newtcolorbox{boxexample}[2][]{%
enhanced,
%oversize,
colback=white,
boxrule=.5pt,
colframe=black,
top=6mm,
bottom=6mm,
enlarge top by=\baselineskip/2+1mm,
enlarge top at break by=0mm,pad at break=2mm,
fontupper=\normalsize,
overlay unbroken and first={%
\node[titlenode] (B)
at ([xshift=0cm,yshift=-.7cm]frame.north east)
  {\strut\setlength{\extrarowheight}{-30.5pt}\textbf{$\begin{array}{c}
\hline
\rule{0pt}{2ex}
\mbox{Example}
\\
\mbox{#2}
\rule{0pt}{1.5ex}
\end{array}$}};},
breakable,
arc=0pt,outer arc=0pt,
#1}%

\begin{document}

\begin{boxexample}{One}
\parshape 3
0pt \dimexpr \hsize-3cm\relax
0pt \dimexpr \hsize-3cm\relax
0pt \hsize
The text of the example is overlayed by the node of the title in the right-corner...
The text of the example is overlayed by the node of the title in the right-corner
\end{boxexample} 

\end{document}

输出

相关内容