# How to create an empty environment with custom caption?

This code shows a simple centered table that looks like this:

\documentclass[12pt,a4paper]{report}
\usepackage[labelfont=bf]{caption}

\begin{document}
\tableofcontents
\listoftables
\chapter{One}
\begin{table}[ht]
\caption{My first table.}
\centering
\begin{tabular}{lcr}
One  & Two  & Three\\
Four & Five & Six
\end{tabular}
\end{table}
\end{document}


I would now like to define a new environment called appendix where the caption should look like this:

Appendix 1: My first appendix.

It should also be possible to make a \listofappendices which I can locate right beneath my \listoftables.

I already tried to modify this code but it did not yield the result I want:

\makeatletter
\newcommand\listexamplename{List of Appendices}
\newcommand\listofexamples{%
\section*{\listexamplename}\@starttoc{exs}}
\makeatother

\newcounter{example}
\newenvironment{example}[2][]{\refstepcounter{example}%
\ifx\\#1\\ % if #1 is empty
\else
\fi
\begin{list}{}{% options
\setlength{\leftmargin}{0mm}%     leftmargin
\parsep\parskip%                  space between paragraphs within an item
\setlength{\itemsep}{-\parsep}%   space between items
}
\item {\centering\textbf{Appendix \theexample:} ~#2}
\item}{\end{list}}


Please note that I would like to write something like this and produce the same output as shown before but with a caption that does not look like this:

Table 1: My first table.

But like this:

Appendix 1: My first appendix.

That is, I would like to write something like this:

\documentclass[12pt,a4paper]{report}
\usepackage[labelfont=bf]{caption}

\begin{document}
\tableofcontents
\listoftables
\listofappendices
\chapter{One}
\begin{table}[ht]
\caption{My first table.}
\centering
\begin{tabular}{lcr}
One  & Two  & Three\\
Four & Five & Six
\end{tabular}
\end{table}
\begin{appendix}[ht]
\caption{My first appendix.}
\centering
\begin{tabular}{lcr}
One  & Two  & Three\\
Four & Five & Six
\end{tabular}
\end{appendix}
\end{document}

• Why do you want to call a table ‘appendix’??? – Bernard Jul 13 at 14:04
• I want an environment that is called appendix but it should be able to contain a table, a figure, just text or whatsoever. The table in the appendix environment here is just an example. But adding another appendix with a figure should then be called “Appendix 2: My second appendix.”. – Incognito Jul 13 at 14:16
• Wouldn't it be as simple to start a real appendix, and use sections inside this appendix ( redefining their numbering)? – Bernard Jul 13 at 14:18
• What do you mean by that? A new chapter called “Appendix” that contains several sections? Usually, I would do that. But my project partners want it to be that way. – Incognito Jul 13 at 14:22
• You can define new floating environments with float (which cooperates with caption), but I wouldn't call this environment ‘appendix’, as it might interfere with real appendices, even if there would be no problem displaying appendix in the caption. – Bernard Jul 13 at 14:26

Environments are implemented as macros, for example \figure and \endfigure. Alas, the macro \appendix is already used, so one would need to modify the newfloat (or float) packages to use \renewenvironment instead of \newenvironment.

However, that only applies to the environment name.

\documentclass[12pt,a4paper]{report}
\usepackage{newfloat}
\DeclareFloatingEnvironment[fileext=app,listname={List of Appendices},
name=Appendix,placement=htp,within=none]{app}
\usepackage[labelfont=bf]{caption}

\begin{document}
\tableofcontents
\listoftables
\listofapps
\chapter{One}
\begin{table}[ht]
\caption{My first table.}
\centering
\begin{tabular}{lcr}
One  & Two  & Three\\
Four & Five & Six
\end{tabular}
\end{table}
\begin{app}[ht]
\caption{My first appendix.}
\centering
\begin{tabular}{lcr}
One  & Two  & Three\\
Four & Five & Six
\end{tabular}
\end{app}
\end{document}