17

I found these beautiful box in Math ebooks which is created by Adobe Indesign, I tired mdframed, tcolorbox but I didn't try Tikz.

enter image description here enter image description here

enter image description here

So could someone create them using LaTeX please?

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}

\tcbset{
    lemmastyle/.style={enhanced, colback=white, colframe=blue!50, arc=0pt, 
                       fonttitle=\bfseries, description color=Maroon,  
                       colbacktitle=white, coltitle=DarkOliveGreen,    
                       top=\tcboxedtitleheight,
                       boxed title style={arc=0pt},
                       attach boxed title to top right={yshift=-\tcboxedtitleheight/3, 
                                                                                                      xshift=-2mm}%
                      },
}

\newtcbtheorem{myLemma}{Type Text Here Without counter }{lemmastyle}{thm}

\usepackage{pifont}

\begin{document}

\begin{myLemma}{}{}
\end{myLemma}
\end{document}

Update:

Thanks, but when I use the code of @Alenanno, the equation doesn't fit the box. It's wider than it. Even when I put long text, the box is still too tight. I tired to fix it but with no luck. Could you please try? And could you make it breakable? (I mean by 'breakable' that the contents can be broken between two pages if the box contains long text.)

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{amsmath,amssymb}%      pour les maths
\usepackage{enumitem}


\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{tikz}

\tcbset{
    lemmastyle/.style={enhanced, colback=white, colframe=blue!20, arc=0pt, 
                       fonttitle=\bfseries, description color=Maroon,  
                       colbacktitle=white, coltitle=DarkOliveGreen,    
                       top=\tcboxedtitleheight,
                       boxed title style={arc=0pt},
                       attach boxed title to top left={yshift=-\tcboxedtitleheight/2,
                                                       xshift=4mm}%
                      },
}

\newtcbtheorem{myLemma}{Long text here without counter }{lemmastyle}{thm}

\usetikzlibrary{calc, fit}



\newcommand{\mybox}[4][8cm]{
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\node[line width=0.5mm, rounded corners, text width=#1, draw=#2] (one) {\vspace{25pt}\\ #4};
\node[text=white,anchor=north east,align=center, minimum height=20pt] (two) at (one.north east) {#3};
\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=25pt, text height=2ex] (three) at (one.north east) {#3 \hspace*{.5mm}};
\end{tikzpicture} 
\end{figure}
}

\usepackage{pifont}

\begin{document}


\mybox[6cm]{green!70!black}{Long Fancy Title}{
\begin{enumerate}
\item Show that 
${\displaystyle 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 
${ \displaystyle \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}
}

\begin{myLemma}{}{}
\begin{enumerate}
\item Show that 
${\displaystyle 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 
${ \displaystyle \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{myLemma}

\mybox[6cm]{blue!70!black}{Very Very Long 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.}

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}

enter image description here

cfr
  • 198,882
Educ
  • 4,362
  • 2
    That the line breaks aren't added in the math expressions has nothing to do with Alenanno's code, but with yours. Use \biggl( ... \biggr) instead of \left( .. \right), and don't enclose the whole math expression in a pair of braces, i.e. don't write ${ ... }$, just $ ... $. Also, you likely want to have \text{ and } instead of \;\text{and}\;. – Torbjørn T. Dec 03 '15 at 21:42
  • i follow your advice but the box is still too tight. – Educ Dec 03 '15 at 23:30
  • Use tcolorbox or mdframed if you need breakable boxes. But, of course, you must ensure that the *content* is breakable. That has nothing to do with the box itself. – cfr Dec 03 '15 at 23:33
  • yeah but now i'm talking about the box is too tight – Educ Dec 03 '15 at 23:34
  • Those packages also offer you extensive customisation options. You can make the separation between content and border as tight or non-tight as you wish. See http://tex.stackexchange.com/questions/171951/how-was-this-tip-box-produced?rq=1 for a worked example which includes a lot of explanation and a breakable example. Note the use of mdframed for the breakable case. – cfr Dec 03 '15 at 23:38
  • In your code, you are simply making the box too narrow or the contents too wide, depending on your point of view. No solution can magically make wide stuff fit into a too-narrow box. Increase the width or put less or breakable content inside it. – cfr Dec 03 '15 at 23:40
  • Educ, please see the new edit. It should solve your problem with the equation. – Alenanno Dec 03 '15 at 23:41
  • cfr Thanks by the way the question that you gave it to me to see it was answered by the best latex designer @Gonzalo Medina – Educ Dec 03 '15 at 23:45
  • @Alenanno ok i'll – Educ Dec 03 '15 at 23:46

3 Answers3

20

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

enter image description here

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}
Alenanno
  • 37,338
  • Thanks but its to tight to put long text or long equation i tired to change the parameter of tikz bu no luck – Educ Dec 03 '15 at 19:54
  • @Educ well, give me an example of a long equation to put inside. Your first question was kind of vague for me, but I can improve it according to what you mean. – Alenanno Dec 03 '15 at 20:04
  • @Educ Added the new version. – Alenanno Dec 03 '15 at 23:42
14

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}

enter image description here

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}
Ignasi
  • 136,588
11

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} 

Result

sayyidd25
  • 166