# Coloured boxes inside latex

I want to make coloured boxes with different colours and i cannot understand the function of the mybox{} order. I attach an example that may helps you.

I write the code

\documentclass[a4paper]{report}

\usepackage[greek]{babel}
\usepackage[iso-8859-7]{inputenc}
\usepackage{xcolor}
\usepackage{blindtext}
\usepackage{tikz,tkz-tab,amsmath}

\begin{document}

\newcommand{\mybox}[1]{%
\begin{center}%
\begin{tikzpicture}%
\node[rectangle, draw=green, top color=green!10, bottom color=green!90, rounded corners=5pt, inner xsep=5pt, inner ysep=6pt, outer ysep=10pt]{
\begin{minipage}{1.05\linewidth}#1\end{minipage}};%
\end{tikzpicture}%
\end{center}%
}

\mybox{\textlatin{\blindtext}}

\end{document}


and the result is this:

-
The information is insufficient. Please add a minimal working example (MWE), stating precisely what you want to achieve. –  egreg Mar 14 '14 at 19:01
Giannis please take a snapshot of the page and crop it in Paint. It takes 3 seconds and show us the code that lead you to this output. Why not giving some info to the people who are trying to help you? Don't you want help? –  percusse Mar 14 '14 at 19:07
It is quite unclear, what you want to do? Two separated boxes with different colours? I would have a look on tcolorbox package (as you tagged already your question) -- there are so many options, it should be possible with that package. –  Christian Hupfer Mar 14 '14 at 19:39
I think i have described my problem the best i could. I want to make coloured boxes like the first image's with different colours. I tried and i managed to have a green box. I CANNOT MAKE A SECOND BOX WITH ANOTHER COLOUR. –  Giannis Mar 14 '14 at 19:50
It would be helpful if you added your last comment into the question itself. And please do crop your images. –  Peter Grill Mar 14 '14 at 20:08

You could add a parameter to \mybox in which you can specify an alternate color. So

\mybox{text}


will produce a box that uses green (the default color as specified in the mybox definition), but

\mybox[red]{text}


will use red:

However, I would recommend that you use the mdframed package instead:

## Code: tikz node

\documentclass[a4paper]{report}

\usepackage[greek]{babel}
\usepackage{xcolor}
\usepackage{blindtext}
\usepackage{tikz}

\newcommand{\mybox}[2][green]{%
\begin{center}%
\begin{tikzpicture}%
\node[rectangle, draw=green, top color=#1!10, bottom color=#1!90, rounded corners=5pt, inner xsep=5pt, inner ysep=6pt, outer ysep=10pt]{%
\begin{minipage}{1.05\linewidth}#2\end{minipage}};%
\end{tikzpicture}%
\end{center}%
}

\begin{document}
\mybox{\textlatin{\blindtext}}
\mybox[red]{\textlatin{\blindtext}}
\mybox[blue]{\textlatin{\blindtext}}
\end{document}


## Code: mdframed

\documentclass{report}

\usepackage[greek]{babel}
\usepackage{xcolor}
\usepackage{blindtext}
\usepackage[framemethod=tikz]{mdframed}

\newcommand{\mybox}[2][]{%
\begin{mdframed}[backgroundcolor=green!70,roundcorner=10.0pt, #1]
#2%
\end{mdframed}
}%

\begin{document}
\mybox{\textlatin{\blindtext}}
\mybox[backgroundcolor=red!40]{\textlatin{\blindtext}}
\mybox[backgroundcolor=blue!25]{\textlatin{\blindtext}}
\end{document}

-
+1 for mdframed; really nice package for drawing boxes and stuff. –  Argo Mar 14 '14 at 23:38

Because you already use the tikz package tcolorbox is another alternative. Page 12 of the Manual describes "mybox" as:

\newtcolorbox[⟨init options⟩]{⟨name⟩}[⟨number⟩][⟨default⟩]{⟨options⟩} Creates a new environment ⟨name⟩ based on tcolorbox. Basically, \newtcolorbox operates like \newenvironment. This means, the new environment ⟨name⟩ optionally takes ⟨number⟩ arguments, where ⟨default⟩ is the default value for the optional first argument. The ⟨options⟩ are given to the underlying tcolorbox.

Theorems are set with \tcbuselibrary{theorems} (see Page 185ff).

\documentclass[a4paper]{report}

\usepackage[greek]{babel}
\usepackage[iso-8859-7]{inputenc}
\usepackage{xcolor}
\usepackage{blindtext}
\usepackage{tikz,tkz-tab,amsmath}
\usepackage{tcolorbox}
\newtcolorbox{mybox}{colback=red!5!white,colframe=red!75!black}
\newtcolorbox{mybox_1}{colback=blue!5!white,colframe=blue!75!black}
\newtcolorbox{mybox_2}{colback=green!5!white,colframe=green!75!black}
\tcbuselibrary{theorems}
\newtcbtheorem[number within=section]{mytheo}{My Theorem}%
{colback=green!5,colframe=green!35!black,fonttitle=\bfseries}{th}

\begin{document}

\chapter{Watt}
\section{James}

\begin{mybox}
\textlatin{This is my own box.}
\end{mybox}

\begin{mybox_1}
This is my own box.
\end{mybox_1}

\begin{mybox_2}
$$V= \pi \cdot r^{2} \cdot h$$
\end{mybox_2}

\begin{mytheo}{This is my title}{theoexample}
\textlatin{This is the text of the theorem. The counter is automatically assigned and, in this example, prefixed with the section number. This theorem is numbered with \ref{th:theoexample} and is given on page\pageref{th:theoexample}.}
\end{mytheo}

\end{document}


-