Inspired beautiful box from Indesign
Here's one way to do it with Tikz. I only tested it with regular text, but being a node, it should work with other graphic elements as well.
Edit: I have applied a fix for your equation (and possible future uses) by adding the varwidth
package and fixing the optional argument.
If the argument is not specified, the box will span the whole textwidth
. If you want to make it shorter, just add a value like \mybox[5cm]{...
as in the red box of the example.
Output
Code
\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amsmath,amssymb}% pour les maths
\usepackage{enumitem}
\usepackage{varwidth}
\usetikzlibrary{calc}
\newcommand{\mybox}[4][\textwidth-\pgfkeysvalueof{/pgf/inner xsep}-2mm]{%
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\node[line width=.5mm, rounded corners, draw=#2, inner ysep=10pt, text width=#1, outer sep=0] (one) {\vspace*{15pt}\\\begin{varwidth}{\textwidth}#4\end{varwidth}};
\node[text=white,anchor=north east,align=center, minimum height=20pt] (two) at (one.north east) {#3 \hspace*{.5mm}};
\path[fill=#2]
(one.north west|-two.west) --
($(two.west)+(-1.5cm,0)$)
to[out=0,in=180] (two.south west) --
(two.south east) [rounded corners] --
(one.north east) --
(one.north west) [sharp corners] -- cycle;
\node[text=white,anchor=north east,align=center, minimum height=20pt, text height=2ex] (three) at (one.north east) {#3 \hspace*{.5mm}};
\end{tikzpicture}
\end{figure}
}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae augue feugiat, ultrices nunc et, maximus nisl. Etiam in dolor id lacus semper luctus eu vitae sem. Pellentesque pharetra urna in magna sagittis dignissim. Morbi nec urna sagittis, eleifend erat id, varius est.
\mybox[5cm]{red!70!black}{Fancy Title}{Duis id dolor et ligula eleifend imperdiet. Mauris luctus, quam vitae viverra sagittis, dolor nibh imperdiet augue, eu venenatis eros augue et nisl. Vivamus nec fermentum est.}
\mybox{green!70!black}{Super Mega Ultra Long Fancy Title}{
\begin{enumerate}
\item Show that\\
$\displaystyle D_2f(x,y) = \frac{\partial {}}{\partial{y}} \biggl( \int_0^xg_1 (t,0) \ dt + \int_0^y g_2(x,s) \ ds \biggr)$
\item prove that\\
$\displaystyle \biggl(\forall x\in\mathbb{R} \biggr)\biggl(\forall y \in \mathbb{R} \biggr) x\neq y\, \text{ and } \, x+y \neq 2 \implies x^{2}-2x \neq y^2-2y$
\end{enumerate}}
Nullam libero augue, luctus et est vitae, fermentum aliquet libero. Maecenas dictum placerat eros, eu fermentum sem fermentum dapibus. Quisque non tellus nec magna feugiat luctus.
\end{document}
Following code shows how to define these boxes with tcolorbox
instead of TiKZ
(like in Alenanno's solution). This way boxes can break between pages.
\documentclass[a4paper]{article}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\makeatletter
\newtcolorbox{mytcbox}[2][]{%
enhanced,
breakable,
colback=white,
colframe=blue!30!black,
attach boxed title to top right={yshift=-2pt}, title={#2},
boxed title size=standard,
boxrule=0pt,
boxed title style={%
sharp corners,
rounded corners=northeast,
colback=tcbcol@frame,
boxrule=0pt},
sharp corners=north,
overlay unbroken={%
\path[fill=tcbcol@back]
([xshift=2pt]title.south west)
to[out=180, in=0] ([xshift=-1.5cm]title.west)--
(title.west-|frame.west) |-
([xshift=2pt]title.south west)--cycle;
\path[fill=tcbcol@frame] (title.south west)
to[out=180, in=0] ([xshift=-1.5cm]title.west)--
(title.west-|frame.west)
[rounded corners=\kvtcb@arc] |-
(title.north-|frame.north)
[sharp corners] -| (title.south west);
\draw[line width=.5mm, rounded corners=\kvtcb@arc,
tcbcol@frame]
(title.north east) rectangle
(frame.south west);
},
overlay first={%
\path[fill=tcbcol@back]
([xshift=2pt]title.south west)
to[out=180, in=0] ([xshift=-1.5cm]title.west)--
(title.west-|frame.west) |-
([xshift=2pt]title.south west)--cycle;
\path[fill=tcbcol@frame] (title.south west)
to[out=180, in=0] ([xshift=-1.5cm]title.west)--
(title.west-|frame.west)
[rounded corners=\kvtcb@arc] |-
(title.north-|frame.north)
[sharp corners] -| (title.south west);
\draw[line width=.5mm, rounded corners=\kvtcb@arc,
tcbcol@frame]
(frame.south west) |- (title.north) -|
(frame.south east);
},
overlay middle={%
\draw[line width=.5mm, tcbcol@frame]
(frame.north west)--(frame.south west)
(frame.north east)--(frame.south east);
},
overlay last={%
\draw[line width=.5mm, rounded corners=\kvtcb@arc,
tcbcol@frame]
(frame.north west) |- (frame.south) -|
(frame.north east);
},
#1
}
\makeatother
\begin{document}
\begin{mytcbox}{Long fancy title}
\begin{enumerate}
\item Show that
\[D_2f(x,y) = \frac{\partial{}}{\partial{y}} \left ( \int_0^xg_1 (t,0)\ dt + \int_0^y g_2(x,s)\ ds \right)\]
\item Prove that
\[\left(\forall x\in\mathbb{R} \right)\left(\forall y \in \mathbb{R} \right) x\neq y\, \text{and} \, x+y \neq 2 \implies x^{2}-2x \neq y^2-2y\]
\end{enumerate}
\end{mytcbox}
\begin{mytcbox}[width=6cm, colback=blue!20, colframe=red!70!black]{Long fancy title}
\lipsum[1-3]
\end{mytcbox}
\end{document}
Update: Code for v4.20
Since v4.20 tcolorboxes colors are documented (section 9.5) and can be easily used for overlay or underlay definitions. This change is incompatible with older versions code where low level names were used.
As an example, color for frames was internally named tcbcol@frame
and now is tcbcolframe
. Similar changes has to be applied to other colors.
Previous code updated to v4.20 looks like:
\documentclass[a4paper]{article}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\makeatletter
\newtcolorbox{mytcbox}[2][]{%
enhanced,
breakable,
colback=white,
colframe=blue!30!black,
attach boxed title to top right={yshift=-2pt}, title={#2},
boxed title size=standard,
boxrule=0pt,
boxed title style={%
sharp corners,
rounded corners=northeast,
colback=tcbcolframe,
boxrule=0pt},
sharp corners=north,
overlay unbroken={%
\path[fill=tcbcolback]
([xshift=2pt]title.south west)
to[out=180, in=0] ([xshift=-1.5cm]title.west)--
(title.west-|frame.west) |-
([xshift=2pt]title.south west)--cycle;
\path[fill=tcbcolframe] (title.south west)
to[out=180, in=0] ([xshift=-1.5cm]title.west)--
(title.west-|frame.west)
[rounded corners=\kvtcb@arc] |-
(title.north-|frame.north)
[sharp corners] -| (title.south west);
\draw[line width=.5mm, rounded corners=\kvtcb@arc,
tcbcolframe]
(title.north east) rectangle
(frame.south west);
},
overlay first={%
\path[fill=tcbcolback]
([xshift=2pt]title.south west)
to[out=180, in=0] ([xshift=-1.5cm]title.west)--
(title.west-|frame.west) |-
([xshift=2pt]title.south west)--cycle;
\path[fill=tcbcolframe] (title.south west)
to[out=180, in=0] ([xshift=-1.5cm]title.west)--
(title.west-|frame.west)
[rounded corners=\kvtcb@arc] |-
(title.north-|frame.north)
[sharp corners] -| (title.south west);
\draw[line width=.5mm, rounded corners=\kvtcb@arc,
tcbcolframe]
(frame.south west) |- (title.north) -|
(frame.south east);
},
overlay middle={%
\draw[line width=.5mm, tcbcolframe]
(frame.north west)--(frame.south west)
(frame.north east)--(frame.south east);
},
overlay last={%
\draw[line width=.5mm, rounded corners=\kvtcb@arc,
tcbcolframe]
(frame.north west) |- (frame.south) -|
(frame.north east);
},
#1
}
\makeatother
\begin{document}
\begin{mytcbox}{Long fancy title}
\begin{enumerate}
\item Show that
\[D_2f(x,y) = \frac{\partial{}}{\partial{y}} \left ( \int_0^xg_1 (t,0)\ dt + \int_0^y g_2(x,s)\ ds \right)\]
\item Prove that
\[\left(\forall x\in\mathbb{R} \right)\left(\forall y \in \mathbb{R} \right) x\neq y\, \text{and} \, x+y \neq 2 \implies x^{2}-2x \neq y^2-2y\]
\end{enumerate}
\end{mytcbox}
\begin{mytcbox}[width=6cm, colback=blue!20, colframe=red!70!black]{Long fancy title}
\lipsum[1-3]
\end{mytcbox}
\end{document}
Box with Tikz
\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[x11names,usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amsmath,amssymb}
\usepackage{enumitem}
\usetikzlibrary{calc}
%-----------
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
%----------
\definecolor{azzul}{RGB}{6,96,167}
%----------
\newcommand{\syBrisse}[6][\textwidth-\pgfkeysvalueof{/pgf/inner xsep}-4mm]{%
\begin{center}
\par\bigskip%
\begin{tikzpicture}
\node[rounded corners, text width=#1, align=justify, inner sep=8pt, outer sep=0] (one)
{\medskip\parbox[t]{\textwidth}{\vspace*{22pt}\par#6}};
\node[text=black,anchor=north east,align=center, minimum height=20pt, inner xsep=5pt] (two) at (one.north east) {#5 \hspace*{.5mm}};
\path[fill=#2,draw=#2]
($(one.north west)+(0ex,-4.5pt)$) [rounded corners=3pt] --
($(two.north west)+(-22pt,-4.5pt)$) --
($(two.south west)+(-4pt,0pt)$) [sharp corners] --
(two.south east) [rounded corners] --
(one.north east) --
(one.north west) [sharp corners] -- cycle;
\node[text=black,anchor=north west,align=center, minimum height=20pt, text height=2ex,inner sep=8pt, inner ysep=3pt] (three) at ($(one.north west)+(0,-3pt)$) {#4};
\node[text=white,anchor=north east,align=center, minimum height=20pt, inner sep=8pt,inner ysep=6.5pt] (for) at ($(one.north east)+(0,1.5pt)$) {#5\hspace*{0.8mm}};
\path[draw=#2,line width=0.8pt]
(one.south west) [rounded corners] --
(one.south east) [rounded corners] --
(one.north east) --
(one.north west) [rounded corners] -- cycle;
\foreach \x in {10,20,...,100}
\path[opacity=\x*0.01]
($(one.north west)+(0.4pt,-6.5pt+\x/100)$) [rounded corners=3pt,draw=gray!\x] --
($(two.north west)+(-23.3pt+\x/100,-6.5pt+\x/100)$) [rounded corners=3.5pt,draw=gray!\x] --
($(two.south west)+(-5.3pt+\x/100,-1.9pt+\x/100)$) --
($(two.south east)+(-0.4pt,-1.9pt+\x/100)$);
\path[draw=white,line width=1.1pt]
($(one.north west)+(0.4pt,-5.2pt)$) [rounded corners=3pt] --
($(two.north west)+(-22.3pt,-5.2pt)$) [rounded corners=3.5pt] --
($(two.south west)+(-4.3pt,-0.6pt)$) --
($(two.south east)+(-0.4pt,-0.6pt)$);
\begin{pgfonlayer}{background}
\path[fill=#3!5]
(one.south west) [rounded corners] --
(one.south east) [rounded corners] --
(one.north east) --
(one.north west) [rounded corners] -- cycle;
\path[opacity=0.5, top color=#3!5,bottom color=#3,middle color=#3!30]
(one.south west) [rounded corners] --
(one.south east) [sharp corners] --
($(one.south east)+(0ex,0.8cm)$) --
($(one.south west)+(0ex,0.8cm)$) [rounded corners] -- cycle;
\end{pgfonlayer}
\end{tikzpicture}
\end{center}
}
\begin{document}
\section{Cuadro con syBrisse}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae augue feugiat, ultrices nunc et, maximus nisl. Etiam in dolor id lacus semper luctus eu vitae sem. Pellentesque pharetra urna in magna sagittis dignissim. Morbi nec urna sagittis, eleifend erat id, varius est.
\syBrisse[10cm]{Crimson}{Crimson}{}{\bf Note:}{Duis id dolor et ligula eleifend imperdiet. Mauris luctus,~quam vitae viverra sagittis, dolor nibh imperdiet augue, eu venenatis eros augue et nisl. Vivamus nec fermentum est.}
\syBrisse{azzul}{azzul}{\it Text}{\bf Super Mega Ultra Long Fancy Title}{
\begin{enumerate}
\item Show that\\
$$\displaystyle D_2f(x,y) = \frac{\partial {}}{\partial{y}} \biggl( \int_0^xg_1 (t,0) \ dt + \int_0^y g_2(x,s) \ ds \biggr)$$
\item prove that\\
$$\displaystyle \bigl(\forall x\in\mathbb{R} \bigr)\bigl(\forall y \in \mathbb{R} \bigr) x\neq y\, \text{ and } \, x+y \neq 2 \implies x^{2}-2x \neq y^2-2y$$
\end{enumerate}
Nullam libero augue, luctus et est vitae, fermentum aliquet libero. Maecenas dictum placerat eros, eu fermentum sem fermentum dapibus.Quisque non tellus nec magna feugiat luctus.
}
Nullam libero augue, luctus et est vitae, fermentum aliquet libero. Maecenas dictum placerat eros, eu fermentum sem fermentum dapibus. Quisque non tellus nec magna feugiat luctus.
\end{document}