TransWikia.com

Create a form of an exercise with shadowbox

TeX - LaTeX Asked by Schüler on January 17, 2021

With the following codes

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}
defexo#1{futurelettestcharMaybeOptArgmyexoo}
defMaybeOptArgmyexoo{ifx[testchar letnextOptArgmyexoo
                        else letnextNoOptArgmyexoo fi next}
defOptArgmyexoo[#1]{begin{Exc}[#1]normalfont}
defNoOptArgmyexoo{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}

I get

enter image description here

How can get the exercises with the following form

enter image description here

One Answer

This is a good use case for amsthm, which lets you define a custom theorem style. Also, newcommand is generally favored over def, it also allows a much cleaner definition of the behavior you want:

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}

Gives

enter image description here

See:

Correct answer by Plant on January 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP