![使用 shadowbox 创建练习形式](https://linux22.com/image/421832/%E4%BD%BF%E7%94%A8%20shadowbox%20%E5%88%9B%E5%BB%BA%E7%BB%83%E4%B9%A0%E5%BD%A2%E5%BC%8F.png)
使用以下代码
\documentclass[12pt,a4paper]{article}
\usepackage{amsfonts,amsmath,amssymb,graphicx}
\usepackage{tikz,tkz-tab,moreverb} % tableau de signe moreverb not needed
\usetikzlibrary{arrows}
\usepackage[francais]{babel}
\usepackage{pifont} %bouni
\usepackage{fancybox} %pour faire l'encadrement
\usepackage[latin1]{inputenc}
\usepackage{verbatim}
\usepackage{color}
\usepackage[final]{pdfpages} %pour inserer une page pdf
\usepackage{fancyhdr} % pagestyle
%---- Dimensions des marges ---
\usepackage{geometry}
\geometry{left=1.5cm,right=1.5cm,top=1.5cm,bottom=1.5cm}
%\usepackage{setspace}
%\onehalfspacing
%---- Structure Exercice -----
\newtheorem{Exc}{Exercice}
\def\exo#1{\futurelet\testchar\MaybeOptArgmyexoo}
\def\MaybeOptArgmyexoo{\ifx[\testchar \let\next\OptArgmyexoo
\else \let\next\NoOptArgmyexoo \fi \next}
\def\OptArgmyexoo[#1]{\begin{Exc}[#1]\normalfont}
\def\NoOptArgmyexoo{\begin{Exc}\normalfont}
\newcommand{\finexo}{\end{Exc}}
\newcommand{\flag}[1]{}
%%%%%%%%%%%%%%%% debut exercice %%%%%%%%%%%%%%%%%%%
%\exo{{}}:\\
%\finexo
%%%%%%%%%%%%%%%% fin exercice %%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\definecolor{sfaxlogo}{RGB}{127,176,206}
\colorlet{sfaxblue}{sfaxlogo!70!black!60!blue}
\begin{document}
%%%%%%%%%%%%%%%% debut exercice %%%%%%%%%%%%%%%%%%%
\exo{{}}:
\finexo
%%%%%%%%%%%%%%%% fin exercice %%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%% debut exercice %%%%%%%%%%%%%%%%%%%
\exo{{}}:
\finexo
%%%%%%%%%%%%%%%% fin exercice %%%%%%%%%%%%%%%%%%%
\end{document}
我明白了
如何获得以下形式的练习
答案1
这是 的一个很好的用例amsthm
,它允许您定义自定义定理样式。此外,\newcommand
普遍受到青睐\def
,它还允许对您想要的行为进行更清晰的定义:
\documentclass[12pt,a4paper]{article}
\usepackage{fancybox}
\usepackage{amsthm}
%any other packages
%---- Structure Exercice -----
\newtheoremstyle{sboxexc}% name of the style to be used
{\topsep}% measure of space to leave above the theorem. E.g.: 3pt
{\topsep}% measure of space to leave below the theorem. E.g.: 3pt
{\itshape}% name of font to use in the body of the theorem
{0pt}% of space to indent
{\bfseries}% name of head font
{}% punctuation between head and body
{ }% space after theorem head; " " = normal interword space
{\thmname{#1}}% Manually specify head
\newcounter{counter}
\setcounter{counter}{1}
\theoremstyle{sboxexc}
\newcommand{\optionaltext}{}
\newtheorem*{Exc}{\shadowbox{Exercice \arabic{counter}\optionaltext}}
\newcommand{\exo}[2][]{\renewcommand{\optionaltext}{#2}\begin{Exc}\normalfont $\:$}
\newcommand{\finexo}{\renewcommand{\optionaltext}{}\end{Exc}\addtocounter{counter}{1}}
\begin{document}
%%%%%%%%%%%%%%%% debut exercice %%%%%%%%%%%%%%%%%%%
\exo
Lorem
\finexo
%%%%%%%%%%%%%%%% fin exercice %%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%% debut exercice %%%%%%%%%%%%%%%%%%%
\exo{: optional extra text}
Lorem
\finexo
%%%%%%%%%%%%%%%% fin exercice %%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%% debut exercice %%%%%%%%%%%%%%%%%%%
\exo
Lorem
\finexo
%%%%%%%%%%%%%%%% fin exercice %%%%%%%%%%%%%%%%%%%
\end{document}
给予
看: