# How to construct a coloured box with rounded corners

Here is the specs of the box.

1. Color of the bar rule should be:

\definecolor{mycolor}{rgb}{0.122, 0.435, 0.698}

2. Radius of the 4 corners of the box: 4pt

3. Thick line = 0.5pt
4. Text should be 6pt indention on all sides
-

Have a look at the mdframed package:

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

\definecolor{mycolor}{rgb}{0.122, 0.435, 0.698}

\newmdenv[innerlinewidth=0.5pt, roundcorner=4pt,linecolor=mycolor,innerleftmargin=6pt,
innerrightmargin=6pt,innertopmargin=6pt,innerbottommargin=6pt]{mybox}

\begin{document}

\lipsum[2]
\begin{mybox}
\lipsum[4]
\end{mybox}
\lipsum[2]

\end{document}


-
How to remove the space after this nice box please ? I dont have the same space above and below this box. –  Terriguest Sep 14 '14 at 21:50

The tcolorbox package does a beautiful job of setting coloured boxes:

\documentclass{article}
\usepackage{tcolorbox}% http://ctan.org/pkg/tcolorbox
\definecolor{mycolor}{rgb}{0.122, 0.435, 0.698}% Rule colour
\makeatletter
\newcommand{\mybox}[1]{%
\setbox0=\hbox{#1}%
\setlength{\@tempdima}{\dimexpr\wd0+13pt}%
\begin{tcolorbox}[colframe=mycolor,boxrule=0.5pt,arc=4pt,
left=6pt,right=6pt,top=6pt,bottom=6pt,boxsep=0pt,width=\@tempdima]
#1
\end{tcolorbox}
}
\makeatother
\begin{document}
\mybox{Here is some fancy box text.}
\end{document}


The tcolorbox options are:

1. color=mycolor
2. arc=4pt
3. boxrule=0.5pt
4. left=6pt, right=6pt, top=6pt, bottom=6pt

The macro \mybox will always set the box on a single line. If you want more than one line, some changes are required. To remove the background colour, add the option colback=white.

-
Hi Werner, Do you know how to fix this? Runaway argument? { title/.store in=\kvtcb@title , notitle/.style={title=}, adjusted ti\ETC. ! Paragraph ended before \pgfkeys@@qset was complete. <to be read again> \par l.87 parskip/.style={before={\par \pagebreak[0]\noindent},after={\par}}, ? –  jeecabz Aug 7 '12 at 5:53
@jee-ar: What code caused this? Are you adding a title to tcolorbox? –  Werner Aug 7 '12 at 14:14
@ werner: no, this is the error comes out when I try to use your given code/tag. –  jeecabz Aug 8 '12 at 3:56
@jee-ar: You need to embrace the \mybox command with \makeatletter ... \makeatother. –  Werner Aug 8 '12 at 4:22
@ werner: thanks. It is now working. I just modify the tcoolbox package. But If I want to include section, subsection, paragraph - It does not work. –  jeecabz Aug 8 '12 at 5:35

I come here looking for the answer to the same question. I wanted it to look nice as well, have colour on the inside too, but unfortunately when trying to implement the suggestions above it didn't seem to work for multiple lines.

What I did was go to the tcolorbox manual http://get-software.net/macros/latex/contrib/tcolorbox/tcolorbox.pdf and had a quick read through the beginning. It tells you how to make very nice looking textboxes very quickly (all of which with rounded corners).

The simplest thing to do is just to include the \usepackage{tcolorbox} and then where you want the coloured textbox you just type

\begin{tcolorbox}
A physical explanation the \emph{dynamic matrix}\\
lots of text\\
a new line\\
equation
$$%\label{eq:dynamic_diag} \nonumber \bm C \bm D \bm C^{\dagger}=\bm \Omega = \left(\begin{array}{cccc} \omega^2_1 & 0 & ... & 0\\ 0 & \omega^2_2 & ... & 0\\ \vdots & & \ddots & \vdots \\ 0 & 0 & ... & \omega^2_{Nd} \end{array}\right),$$
where $\bm C$ is a unitary matrix (each column is one of the eigenvectors of the dynamic matrix $\bm D$), $Nd$ is the product of the number of particlces, $N$, and the number of dimensions, $d$.
\end{tcolorbox}


Which gives you something like

One can also customise it, either with "[options]" after the the "\begin{tcolorbox}" or one can create a "mybox" environment. So, if I want it to be a clear red background with a darker red frame then I type

\usepackage{tcolorbox} \newtcolorbox{mybox}{colback=red!5!white,colframe=red!75!black}

where the "newtcolorbox" creates a new environment, "mybox" is the name, "colback" is the background colour of the box, "colframe" is the colour of the frame. See the manual for a huge number of further customisations. Then include the "mybox" environment somewhere in the tex document

\begin{mybox}
A physical explanation the \emph{dynamic matrix}\\
lots of text\\
a new line\\
equation
$$%\label{eq:dynamic_diag} \nonumber \bm C \bm D \bm C^{\dagger}=\bm \Omega = \left(\begin{array}{cccc} \omega^2_1 & 0 & ... & 0\\ 0 & \omega^2_2 & ... & 0\\ \vdots & & \ddots & \vdots \\ 0 & 0 & ... & \omega^2_{Nd} \end{array}\right),$$
where $\bm C$ is a unitary matrix (each column is one of the eigenvectors of the dynamic matrix $\bm D$), $Nd$ is the product of the number of particlces, $N$, and the number of dimensions, $d$.
\end{mybox}


Which gives you something like:

It looks really cool! Adding titles to the boxes is straightforward too. This time use \newtcolorbox{mybox}[1]{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,title=#1}, where the "1" means one argument is to be expected after "\begin{mybox}", "fonttitle" is the font type and "title=#1" tell it that the first argument after "\begin{mybox}" is the title, i.e.

\begin{mybox}{A physical explanation of the \emph{dynamic matrix}}

This looks like

-
Welcome to TeX-SX ! very nice answer. Also I would kindly draw your attention to these questions too; does-it-matter-if-i-use-textit-or-it-bfseries-or-bf-etc and also a related one will-two-letter-font-style-commands-bf-it-ever-be-resurrected-in-latex –  percusse Apr 21 '14 at 16:38
Hehe, you make a good point! I should have used \emph or \textit instead of \it... I'll change it now. –  gloriphobia Apr 22 '14 at 14:16

Since version 2.02 (2013/03/13), the package tcolorbox contains the \tcbox and \newtcbox (version 2.22) macros which allow to give an alternative answer. I also added some text around the box example to demonstrate the usage of the option tcbox raise base.

\documentclass{article}
\usepackage{tcolorbox}
\definecolor{mycolor}{rgb}{0.122, 0.435, 0.698}

\newtcbox{\mybox}{nobeforeafter,colframe=mycolor,colback=mycolor!10!white,boxrule=0.5pt,arc=4pt,
boxsep=0pt,left=6pt,right=6pt,top=6pt,bottom=6pt,tcbox raise base}

\begin{document}
Some text. \mybox{Here is some fancy box text.} More text.
\end{document}


-
I had to add the options nobeforeafter to get the box inline like your picture. –  Nate Glenn Jul 8 '13 at 5:41
@NateGlenn Thank you for this hint! The version I used had a bug which is eliminated now. Therefore, nobeforeafter has to be set. I corrected the the example. Thanks again! :-) –  Thomas F. Sturm Jul 8 '13 at 6:35
No problem! Thanks for showing me that this distribution allows inline text boxing. I had been searching for it for a while. –  Nate Glenn Jul 8 '13 at 20:30