0

I want to use a floating framed box that could be nicely placed in the text. \fbox needs to be placed by hand. I wrote this code which was exactly what I want to get...but with a floating object.

\documentclass[a4paper,12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[francais]{babel}
\usepackage{lipsum}
\usepackage{caption}
\usepackage[usenames,dvipsnames]{color} 
\usepackage{framed}
\usepackage{hyperref} 
\newcounter{encadre}
\newenvironment{encadre}
\refstepcounter{encadre}\vspace{0.2cm}\textsc{\bfseries encadré \theencadre\ :}}
{\par\vspace{0.2cm}}
\begin{document}
\lipsum
\fcolorbox{Black}{Gray}{
\begin{minipage}{\linewidth}
   \begin{encadre}\label{enc:metamere}
blabla
\end{encadre}
\lipsum[10]
\end{minipage}
}
\end{document}

So I use framed (impossible to install mdframed on my LaTeX version of 2009 on Ubuntu 12.04)

My question : Where must I define \defineshadecolor as it is said in the framed documentation?

framed doc p2 :"In fact, the “shaded” environment just redefines \FrameCommand to be \colorbox{shadecolor} (and you have to define the color “shadecolor”: \definecolor{shadecolor}...)."

I tried to put it as an option or to write it like directly in the preamble, but it does not work. Here is the framed code, but without background.

\documentclass[a4paper,12pt]{book}
\usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}
\usepackage[francais]{babel}
\usepackage{lipsum}
\usepackage{caption}
\usepackage{xcolor}
\usepackage{framed}
\usepackage{hyperref}

\newcounter{encadre}
\newenvironment{encadre} {\refstepcounter{encadre}
\vspace{0.3cm}\textsc{\bfseries encadré \theencadre\ :}}
{\par\vspace{0.3cm}}

\begin{document} 
\lipsum [50]

\begin{framed}
 \begin{encadre} test
 \end{encadre}\label{enc}
\lipsum[15]
\end{framed}


l'encadré \ref{enc} est à la page \pageref{enc}

 \lipsum 
\end{document}
6
  • shadecolor will only have effect if the shaded environment from framed is used, since you are not using it, shadecolor will do nothing in your code. In any case, you can define it using \definecolor (as in \definecolor{shadecolor}{RGB}{123,45,67}) or \colorlet (as in \colorlet{shadecolor}{red}) .See the package xcolor documentation for details. Feb 18, 2014 at 14:25
  • Thanks a lot; I try that, putting \definecolor{shadecolor}{RGB}{123,45,67} in the preambule...but it has no effect, it is my problem. perhaps isn't it the write place to put it?
    – catindri
    Feb 18, 2014 at 14:33
  • I try also \usepackage[shaded]{framed} but does not work
    – catindri
    Feb 18, 2014 at 14:41
  • OK!! I just find it [tex.stackexchange.com/questions/86205/…
    – catindri
    Feb 18, 2014 at 14:43
  • Yes, as I said in my comment, you need to use the shaded environment. Feb 18, 2014 at 14:44

2 Answers 2

1

Here the solution, thanks a lot to Gonzalo

 \documentclass[a4paper,12pt]{book}
 \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}
 \usepackage[francais]{babel}
 \usepackage{lipsum, caption, xcolor, framed}
 \definecolor{shadecolor}{RGB}{140,20,21}
 \newcounter{encadre}
 \newenvironment{encadre} {\refstepcounter{encadre}
 \vspace{0.3cm}\textsc{\bfseries encadré \theencadre\ :}}
 {\par\vspace{0.3cm}}

\begin{document} 
\lipsum [50]
\begin{framed}
   \begin{shaded}
      \begin{encadre} test     
      \end{encadre} 
    \lipsum[15]
   \end{shaded}
\end{framed}
\lipsum 
\end{document}
2
0

Here and example of "Encadré" box with package tcolorbox. I do not know why, but it needs the package to be in the same folder than the .tex file. It does not work if the tcolorbox.sty is the usual location (for me /usr/share/texmf/tex/latex)

documentclass[a4paper,12pt]{book}
\usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}
\usepackage[francais]{babel}
\usepackage{lipsum, xcolor}
\usepackage{tcolorbox}
\newtcolorbox[auto counter,number within=chapter]{encbox}[2][]{%
colback=blue!5!white,colframe=blue!75!black,fonttitle=\bfseries,
title=Encadré.~\thetcbcounter: #2,#1}
\begin{document} 
\chapter{boite}
\begin{encbox}{Boite tbolorbox}
\lipsum[30]
\end{encbox}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.