创建针对特定问题的环境

创建针对特定问题的环境

如何创建类似于下图的环境?请帮忙。

在此处输入图片描述

答案1

在此处输入图片描述

这是使用推入边缘的tcolorbox包来实现此目的的一种方法。\tcbox

\documentclass{article}

\usepackage{tcolorbox}
\usepackage{amsmath,amssymb}  % needed for \dotsb and \mathbb
\usepackage{blindtext} % needed for filler text from \blindtext

\newcounter{example}
\newenvironment{example}{%
    \tcbox[
        enlarge left by=-10em,
        left=0mm,
        right=0mm,
        top=0mm,
        bottom=0mm,
        sharp corners,
        colback=black!30,
        colframe=black!20]
        {Example \refstepcounter{example}\theexample.}
    \vspace{-2em}\noindent
}{%
    \\
}

\begin{document}
    \blindtext
    
    \begin{example}
        Let \(p\) and \(q\) be distinct odd primes.
        Prove that the equation
        \[x_1^2 - x_2^2 + x_3^2 - x_4^2 + \dotsb + x_p^2 = 1\]
        has \(q^{p-1} + q^{\frac{p-1}{2}}\) solutions in \((\mathbb{Z}/q\mathbb{Z})^p\).
        Deduce a new proof of the quadratic reciprocity law.
        
        \hfill [Wouter Castryck]
    \end{example}
    
    \blindtext
    
    \addtocounter{example}{10}
    \begin{example}
        Here is an example with a higher counter value.
    \end{example}
    
    \blindtext
\end{document}

相关内容