# Troubles with tikzset

I tried to do a box with round corners and a title with tikz to do some definitions, properties,...

I tried this

\tikzset{mybox/.style={draw=black, thick,rectangle, rounded corners, inner sep=10pt, inner ysep=10pt}}
\tikzset{titlebox/.style={fill=white, text=black,thick,draw=black}}

\newcommand{\tikzboxb}[2]{%
\begin{tikzpicture}%
\node[mybox] (box){%
\begin{minipage}{0.96\linewidth}%
#2%
\end{minipage} };%
\node[titlebox] at (box.north west) {%
#1%
};%
\end{tikzpicture}%
}

\begin{document}

\tikzboxb{Propriété}{

\begin{center}
\begin{tikzpicture}[scale=0.3]
\draw (0,0)--(8,1)--(4,5)--cycle;
\end{tikzpicture}
\end{center}

}


and even this

\begin{tikzpicture}%
\begin{minipage}{0.96\linewidth}%
\begin{tikzpicture}[scale=0.3]
\draw (0,0)--(8,1)--(4,5)--cycle;
\end{tikzpicture}
\end{minipage} };%
\node[fill=white, text=black,thick,draw=black , right=10pt] at (box.north west) {Propriété};%
\end{tikzpicture}


The result is

In both case there is a problem. In the first case, the box doesn't look like I want which is the case with the second test.

In both case the triangle s have round corners !

It seems that the style I defined for the node (and only for It) was used for all the drawings.

I tried so many changes that I am exhausted and I need some help.

Thanks, Benoît

• Welcome ! I have some quick remarks for you, maybe it will help. 1- Nesting tikzpictures is to be avoided, it is probably part of your problem. 2 - You may not know about it but the tcolorbox package proposes a very easy way to achieve what you want ;). 3 - In general on this site, it is better to post compilable codes so that people can reproduce you issue easily without having to guess the packages / parameters you use ! Hope this helps – BambOo Sep 25 '18 at 9:33
• 1-2- do you mean that I have to use tcolorbox rather than tikzpicture to do my specific box ? Or that I do not have to use tikz ? I suppose the first one is correct. I am not a specialist and I had in mind to limit the number of package I use and avoid conflict between them. I will try with It to check. 3- sorry for that point but I am using personal class and package. Next time I will send a complete and compilable code. – Benoit Sep 25 '18 at 15:30

With the tcolorbox package, you can get what you want. Here is a box with an optional argument that by default displays the word Propriété.

I have reproduced approximately your box, it is possible to modify the colors of the frame, the title, in fact everything because everything is configurable.

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage[most]{tcolorbox}

% title style "mybox"
\tcbset{titlebox/.style={boxed title style={colframe=black,colbacktitle=white,sharp corners,boxrule=.6pt,boxsep=1.5pt}}}

% box creating the box "mybox"
\newtcolorbox{mybox}[1][Propriété]{
titlebox,arc=7pt,width=0.95\textwidth,
colframe=black,colbacktitle=white,coltitle=black,colback=white,
center,boxrule=0.6pt,
enhanced,nobeforeafter,
attach boxed title to top left={yshift=-3mm,xshift=18pt},
title=#1}

\begin{document}

\begin{mybox}
\begin{center}
\begin{tikzpicture}[scale=0.3]
\draw (0,0)--(8,1)--(4,5)--cycle;
\end{tikzpicture}
\end{center}
\end{mybox}
\bigskip

\begin{mybox}[Définition]
\begin{center}
\begin{tikzpicture}[scale=0.3]
\draw[fill=green!50] (0,0)--(8,1)--(4,5)--cycle;
\end{tikzpicture}
\end{center}
\end{mybox}
\end{document}

• I was ready to find a solution with this new package and you did It. Thank you. – Benoit Sep 25 '18 at 15:40
• Thank you so much, I just modify some details to put your code in my class file and It works perfectly. – Benoit Sep 25 '18 at 15:53
• @Benoit I am glad that this answer is useful to you. In this case, it is customary to accept it, see: tex.stackexchange.com/help/someone-answers – AndréC Sep 25 '18 at 16:46
• It is done. It was my first question on tex.stackexchange.com and I didn't know how It works. – Benoit Sep 27 '18 at 2:22

As BambOo pointed out, and as discussed here, nesting tikzpictures is to be avoided. Your example also shows why that is: the pgfkeys like rounded corners of the outer tikzpicture will be applied to the inner tikzpicture. Putting the inner tikzpicture in a \savebox will, as explained here, avoid this.

\documentclass{article}
\usepackage{tikz}
\tikzset{mybox/.style={draw=black, thick,rectangle, rounded corners, inner sep=10pt, inner ysep=10pt}}
\tikzset{titlebox/.style={fill=white, text=black,thick,draw=black}}

\newcommand{\tikzboxb}[2]{%
\begin{tikzpicture}%
\node[mybox] (box){%
\begin{minipage}{0.96\linewidth}%
#2%
\end{minipage} };%
\node[titlebox] at (box.north west) {%
#1%
};%
\end{tikzpicture}%
}
\newsavebox\picbox
\sbox\picbox{\begin{tikzpicture}[scale=0.3]
\draw (0,0)--(8,1)--(4,5)--cycle;
\end{tikzpicture}}
\begin{document}

\tikzboxb{Propri\'et\'e}{

\begin{center}
\usebox\picbox
\end{center}

}
\end{document}


• Thank you so much for the solution, the advices and the explanation. My english is not as good as I would like and I didn't find any message about this inheritage of tikzpicture. I will try with tcolorbox. – Benoit Sep 25 '18 at 15:39