3

I am using the text box with title, which was replied by @Alenanno at Inspired beautiful box from Indesign.

In this title is designed as right-justified. Can somebody make it left-justified.

\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}
2
  • This code uses tcolorbox or TiKZ but not mdframed. This code show three different boxes, which one do you want to change?
    – Ignasi
    Commented Nov 24, 2016 at 9:54
  • Thanks @Ignasi, for pointing out. I want to change the title of \mybox command Commented Nov 24, 2016 at 10:03

2 Answers 2

4

Alenanno's mybox is defined with TiKZ commands. It can be defined using tcolorbox which allows breakable boxes between pages.

enter image description here

\documentclass[a4paper]{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}

\makeatletter
\newtcolorbox{mytcbox}[2][]{%
enhanced, 
breakable,
colback=white,
colframe=blue!30!black,
attach boxed title to top left={yshift=-2pt}, title={#2},
boxed title size=standard,
boxrule=0pt,
boxed title style={%
    sharp corners, 
    rounded corners=northwest, 
    colback=tcbcolframe, 
    boxrule=0pt},
sharp corners=north,
overlay unbroken={%
    \path[fill=tcbcolback] 
        ([xshift=-2pt]title.south east) 
        to[out=0, in=180] ([xshift=1.5cm]title.east)--
        (title.east-|frame.east) |- 
        ([xshift=-2pt]title.south east)--cycle;
    \path[fill=tcbcolframe] (title.south east) 
        to[out=0, in=180] ([xshift=1.5cm]title.east)--
        (title.east-|frame.east)
        [rounded corners=\kvtcb@arc] |- 
        (title.north-|frame.north) 
        [sharp corners] -| (title.south east);
    \draw[line width=.5mm, rounded corners=\kvtcb@arc, 
        tcbcolframe] 
        (title.north west) rectangle 
        (frame.south east);
}, 
overlay first={%
    \path[fill=tcbcolback] 
        ([xshift=-2pt]title.south east) 
        to[out=0, in=180] ([xshift=1.5cm]title.east)--
        (title.east-|frame.east) |- 
        ([xshift=-2pt]title.south east)--cycle;
    \path[fill=tcbcolframe] (title.south east) 
        to[out=0, in=180] ([xshift=1.5cm]title.east)--
        (title.east-|frame.east)
        [rounded corners=\kvtcb@arc] |- 
        (title.north-|frame.north) 
        [sharp corners] -| (title.south east);
    \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}
\lipsum[1-12]
\end{mytcbox}

\begin{mytcbox}[colframe=blue!70!black, colback=red!20, width=.75\linewidth]{Even Longer fancy title}
\lipsum[1]
\end{mytcbox}

\begin{mytcbox}[colback=white]{Title}
\lipsum[1]
\end{mytcbox}

\end{document}

Note Previous code has been updated for compatibility with tcolorbox v4.20. If you're using previous versions, rename colors with form tcbcol... to older form tcbcol@....

2
  • +1. This should be the accepted answer. It's much (much) better than mine (which I did mostly to help the OP but I didn't like it). I flagged the OP to change it, hopefully he/she will. Commented Nov 25, 2016 at 18:40
  • Thanks to both ignasi and Guilherme for showing excellent ways. Really a lot is there to study. Commented Nov 26, 2016 at 13:46
5

You need to rebuild the path done inside the \mybox command:

\usetikzlibrary{calc, fit, backgrounds}
\usepackage{varwidth}
\newcommand{\mybox}[4][\textwidth-\pgfkeysvalueof{/pgf/inner xsep}-2mm]{%
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\node[line width=0.5mm, inner ysep=10pt, text width=#1, outer sep=0] (text) {\begin{varwidth}{\textwidth}#4\end{varwidth}};
\node[text=white, above right, align=left] (title) at (text.north west) {#3};
\node[fit=(title) (text), line width=0.5mm, rounded corners, draw=#2, inner sep=0pt] (box){};
\begin{scope}[on background layer]
\fill[#2] (title.south west) -- (title.south east) to[out=0, in=180] ([xshift=1.5cm]title.east) -- (title.east-|box.north east) [rounded corners] -- (box.north east) -- (box.north west) [sharp corners] -- cycle;
\end{scope}
\end{tikzpicture} 
\end{figure}
}

I also used the backgrounds library to avoid repeating the white node, and the fit library + vardiwdth package to make the box more flexible.

enter image description here

1
  • @RamaKrishnaMajety, consider changing the accepted answer to Ignasi's, that's' definetly better. Commented Nov 25, 2016 at 18:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .