谁能用乳胶代码帮助我如何创建如下图所示的框?
第二个框是
我尝试使用包{tcolorbox},但没有成功。我想用那个颜色创建一个与图 1 完全相同的盒子!我想在图 1 中自动编号“Assumption SLR. xx”,在图 2 中自动编号“Example 1.xxx”
谢谢
答案1
改良版:
\documentclass{article}
\usepackage[many]{tcolorbox}
\usetikzlibrary{calc}
\definecolor{myblue}{RGB}{0,163,243}
\tcbset{mystyle/.style={
breakable,
enhanced,
outer arc=0pt,
arc=0pt,
colframe=myblue,
colback=myblue!20,
attach boxed title to top left,
boxed title style={
colback=myblue,
outer arc=0pt,
arc=0pt,
top=3pt,
bottom=3pt,
},
fonttitle=\sffamily
}
}
\newtcolorbox[auto counter,number within=section]{example}[1][]{
mystyle,
title=Example~\thetcbcounter,
overlay unbroken and first={
\path
let
\p1=(title.north east),
\p2=(frame.north east)
in
node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1]
at (title.east) {#1};
}
}
\newtcolorbox[auto counter]{assumption}[1][]{
mystyle,
colback=white,
rightrule=0pt,
toprule=0pt,
title=Assumption SLR.\thetcbcounter,
overlay unbroken and first={
\path
let
\p1=(title.north east),
\p2=(frame.north east)
in
node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1]
at (title.east) {#1};
}
}
\begin{document}
\section{Test section}
\begin{example}
test
\end{example}
\begin{assumption}
test
\end{assumption}
\begin{example}[Optional title]
test
\end{example}
\begin{assumption}[Optional title with some more words for the example so it spans two lines]
test
\end{assumption}
\end{document}
结果:
第一个版本:
一种可能性是:
\documentclass{article}
\usepackage[many]{tcolorbox}
\definecolor{myblue}{RGB}{0,163,243}
\tcbset{mystyle/.style={
breakable,
enhanced,
outer arc=0pt,
arc=0pt,
colframe=myblue,
colback=myblue!20,
attach boxed title to top left,
boxed title style={
colback=myblue,
outer arc=0pt,
arc=0pt,
},
title=Example~\thetcbcounter,
fonttitle=\sffamily
}
}
\newtcolorbox[auto counter,number within=section]{example}[1][]{
mystyle,
title=Example~\thetcbcounter,
}
\newtcolorbox[auto counter]{assumption}[1][]{
mystyle,
title=Assumption SLR.\thetcbcounter,
}
\begin{document}
\section{Test section}
\begin{example}
test
\end{example}
\begin{assumption}
test
\end{assumption}
\end{document}
输出:
我对示例和假设使用了相同的风格,但如果您还想重现其他风格,只需进行简单的修改即可:
\documentclass{article}
\usepackage[many]{tcolorbox}
\definecolor{myblue}{RGB}{0,163,243}
\tcbset{mystyle/.style={
breakable,
enhanced,
outer arc=0pt,
arc=0pt,
colframe=myblue,
colback=myblue!20,
attach boxed title to top left,
boxed title style={
colback=myblue,
outer arc=0pt,
arc=0pt,
},
title=Example~\thetcbcounter,
fonttitle=\sffamily
}
}
\newtcolorbox[auto counter,number within=section]{example}[1][]{
mystyle,
title=Example~\thetcbcounter,
}
\newtcolorbox[auto counter]{assumption}[1][]{
mystyle,
colback=white,
rightrule=0pt,
toprule=0pt,
title=Assumption SLR.\thetcbcounter,
}
\begin{document}
\section{Test section}
\begin{example}
test
\end{example}
\begin{assumption}
test
\end{assumption}
\end{document}
输出: