# Referencing custom environment

I am using

\begin{figure}
\includegraphics{}
\caption{Caption}
\label{fig:fig_name}
\end{figure}


and

\begin{table}
\begin{tabular}
....
\end{tabular}
\caption{Caption}
\label{tab:table_name}
\end{figure}


but I also need a custom environment iteration having layout:

Hypothesis:
<text>

Validation:
<text>


and I need to be able to reference it with \ref{it:iteration_name}.

How is this possible? I have seen the command \newenvironment but it doesn't seem to fit my needs. I could maybe just use the figure or table environment but the counter should be independent from the tables and figures when I'm referencing them.

# Edit

I want the new environment with content

Hypothesis:
<text>

Validation:
<text>


to be numbered. It should work just like figures/tables, so the entire environment is numbered but neither the text "Hypothesis" nor "Validation". I also want to color the background so it's more clear that the environment "stands out" as "independent" from the rest of the document.

• You might want to give some more information. Is Hypothesis numbered? You need something for \label to latch on to. Jun 19 '15 at 11:35
• Maybe a theorem-like environment is all you need? Jun 19 '15 at 11:39
• Just like figure and table? So it shall float around the document? Or always stay where you are putting it? Jun 19 '15 at 11:47
• @Jamgreen: tcolorbox is what you want, for example
– user31729
Jun 19 '15 at 12:25
• Please tell us how the iteration environment is defined. In essence, we need to find out where a counter associated with the environment is defined and how it is incremented.
– Mico
Jun 20 '15 at 5:47

A suggestion, to keep track of options and arguments, is to replace the iteration environment by a command, having some optional arguments etc.

The typesetting will be done within of a tcolorbox box environment. The counter is incremented automatically and reset with each section.

Please note, that the label must be used in the first optional argument as label=it:somelabelname.

\documentclass{article}

\PassOptionsToPackage{svgnames}{xcolor}
\usepackage[most]{tcolorbox}

\usepackage{ulem}%
\usepackage{blindtext}

\usepackage{xparse}

\newcounter{iteration}[section]

\newtcolorbox[use counter=iteration]{iterationbox}[1][]{arc=0pt, auto outer arc,left=2pt,right=2pt,colback=LightBlue,colbacktitle=yellow,coltitle=black,title={Iteration \thetcbcounter},#1}

\NewDocumentCommand{\iteration}{+O{}+m+m+o}{%
\begin{iterationbox}[#1]
\uline{Hypothesis}:

#2

\uline{Validation}:

#3

\IfValueT{#4}{%

\uline{Validation}:

#4
}%
\end{iterationbox}
}

\begin{document}

In \ref{it:brontosaurs}, we will see that...

\iteration[label=it:brontosaurs,colbacktitle=red,colback=yellow]{Theory on Brontosaurs}{Excavate a brontosaur}

\iteration[label={it:brontosaurs_extended},colbacktitle=red,colback=yellow]{Extended theory on Brontosaurs}{Excavate a brontosaur

\blindtext}[There must have been Brontosaurs]

\end{document}


• Did you just come back from a vacation in Spain? :-)
– Mico
Jun 20 '15 at 5:48
• @Mico: Nope, "Badische Landesfarben" :D
– user31729
Jun 20 '15 at 5:54
• @cfr: I prefer hideous over hilarious :-P ... I would not use those colours for my own documents :D
– user31729
Jun 20 '15 at 9:31