Re: Aiuto creare ambiente teoremi personalizzati

#66674
Up
0
Down
::


Per il fatto dei colori, dipende chi è il tuo lettore, soprattutto quanti anni ha. 🙂 Per materiale universitario eviterei certamente, ma per dispense scolastiche perché no? Basta che i colori siano tenui e tutto stia in armonia. Ma altri possono argomentarti con forza certamente maggiore della mia.

Ho dato una sistemata al codice:
`\documentclass{article}

\usepackage{mdframed,lipsum,tikz}

\makeatletter
% #1: il nome dell'ambiente (es: teorema)
% #2: il colore (es: blue!20)
% #3: il titolo del teorema (es: di Pitagora)
\newenvironment{mdfthm}[3]{%
\expandafter\let\expandafter\mdframedtitleenv\csname @mdfthm@titenv@#1\endcsname
\stepcounter{#1}%
\ifstrempty{#3}%
{\mdfsetup{frametitle={\strut}}}%
{\mdfsetup{frametitle={:~#3}}}%
\begin{mdframed}[innertopmargin=0pt,linecolor=#2,%
linewidth=2pt,topline=false,]%
}{\end{mdframed}}

% Argomenti:
% #1: il nome dell'ambiente (es: teorema)
% #2: il titolo dell'ambiente (es: Teorema)
% #3: il colore (es: blue!20)
% #4: il titolo del teorema (es: di Pitagora)
\newcommand{\@mdfthm@titenv}[4]{%
\@afterindentfalse
{\parindent \z@
\setlength{\parfillskip}{\z@ plus 1fil}%
\mdraggedtitle\nobreak
\makebox[\linewidth][l]{%
\hspace*{-1\mdf@innerleftmargin@length}%
\rlap{\color{white}%
\hspace*{-1\mdf@middlelinewidth@length}%
\rule[\mdf@middlelinewidth@length]%
{\dimexpr\linewidth+1\mdf@innerleftmargin@length
+\mdf@innerrightmargin@length
+2\mdf@middlelinewidth@length\relax}%
{\dimexpr\ht\strutbox+.3333em\relax}}%
\rlap{\color{#3}%
\rule{\dimexpr\linewidth+\mdf@innerleftmargin@length%
+\mdf@innerrightmargin@length\relax}%
{\mdf@middlelinewidth@length}}%
\hspace*{-1\mdf@middlelinewidth@length}%
\tikz[remember picture,baseline]%
\node[draw = none, text = black, fill = #3]%
{\mdf@frametitlefont\strut #2~\@nameuse{the#1}#4};\relax}%
\par\kern.5\baselineskip}%
\@afterheading}

% Argomenti:
% #1: il nome dell'ambiente (es: teorema)
% #2: il titolo dell'ambiente (es: Teorema)
% #3: il colore (es: blue!20)
\newcommand\mdfnewtheorem[3]{%
\newcounter{#1}[section]%
\newenvironment{#1}[1][]{%
\begin{mdfthm}{#1}{#3}{##1}}{\end{mdfthm}}%
\@namedef{@mdfthm@titenv@#1}{%
\@mdfthm@titenv{#1}{#2}{#3}}}
\makeatother

\mdfnewtheorem{teorema}{Teorema}{blue!20}
\mdfnewtheorem{definizione}{Definizione}{green!20}

\begin{document}
\begin{teorema}[di pitagora]
\lipsum[3]
\end{teorema}
\begin{teorema}
\lipsum[2]
\end{teorema}
\begin{definizione}[di insieme]
\lipsum[4]
\end{definizione}
\begin{definizione}
\lipsum[6]
\end{definizione}
\end{document}`

Noto però che c’è un’imperfezione sul lato superiore del disegno, e c’è anche nel codice originario (non ce l’ho messa io!). Servirebbe un esperto di TikZ per capirne il perché.

Ciao,
Antonio

Go to top