6

I wish to customise my theorem style to something like the one shown, but I couldn,t figure a universal definition of parameters. Some suggestions?

enter image description here

The code:

\documentclass{article}
\usepackage{tikz}

\newcommand\Loadedframemethod{TikZ}
\usepackage[framemethod=\Loadedframemethod]{mdframed}
\tikzstyle{titregris} =
     [draw=gray, thick, fill=white, shading = exersicetitle, %
      text=black, rectangle, rounded corners, right,minimum height=.7cm]
\pgfdeclarehorizontalshading{exersicebackground}{100bp}
          {color(0bp)=(white); color(100bp)=(white!5)}
\pgfdeclarehorizontalshading{exersicetitle}{100bp}
          {color(0bp)=(white);color(100bp)=(black!5)}
\newcounter{exercise}
\renewcommand*\theexercise{Example:~\arabic{exercise}}
\makeatletter
\def\mdf@@exercisepoints{}%new mdframed key:
\define@key{mdf}{exercisepoints}{%
    \def\mdf@@exercisepoints{#1}
}
\mdfdefinestyle{exercisestyle}{%
  outerlinewidth=1em,outerlinecolor=white,%
  leftmargin=-1em,rightmargin=-1em,%
  middlelinewidth=1.2pt,roundcorner=5pt,linecolor=gray,
  apptotikzsetting={\tikzset{mdfbackground/.append style ={%
                       shading = exersicebackground}}},
  innertopmargin=1.2\baselineskip,
  skipabove={\dimexpr0.5\baselineskip+\topskip\relax},
  skipbelow={-1em},
  needspace=3\baselineskip,
  frametitlefont=\sffamily\bfseries,
  settings={\global\stepcounter{exercise}},
  singleextra={%
      \node[titregris,xshift=1cm] at (P-|O) %
         {~\mdf@frametitlefont{\theexercise}~};
      \ifdefempty{\mdf@@exercisepoints}%
      {}%
      {\node[titregris,left,xshift=-1cm] at (P)%
        {~\mdf@frametitlefont{\mdf@@exercisepoints points}~};}%
   },
  firstextra={%
      \node[titregris,xshift=1cm] at (P-|O) %
         {~\mdf@frametitlefont{\theexercise}~};
      \ifdefempty{\mdf@@exercisepoints}%
      {}%
      {\node[titregris,left,xshift=-1cm] at (P)%
        {~\mdf@frametitlefont{\mdf@@exercisepoints points}~};}%
   },
}
\makeatother


\begin{document}

\begin{mdframed}[style=exercisestyle]
Near what I want
\end{mdframed}

\end{document}
masu
  • 6,571
user21778
  • 269
  • 8
    Hi. See e.g.: mdframed. The package provides a lot of examples. You can also use the search function of tex.sx to find more examples. BTW: Your name irritates me. The typesetting system is written LaTeX. – Marco Daniel Feb 08 '13 at 21:20
  • 2
    Maybe another interesting package would be the thmbox-package. It doesn't exactly the style you showed as an example but something similar. – Stephan Lukasczyk Feb 09 '13 at 09:29
  • @MarcoDaniel, I have included my attempt in my question,I cant figure out how to do the line breaking on the sides. – user21778 Feb 12 '13 at 14:18

1 Answers1

6

I hope you've solved this already (because you posted this a while ago). If not, here are my two solutions:

  • A nonbreakable box using the environ package: \NewEnviron{sqbrrotnbr}
  • A breakable box using the tcolorbox package (instead of mdframed - it's a matter of taste (?)): \newenvironment{sqbrrotbr}

The output looks like this

\documentclass{article}

\usepackage{lipsum}                         % for the sake of demonstration
\usepackage[a5paper]{geometry}  % for the sake of demonstration

\usepackage{environ}
\usepackage{tikz}
    \usetikzlibrary{calc}
\usepackage[many]{tcolorbox}

\NewEnviron{sqbrrotnbr}[1]{
   \par\vspace{0.5\baselineskip}\noindent
   \begin{tikzpicture}
      \node (body) [
                text justified,
                text width=\textwidth-4pt-2ex,
                inner sep=0pt,
      ] {\BODY};
      \draw [
                line width=0.5pt,
                black,
      ] ($(body.south east)+( 5pt, 4pt)$) |-
                ($(body.south)     +( 0pt,-5pt)$) -|
                ($(body.south west)+(-5pt, 4pt)$)   
                ($(body.north west)+(-5pt, 0pt)$) |-
                ($(body.north)     +( 0pt,+9pt)$) -|
                ($(body.north east)+( 5pt, 0pt)$);
      \node [black,fill=white] at ($(body.north west)+(35pt,10pt)$) {\sffamily\bfseries #1};
   \end{tikzpicture}
   \par\vspace{0.25\baselineskip}
}

\newenvironment{sqbrrotbr}[1]{
    \par\vspace{0.5\baselineskip}
    \begin{tcolorbox}[
        blank,
        breakable,
        parbox=false,
        top=5pt,
        left=5pt,
        bottom=5pt,
        right=5pt,
        overlay first={
            \draw[
                    black,
                    line width=0.5pt,
            ] ($(interior.north west)+( 0pt,-5pt)$) |-
                ($(interior.north)     +( 0pt, 4pt)$) -|
                ($(interior.north east)+( 0pt,-5pt)$);
            \node [black,fill=white] at ($(interior.north west)+(40pt, 4pt)$) {\sffamily\bfseries #1};
            },
        overlay last={
            \draw[
                    black,
                    line width=0.5pt,
            ] ($(interior.south east)+( 0pt,10pt)$) |-
                ($(interior.south)     +( 0pt, 0pt)$) -|
                ($(interior.south west)+( 0pt,10pt)$);},
        ]{#1}
}{
    \end{tcolorbox}
    \par\vspace{0.5\baselineskip}
}

\begin{document}

\textbf{Sq}uare \textbf{Br}ackets \text{Rot}ated - \textbf{N}on-\textbf{br}eaking \hrulefill\\
\begin{sqbrrotnbr}{Title}
\lipsum[1]
\end{sqbrrotnbr}

\vspace{36pt}

\textbf{Sq}uare \textbf{Br}ackets \text{Rot}ated - \textbf{Br}eaking \hrulefill\\
\begin{sqbrrotbr}{Title}
\lipsum[3]
\end{sqbrrotbr}

\end{document}

Note: there are still some bad boxes I didn't look into.

David Carlisle
  • 757,742
masu
  • 6,571
  • how to make it as a theorem style for many other environment i.e. \begin { defi} ... \end{defi} \begin{lem} ... \end {lem} – Don Freecs Apr 05 '21 at 20:53