我在自由文本数学站点。我想在 latex 使用mdframed
和tcolorbox
包中模仿这些样式和结构。
\documentclass{article}
\usepackage{graphicx}
\usepackage[most]{tcolorbox}
% Define a new environment for LibreTexts-style math
\newtcolorbox{libremath}[1][]{
colframe=blue!30,
colback=white,
rounded corners,
title={#1},
attach title to upper,
coltitle=blue!70,
boxed title style={
colframe=blue!30,
colback=white,
outer arc=0pt,
},
fonttitle=\bfseries,
before upper={\parindent0pt},
after=\par\smallskip,
}
\begin{document}
\begin{libremath}[]
\includegraphics[width=1cm]{example-image-a}
Solve the equation for $x$:
\[ ax^2 + bx + c = 0 \]
\end{libremath}
\end{document}
答案1
首先要说的是:
\documentclass{article}
\usepackage{graphicx}
\usepackage[most]{tcolorbox}
\usepackage{fontawesome}
% Define a new environment for LibreTexts-style math
\newtcolorbox{libremath}[2][]{
enhanced,
colframe=green!30!black,
colback=green!20,
sharp corners,
attach boxed title to top left={yshift*=-\tcboxedtitleheight},
title={\faCubes~#2},
toprule=0pt, rightrule=0pt,bottomrule=0pt,
coltitle=white,
colbacktitle=green!30!black,
boxed title style={
sharp corners,
},
fonttitle=\bfseries,
#1
}
\begin{document}
\begin{libremath}{some title}
\includegraphics[width=1cm]{example-image-a}
Solve the equation for $x$:
\[ ax^2 + bx + c = 0 \]
\end{libremath}
\end{document}
更新
由于所有框都遵循类似的设计,因此它们可以采用通用样式但具有特定颜色和名称。接下来是每种框的定义及其特定的颜色、图标和名称。
定义和定理使用newtcbtheorem
定义,它们将有两个强制参数,即定理标题和标签后缀。两者都可以声明为空,但必须出现。
\documentclass{article}
\usepackage{graphicx}
\usepackage[most]{tcolorbox}
\usepackage{fontawesome}
% Define a new environment for LibreTexts-style math
\tcbset{
libretext/.style={
enhanced,
sharp corners,
attach boxed title to top left={yshift*=-\tcboxedtitleheight},
colframe=#1!30!black,
colback=#1!20,
colbacktitle=#1!30!black,
toprule=0pt, rightrule=0pt, bottomrule=0pt,
coltitle=white,
fonttitle=\bfseries,
boxed title style={sharp corners}
}
}
\newtcolorbox[auto counter, number within=section]{example}[1][]{
libretext=blue,
title={\faCheck~Example~\thetcbcounter},
#1,
}
\newtcolorbox[auto counter, number within=section]{exercise}[1][]{
libretext=blue,
title={\faQuestion~Exercise~\thetcbcounter},
#1,
}
\newtcolorbox{caution}[1][]{
libretext=red,
title={\faHandPaperO~Caution},
#1,
}
\newtcolorbox{note}[1][]{
libretext=gray,
title={\faThumbTack~Note},
#1,
}
\newtcbtheorem[auto counter, number within=section]{theorem}{Theorem}{
libretext=green,
before title={\faCubes~}
}{th}
\newtcbtheorem[auto counter, number within=section]{definition}{Definition}{
libretext=green,
before title={\faPencil~}
}{df}
\begin{document}
\section{First section}
\begin{theorem}{}{}
Solve the equation for $x$:
\[ ax^2 + bx + c = 0 \]
\end{theorem}
\begin{example}
Solve the equation for $x$:
\[ ax^2 + bx + c = 0 \]
\end{example}
\begin{definition}{Relative Frequency}{}
Solve the equation for $x$:
\[ ax^2 + bx + c = 0 \]
\end{definition}
\begin{caution}
Solve the equation for $x$:
\[ ax^2 + bx + c = 0 \]
\end{caution}
\begin{note}
Solve the equation for $x$:
\[ ax^2 + bx + c = 0 \]
\end{note}
\begin{exercise}
Solve the equation for $x$:
\[ ax^2 + bx + c = 0 \]
\end{exercise}
\end{document}