
我使用 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}