我对 LaTeX 还很陌生。我需要自定义颜色框,并获得了 @Gonzalo Medina 提供的出色自定义功能。我从这里获得了这个创建一个彩色盒子? 然后直接复制粘贴程序
我需要为示例添加标签,还需要假设宏以供引用。此外,我发现当 colorbox 运行到多个页面时,正文字体颜色(比如我想要红色)会更改为默认黑色。如何纠正这个问题。我使用了 \color{red} \Blindtext。这是更改文本字体颜色的正确方法吗?我发现它可以在同一页面上更改字体颜色,但对于多页 colorbox,文本颜色会重置为黑色。
\documentclass{article}
\usepackage[many]{tcolorbox}
\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}
\color{red} \Blindtext % Is this correct way to change font color??
\end{example}
\begin{assumption}
\color{red} \Blindtext % Is this correct way to change font color?
\end{assumption}
\end{document}
答案1
为每个框添加一个label
选项以供引用。在下面的代码中,我已将第二个强制参数添加到example
和assumption
定义中。可选参数可用于更改默认设置。
colupper
关于颜色问题,可以使用修复文本颜色的选项来解决。\color{red}
在这种情况下不应使用命令。
\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{blindtext}
\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,
colupper=red,
}
}
\newtcolorbox[auto counter,number within=section]{example}[2][]{
mystyle,
title=Example~\thetcbcounter,
label=#2,
#1
}
\newtcolorbox[auto counter]{assumption}[2][]{
mystyle,
colback=white,
rightrule=0pt,
toprule=0pt,
title=Assumption SLR.\thetcbcounter,
label=#2,
#1
}
\begin{document}
\section{Test section}
\begin{example}{A}
\Blindtext % Is this correct way to change font color??
\end{example}
As you can see in \ref{A} \dots
\begin{assumption}[colupper=myblue!50!red]{B}
\Blindtext % Is this correct way to change font color?
\end{assumption}
\end{document}