我正在尝试创建这些环境,但没有取得太大成功...我想知道使用 tikz 创建它是否更好,或者自定义 tcolorbox 的标题并稍微旋转它是否更容易?
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{tikz,tikzpagenodes}
\usepackage[most]{tcolorbox}
\usetikzlibrary{calc}
\usetikzlibrary{intersections, patterns}
\tcbuselibrary{skins}
\usepackage{lipsum}
\usepackage{xcolor,etoolbox}
\definecolor{lightblue}{RGB}{199,232,250}
\definecolor{darkblue}{RGB}{59,134,215}
\begin{document}
\begin{tikzpicture}[overlay,remember picture]
% container
\draw[fill=darkblue,draw=none] (0,0) -- ++(5cm,0) -- ++(0,1cm)
arc (0:90:0.5) -- ++(-4.5cm,0) -- cycle;
% Horizontal line
\draw[darkblue, line width=2pt] (0,0) -- (\textwidth,0);
% title of container
\node[scale=1.2] at (0.2cm,0.2cm) {\textcolor{white}{Environment
Title }};
\end{tikzpicture}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
答案1
我提出的另一个答案与@Ignasi 给出的答案非常相似但不完全相同:
(根据@TeXnician 提出的与顶线垂直移动相关的改进进行了重新编辑)
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage[most]{tcolorbox}
\usetikzlibrary{calc}
\tcbuselibrary{skins}
\usepackage{xcolor}
\definecolor{titleboxcolor}{RGB}{199,232,250}
\definecolor{darkblue}{RGB}{59,134,215}
\newcommand{\titlepath}{
\fill[titleboxcolor]
(title.south east)
--(title.east)coordinate(A)
to[curve to,out=90,in=0]($(A)+(-5mm,5mm)$)
--($(title.north west)+(5mm,0mm)$)coordinate(B)
to[curve to,out=180,in=90]($(B)+(-5mm,-5mm)$)coordinate(C)
--($(C)+(0mm,-5mm)$)
to[curve to,out=90,in=180]($(title.south west)+(+5mm,0mm)$)coordinate(F)
--cycle;
\draw[titleboxcolor,ultra thick]
([yshift=.5\pgflinewidth]title.south east)--
([yshift=.5\pgflinewidth]title.south-|interior.east);
}
\newtcolorbox{myenvironment}{
enhanced,
frame empty,
title=Exercice résolu,
colback=white,
coltitle=red,
attach boxed title to top left={xshift=-5mm},
boxed title style={empty},
underlay boxed title=\titlepath
}
\begin{document}
\begin{myenvironment}
Soit \(f\) une fonction définie sur ...
\end{myenvironment}
\end{document}
答案2
开始工作:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\makeatletter
\newtcolorbox{mybox}[2][]{
enhanced,
breakable,
sharp corners,
rounded corners=northwest,
colback=white,
colframe=orange!80!black,
fonttitle=\bfseries\large\sffamily,
frame hidden,
title=#2,
attach boxed title to top left,
boxed title size=standard,
boxed title style={%
empty,
rounded corners=north,
boxrule=0pt,
bottom=0pt,
},
underlay boxed title={%
\filldraw[rounded corners=\kvtcb@arc, orange!80!black, line width=.5mm]
(title.south east)--++(93:\tcboxedtitleheight)--++(183:\tcboxedtitlewidth)--++(-87:\tcboxedtitleheight)|-cycle;
\draw[tcbcolframe, line width=.5mm] (title.south)|-(frame.north east);
},
#1
}
\makeatother
\begin{document}
\begin{mybox}{Exercice résolu}
\lipsum[2]
\end{mybox}
\end{document}
笔记先前的代码已更新,以兼容 tcolorbox v4.20。如果您使用的是先前版本,请将颜色形式重命名tcbcol...
为旧形式 tcbcol@...
。