60

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
jeecabz
  • 1,448

4 Answers4

72

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
\begin{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),
\end{equation}
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

Picture of tcolorbox created with default settings

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
\begin{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),
\end{equation}
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: Picture of tcolorbox created with mybox environment

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

Picture of tcolorbox with title

gloriphobia
  • 821
  • 6
  • 4
43

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

enter image description here

\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.

Werner
  • 603,163
  • 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. \par l.87 parskip/.style={before={\par \pagebreak[0]\noindent},after={\par}}, ? – jeecabz Aug 07 '12 at 05:53
  • @jee-ar: What code caused this? Are you adding a title to tcolorbox? – Werner Aug 07 '12 at 14:14
  • @ werner: no, this is the error comes out when I try to use your given code/tag. – jeecabz Aug 08 '12 at 03:56
  • @jee-ar: You need to embrace the \mybox command with \makeatletter ... \makeatother. – Werner Aug 08 '12 at 04: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 08 '12 at 05:35
  • @jee-ar: That requires much more work than is covered by the original question. Perhaps you can ask a follow-up question. – Werner Aug 17 '12 at 16:51
37

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}

enter image description here

Gonzalo Medina
  • 505,128
25

Update: tcbox raise base,nobeforeafter replaced by on line.

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 on line.

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

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

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

enter image description here