1

I would like to create an environment for my definitions or properties, like that:

enter image description here

\noindent
\begin{tikzpicture}
\matrix [anchor=west,inner xsep=0pt] at (0,0)
    {
    \node
        [text width=4cm,inner xsep=0ex,inner ysep=1ex,text=Maroon,fill=Tan] (titre)
        {\quad {Définition 1} : a long title }; \\
    \node
        [anchor=north west,fill=white!40!Tan,draw=none,text justified,inner xsep=1em, inner ysep=1em,
        text width=\columnwidth-2em-1pt,text=Maroon] (texte)
        {some text} ;\\
    };
    \draw [line width=1pt, color=Maroon,rounded corners=5pt](titre.south west)--(titre.north west)--(titre.north east)--(titre.south east);
    \draw [line width=1pt, color=Maroon,rounded corners=0pt](titre.south east)--(texte.north east)--(texte.south east)--
    (texte.south east)--(texte.south west)--(titre.south west);
\end{tikzpicture}

and I want to adjust the width of the first node to the width of the title, because something like that happens with long title :

enter image description here

I tried with the \widthof command, the \def command, the width option inside tikz ... anyway, nothing works. My environment is this one :

\newcounter{definition}
\NewEnviron{definition}[1]{
\stepcounter{definition}
\noindent
\begin{tikzpicture}[x=1.0cm,y=1.0cm, scale=1, every node/.style={scale=1}]
\matrix [anchor=west,inner xsep=0pt] at (0,0)
    {
    \node
        [text width={width("\quad \textbf{Définition} \thedefinition #1")},inner xsep=0ex,inner ysep=1ex,text=Maroon,fill=Tan] (titre)
        {\quad \textbf{Définition} \thedefinition\ #1}; \\
    \node
        [anchor=north west,fill=white!40!Tan,draw=none,text justified,inner xsep=1em, inner ysep=1em,
        text width=\columnwidth-2em-1pt,text=Maroon] (texte)
        {\BODY};
    };
    \draw [line width=1pt, color=Maroon,rounded corners=5pt](titre.south west)--(titre.north west)--(titre.north east)--(titre.south east);
    \draw [line width=1pt, color=Maroon,rounded corners=0pt](titre.south east)--(texte.north east)--(texte.south east)--
    (texte.south east)--(texte.south west)--(titre.south west);
\end{tikzpicture}
}

Thanks a lot.

  • 1
    What happens if you don't specify the text width at all? – Torbjørn T. Feb 6 '17 at 12:08
  • Do you know tcolorbox? – Schweinebacke Feb 6 '17 at 12:09
  • yes I know (a little bit) this package ... but I would like to know how to do what I need here. I try the first solution, it seems to be good but I have errors with the newenvironment. I try to figure it out. – Stan Feb 6 '17 at 12:31
  • ok, it's perfect without specifying text width. Thanks. – Stan Feb 6 '17 at 12:41
3

Although, it seems that OP is not interested in a tcolorbox version for this format, may be someone else want it.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\usepackage[dvipsnames]{xcolor}
\usepackage[most]{tcolorbox}

\tcbset{
    defstyle/.style={
        enhanced, 
        colback=Tan!40, 
        colbacktitle=Tan, 
        colframe=Maroon, 
        colupper=Maroon, 
        coltitle=Maroon,
        sharp corners, 
        attach boxed title to top left={yshift=-.5mm}, 
        boxed title style={
            skin=enhancedfirst jigsaw,
            boxrule=.5mm,
            bottom=-.5mm}, 
        }
    }

\newtcbtheorem{Definition}{Définition}{defstyle}{def}

\begin{document}

\begin{Definition}{My title}{}
Some text
\end{Definition}

\begin{Definition}{This is a longer title}{}
Some text
\end{Definition}
\end{document}

enter image description here

  • yes, that's I have now in a different way. That's very interesting with this solution. Thanks a lot. I'll try it with tikz pictures inside, to see if this box doesn't deform the picture (I have to use \savebox \usebox for this at this time). – Stan Feb 7 '17 at 8:41
  • @Stan Please, take a look a tcolorbox documentation and you will see how you can draw any tikzpicture inside a tcolorbox and you don't have to use \savebox and \usebox. In any case if you explain this "new problem", may be we can help ;-) – Ignasi Feb 7 '17 at 8:49
  • Thank you. I knew tcolorbox but I didn't have "so much time" to learn about it (I spent time with tikz). But I'm going to read the book now (p150 at this time ;-) ). It's working fine with my tikz picture too. That's a great solution. – Stan Feb 7 '17 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.