我恳请您帮助我实现重新创建下面这个精美盒子的目标。
我尝试使用以下代码:
\documentclass[openany]{book}
\usepackage[many]{tcolorbox}
\usepackage{tikz}
\definecolor{mybrown}{HTML}{B35823}
\definecolor{myorange}{HTML}{ED8C2B}
\newtcolorbox[auto counter]{myex}[2][]{enhanced,
colframe=white,colback=white,colbacktitle=yellow,breakable,
fonttitle=\bfseries,coltitle=black,right=1mm,
overlay={\draw[gray,rounded corners](0.32,78pt)--(340pt,78pt)--(340pt,55pt)--(0.32,55pt)--cycle;
\draw[gray,rounded corners](340pt,66.5pt)--(350pt,66.5pt)--(350pt,-50pt);
},
attach boxed title to top left={xshift=0.3cm,yshift=-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},
boxed title style={enhanced,arc=0pt,outer arc=5pt,colframe=mybrown,interior code={
\node[anchor=west,fill=myorange,minimum height=0.4cm,inner ysep=0pt,rounded corners=3pt](a) at ([xshift=-8pt]interior.east){\color{white}\thetcbcounter};
}
},
title={\color{white}Example},#1}
\begin{document}
\begin{myex}{}
You are provided with substance Q which contains two cations and two anions. Carry out the following tests on Q and identify the cations and anions in it. Identify any gas(es) evolved. Record your results in the table below.
\end{myex}
\end{document}
它给了我下面的图像,但离我需要的相差甚远。
答案1
要绘制示例线,请参见下面的改编Ignasi 的解决方案. 按键:
- 忽略
title
- 将所需的节点放入
overlay
部分中 - 按照你喜欢的方式将这些节点与其位置关联起来:我使用了锚点和移位
但是,当您向环境中添加更多文本时,您会看到代码中仍然存在问题。例如,取消注释两条 lipsum 行。问题可能与您在覆盖层内绘制额外线条的方式有关。
参见此处的两条 Lipsum 线:
\documentclass[openany]{book}
\usepackage[many]{tcolorbox}
%\usepackage{tikz}
\definecolor{mybrown}{HTML}{B35823}
\definecolor{myorange}{HTML}{ED8C2B}
%\usepackage{lipsum}
% ~~~~~~~~~~~~~~~~~~~~~
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\newtcolorbox[auto counter]{myex}[2][]{%
enhanced, %
colframe=white,colback=white,colbacktitle=yellow,breakable,%
fonttitle=\bfseries,coltitle=black,right=1mm,%
overlay={%
% ~~~ borders, as OP defined them ~~~~~~~~~~~~
\draw[gray,rounded corners]%
(0.32,78pt)--(340pt,78pt)--(340pt,55pt)--(0.32,55pt)--cycle;%
\draw[gray,rounded corners]%
(340pt,66.5pt)--(350pt,66.5pt)--(350pt,-50pt);%
% ~~~ new version of title ~~~~~~~~
% Example
\node[anchor=south west,
xshift=2.6mm,
yshift=-2.3mm,
minimum width=28mm,
minimum height=7mm,
fill=mybrown,
text=white,
rounded corners,
font=\bfseries\sffamily,
] (EX) at (frame.north west) {Example};
% Counter
\node[anchor=east,
xshift=-4pt,
fill=orange,
text=white,
rounded corners,
font=\bfseries\sffamily,
] (NN) at (EX.east) {\thetcbcounter};
% Subheader
\node[anchor=west,
red,
font=\bfseries\sffamily,
] (SUB) at (EX.east) {#2};
},%
%
%
% attach boxed title to top left={%
% xshift=0.3cm,yshift=-\tcboxedtitleheight/2,%
% yshifttext=2mm-\tcboxedtitleheight/2%
% },%
% boxed title style={%
% enhanced,arc=0pt,outer arc=5pt,colframe=mybrown,%
% interior code={%
% \node[anchor=west,fill=myorange,%
% minimum height=0.4cm,inner ysep=0pt,%
% rounded corners=3pt] (a) at%
% ([xshift=-14pt]interior.east)%
% {\color{white}\thetcbcounter};%
% }%
% },%
% title={\color{white}Example\ \ \ \ },#1
}
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}
\begin{myex}{Rewriting something}
You are provided with substance Q which contains two cations and two anions. Carry out the following tests on Q and identify the cations and anions in it. Identify any gas(es) evolved. Record your results in the table below.
%\lipsum[1]
\end{myex}
\end{document}