[Tex/LaTex] How to locally change the “Table” caption prefix in table environment

captionstables

In my memoir document, I have several tables looking something like:

\begin{table}[htbp]
\centering
\caption{This is a caption.}
\label{tab:some_table}
\begin{tabular}{l p{10cm}}
\toprule
some text & some more text \\
\midrule
some text & even more text, it's crazy! \\
\bottomrule
\end{tabular}
\end{table}

This results in the caption: "Table 3.1: This is a caption."

I would like this caption to be: "Use case 1: This is a caption."

That is, I would like to choose the prefix myself (not necessarily "Use case 1") but only locally, since my document includes other tables which should use the "standard" caption. And I want to be able to reference the tables/use cases using cleveref (or just \ref if that makes the reference "Use case 1").

Best Answer

You can easily define new float types.

\documentclass{memoir}

\usepackage{lipsum} % for mock text

\newfloat{usecase}{luc}{Use case}

\begin{document}

\lipsum[1]

\begin{table}[htp]
\centering
\caption{A caption}
A table here
\end{table}

\lipsum[2]

\begin{usecase}[htp]
\centering
\caption{This is a caption.}
\label{tab:some_table}

Whatever should appear here to describe the use case
\end{usecase}

\lipsum[3]

\end{document}

enter image description here

If you want the use cases to be numbered, like tables, within chapters, change into

\newfloat[chapter]{usecase}{luc}{Use case}

Adding support for cleveref is as easy as adding a \crefname instruction.

\documentclass{memoir}

\usepackage{lipsum} % for mock text

\usepackage{cleveref}

\newfloat{usecase}{luc}{Use case}
\crefname{usecase}{use case}{use cases}

\begin{document}

\lipsum[1]

\begin{table}[htp]
\centering
\caption{A caption}
A table here
\end{table}

\lipsum[2]

\begin{usecase}[htp]
\centering
\caption{This is a caption.}
\label{uc:some_use_case}

Whatever should appear here to describe the use case
\end{usecase}

See \cref{uc:some_use_case}.
\lipsum[3]

\end{document}

I'll show only the relevant extract from the image:

enter image description here