![如何获取附件 jpg 文件中样式的示例和解决方案](https://linux22.com/image/354599/%E5%A6%82%E4%BD%95%E8%8E%B7%E5%8F%96%E9%99%84%E4%BB%B6%20jpg%20%E6%96%87%E4%BB%B6%E4%B8%AD%E6%A0%B7%E5%BC%8F%E7%9A%84%E7%A4%BA%E4%BE%8B%E5%92%8C%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88.png)
如何获取如所附 jpg 文件带有边界的样式的示例和解决方案。
\documentclass{book}
\usepackage{graphicx,amssymb,amsmath}
\usepackage{exercise,chngcntr}
\counterwithin{Exercise}{chapter}
\counterwithin{Answer}{chapter}
\renewcounter{Exercise}[chapter]
\renewcommand{\theExercise}{\thechapter.\arabic{Exercise}}
\begin{document}
\begin{Exercise}
Prove that $ \frac{1}{2}\Delta(f_{ij}f^{ij}) =\nabla^{k}f^{ij}+f^{ij}f^{k}[2 \nabla_{i}R_{jk}-\nabla_{k}R_{ij}]$
\end{Exercise}
\begin{Answer}
Answer 2.2
\end{Answer}
\end{document}
答案1
我已经创建了新的环境Example
,将其放置Exercise
在 中tcolorbox
。
\documentclass{book}
\usepackage{graphicx,amssymb,amsmath}
\usepackage[lastexercise]{exercise}
\usepackage{chngcntr}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbset{arc=0mm,boxrule=1pt,colback=white,colframe=cyan,leftrule=3mm}
\counterwithin{Exercise}{chapter}
\counterwithin{Answer}{chapter}
\renewcounter{Exercise}[chapter]
\renewcommand{\theExercise}{\thechapter.\arabic{Exercise}}
\renewcommand{\AnswerHeader}{\medskip\noindent\textcolor{red}{\textbf{SOLUTION}}\;}
\renewcommand{\ExerciseName}{EXAMPLE}
\renewcommand{\ExerciseHeader}{\noindent\textbf{\ExerciseName\;\ExerciseHeaderNB}}
\newenvironment{Example}{\begin{tcolorbox}\begin{Exercise}}{\end{Exercise}\end{tcolorbox}}
\setlength{\ExerciseSkipBefore}{0pt}
\setlength{\AnswerSkipAfter}{\baselineskip}
\begin{document}
\chapter{My first set of exercises}
\begin{Example}
Prove that $\frac{1}{2}\Delta(f_{ij}f^{ij}) =\nabla^{k}f^{ij}+f^{ij}f^{k}[2\nabla_{i}R_{jk}-\nabla_{k}R_{ij}]$
\end{Example}
\begin{Answer}
From \dots
\end{Answer}
\begin{Example}
Prove that Paulinho is smart.
\end{Example}
\begin{Answer}
All ducks are smart. Paulinho is a duck. Therefore, Paulinho is smart.
\end{Answer}
\begin{Example}
Prove that Paulinho is smart.
\end{Example}
\begin{Answer}
All ducks are smart. Paulinho is a duck. Therefore, Paulinho is smart.
\end{Answer}
\chapter{My second set of exercises}
\begin{Example}
Prove that Paulinho is smart.
\end{Example}
\begin{Answer}
All ducks are smart. Paulinho is a duck. Therefore, Paulinho is smart.
\end{Answer}
\begin{Example}
Prove that Paulinho is smart.
\end{Example}
\begin{Answer}
All ducks are smart. Paulinho is a duck. Therefore, Paulinho is smart.
\end{Answer}
\end{document}
我希望这是您正在寻找的输出:
答案2
使用xsim
包装tcolorbox
(问题和答案来自CarLaTeX 的答案):
\documentclass{article}
\usepackage{xsim,tcolorbox,needspace}
\xsimsetup{
exercise/within = section ,
exercise/the-counter = \thesection.\arabic{exercise} ,
exercise/template = cyan-box ,
exercise/name = Example ,
solution/template = red ,
solution/print = true
}
\DeclareExerciseEnvironmentTemplate{cyan-box}
{%
\begin{tcolorbox}[arc=0mm,boxrule=1pt,colback=white,colframe=cyan,leftrule=3mm]
\textsf{%
\MakeUppercase{%
\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}%
}%
}%
\GetExercisePropertyT{subtitle}{ \textit{#1}}%
\quad
}
{\end{tcolorbox}}
\DeclareExerciseEnvironmentTemplate{red}
{%
\par
\Needspace*{2\baselineskip}
\noindent
\textsf{\textcolor{red}{\MakeUppercase{\XSIMmixedcase{\GetExerciseName}}}}%
\quad
}
{\par\bigskip}
\begin{document}
\section{My first set of exercises}
\begin{exercise}
Prove that $\frac{1}{2}\Delta(f_{ij}f^{ij})
=\nabla^{k}f^{ij}+f^{ij}f^{k}[2\nabla_{i}R_{jk}-\nabla_{k}R_{ij}]$
\end{exercise}
\begin{solution}
From \dots
\end{solution}
\begin{exercise}
Prove that Paulinho is smart.
\end{exercise}
\begin{solution}
All ducks are smart. Paulinho is a duck. Therefore, Paulinho is smart.
\end{solution}
\begin{exercise}
Prove that Paulinho is smart.
\end{exercise}
\begin{solution}
All ducks are smart. Paulinho is a duck. Therefore, Paulinho is smart.
\end{solution}
\section{My second set of exercises}
\begin{exercise}
Prove that Paulinho is smart.
\end{exercise}
\begin{solution}
All ducks are smart. Paulinho is a duck. Therefore, Paulinho is smart.
\end{solution}
\begin{exercise}
Prove that Paulinho is smart.
\end{exercise}
\begin{solution}
All ducks are smart. Paulinho is a duck. Therefore, Paulinho is smart.
\end{solution}
\end{document}