# How I can customize fbox and hrule?

I want to customization a sample exercises for a book. I like so much this style:

I think that is possible with fbox and hrule, but I don't know how I can do it. No need to use fbox and hrule if there is another way to do.

EDIT: The bottom rule is here Creating a custom rule

UPDATE: I have made my example code with the help Dan and azetina. Thank you both and now I share the code:

\documentclass{article}
\usepackage{multicol}
\usepackage{colortbl}
\usepackage{blindtext}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amssymb}

% 1. define its color
\definecolor{ejemplo}{RGB}{37,153,116}
% 2. define its counter, to be reset with each section
\newcounter{ejemplo}[section]
\renewcommand\theejemplo{\mdseries\normalsize\thesection.\arabic{ejemplo}}
% 3. define the environment. Its argument is the name of the example.
\makeatletter
\newenvironment{ejemplo}[1]{%
\bigbreak
\refstepcounter{ejemplo}
\par%
\noindent{\color{ejemplo}\large\sffamily
{\setlength{\extrarowheight}{5pt}\begin{tabular}{ll@{}}%
\hline
\cellcolor{ejemplo}\color{white}%
\textmd{\normalsize Ejemplo} \theejemplo&\bfseries #1%
\end{tabular}}}\par
% (b) space after and no indentation after
\begin{multicols}{2}
\vspace{1em}%
\@afterindentfalse
}   {\end{multicols}
% (c) place the custom rule
\noindent{\color{ejemplo}%
\parbox{\linewidth}{%
\hrulefill\rule{2em}{0.4em}}%
}\par%
}
% The solution
\newcommand\solucion{
\par\vspace{1em}
\noindent
\colorbox{ejemplo}{\textsc{\MakeLowercase{\sffamily\mdseries\color{white}Soluci\'on}}}%
\par\vspace{1em}
\@afterindentfalse
}
\makeatother


And here the result:

• Do you want to create an environment to replicate the example in the diagram or just the title of each example? – azetina Dec 6 '13 at 15:32
• @azetina - I only want the title and footer, but if is possible all environment... I really appreciate it – Kiyoshi Dec 6 '13 at 16:06
• Have you contemplated on using TikZ? – azetina Dec 6 '13 at 17:25
• @azetina - No, but if with TikZ is possible I will use it – Kiyoshi Dec 6 '13 at 17:33

The Ejemplo part looks like it was set with colortbl and the Soluci\'on part with \colorbox Here is some code to produce those effects. Normally one would code examples with \newtheorem and one would have to go to some effort to make this automatic. But it is late, and I will leave that until later (or someone else can step in). I didn't try to match the color and just went with blue. One can, of course change colors, fonts, and sizes to suit ones tastes:

\documentclass{article}
\usepackage{colortbl}
\begin{document}
Some text.

\bigskip
\noindent{\color{blue}\Large\sffamily
\begin{tabular}{ll@{}}
\hline
\cellcolor{blue}\color{white}Ejemplo 37.12&\bfseries Choque Relativista
\end{tabular}}

\bigskip
Statement of example.

\bigskip
\noindent \colorbox{blue}{\sffamily\bfseries\color{white}SOLUCI\'ON}

\bigskip
Description of solution.

\end{document}


Here's a more complete example, coded as an ejemplo environment.

\documentclass{article}
\usepackage{colortbl}
\usepackage{multicol}
\usepackage{blindtext}
%
%
% Prepare an ejemplo environment
% 1. define its color
\definecolor{ejemplo}{rgb}{0.1,0.5,0.4}
% 2. define its counter, to be reset with each section
\newcounter{ejemplo}[section]
\renewcommand\theejemplo{\thesection.\arabic{ejemplo}}
% 3. Define the lengths of the rule that follows
\newlength\ejemplorulei
\newlength\ejemploruleii
\setlength\ejemploruleii{4em}
\setlength\ejemplorulei\textwidth
% 4. define the environment. Its argument is the name of the
%    example.
\makeatletter
\newenvironment{ejemplo}[1]
{%
\refstepcounter{ejemplo}
\begin{multicols}{2}%
\noindent{\color{ejemplo}\large\sffamily
\begin{tabular}{ll@{}}%
\hline
\cellcolor{ejemplo}\color{white}Ejemplo \theejemplo&\bfseries #1%
\end{tabular}}\par
%    (b) space after and no indentation after
\vspace{1em}%
\@afterindentfalse
}{\end{multicols}
%    (c) place the custom rule
\noindent{\color{ejemplo}%
\rule[2ex]{\ejemplorulei}{.4pt}%
\rule[2ex]{\ejemploruleii}{1.2pt}}\par
}
\newcommand\solucion{% The solution
\par\vspace{1em}
\noindent
\colorbox{ejemplo}{\sffamily\bfseries\color{white}SOLUCI\'ON}%
\par\vspace{1em}
\@afterindentfalse
}
\makeatother
\begin{document}

\section{Start of section}
\blindtext
\begin{ejemplo}{Choque Relativista}
\blindtext[1]
\solucion
\blindtext[2]
\end{ejemplo}

\end{document}


• It looks good! Just missing the bottom but I do not know how to do the lower right box. If possible make the example in two columns? – Kiyoshi Dec 7 '13 at 9:47
• Sorry, I didn't even see the line at the bottom. It's just two rules. I'll be adding a more-or-less complete solution in a bit – Dan Dec 7 '13 at 22:04