Title: I made a `box' float environment, and now I would like to put the caption inside the box
Tags: floats;captions;environments
Question: I made a box float using the following:
\usepackage{float}
\newfloat{Box}{t}{bx}[chapter]
\begin{Box}[htp]
\label{box:test}
\fcolorbox{black}{boxgray}{\parbox[c]{\textwidth}{The text goes here}}
\end{Box}
I would like to have the label, i.e. 'Box 1' appear inside the box in the first row of text. Does anyone have an idea of how to implement this?
A basic version of the file I am using:
\documentclass[11pt]{article}
\usepackage{color}
\definecolor{boxgray}{RGB}{215,215,215}
\usepackage{hyperref}
\usepackage{float}
\newfloat{Box}{t}{bx}[section]
\begin{document}
\section{example}
Something about \ref{box:test}.
\begin{Box}[htp]
\label{box:test}
\fcolorbox{black}{boxgray}{\parbox[c]{\textwidth}{The text goes here}}
\end{Box}
\end{document}
Comment: Welcome to TeX.SX! You can have a look on [our starter guide](http://meta.tex.stackexchange.com/q/1436) to familiarize yourself further with our format.

Comment: Please add a [minimal working example (MWE)](http://meta.tex.stackexchange.com/q/228) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with `\documentclass{...}` and ending with `\end{document}`.


Here is another answer: You need an anchor for the label. This is normally done by caption and not by the float environment. This is the reason why you should put the label after caption. In your case there is no anchor. A trick would be:
\usepackage{etoolbox}
\AtBeginEnvironment{Box}{\refstepcounter{Box}}
However there is no hint inside your environment that the reference number contains to the environment. So I suggest the following:
Define the new float environment with newfloat
Related to point 1 you can setup the caption with captionsetup. (I know caption supports float)
Using tcolorbox to draw the frame around the caption.
Here an MWE:
\documentclass[11pt]{article}
\usepackage{xcolor}
\definecolor{boxgray}{RGB}{215,215,215}
\usepackage{caption}
\usepackage{newfloat}%loaded by caption too
\DeclareFloatingEnvironment[%
fileext=bx,%
within=section,%
placement=t,
name=Box,%
listname={List of Boxes},%
]{Boxed}
\captionsetup[Boxed]{justification=justified,format=plain,singlelinecheck=false,skip=0pt}
\usepackage{tcolorbox}
\newcommand*\boxedcaption[2][box:\arabic{Boxed}]%
{\begin{tcolorbox}\caption{#2}\label{#1}\end{tcolorbox}}
\usepackage{lipsum}
\usepackage{hyperref}
\begin{document}
\section{example}
Something about \ref{box:test}.
\begin{Boxed}[htp]
\lipsum[1]
\boxedcaption[box:test]{Text goes here}
\end{Boxed}
Something about \ref{box:2}.
\begin{Boxed}[htp]
\lipsum[2]
\boxedcaption{Text goes here}
\end{Boxed}
\end{document}
Comment for this answer: Or do you want a frame around the environment Box?

{'source': 'StackExchangeDataset', 'subset': 'tex.stackexchange.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:06/06/13', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<floats><captions><environments>', 'Title': "I made a `box' float environment, and now I would like to put the caption inside the box", 'ViewCount': 165, 'id': 117890, 'user_AboutMe': None, 'user_AccountId': 2864537.0, 'user_DisplayName': 'superhungryhippo', 'user_Reputation': 31.0, 'user_Views': 3.0, 'user_id': 31831.0}}