LaTeX: how to change SOME figure's titles from Figure to Code?

Viewed 69

My manuscript uses \begin{figure}...\end{figure} to both images and code fragments.

However, I want that code fragments are titled "Code 1. ..." and not "Figure 1. ...", while the pictures are still titled "Figure 1. ...".

What I can find is only how to change figure titles for the whole document.

1 Answers

You can use the float package to create new float types:

\documentclass{article}

\usepackage{float}

\newfloat{Code}{htbp}{loc}

\begin{document}

\begin{figure}[htbp]
\caption{a figure}
\end{figure}

\begin{Code}[htbp]
\caption{some code}
\end{Code}
    
\end{document}

(although the result would be better if instead of images, you'd use a proper source code package to include the code, e.g. listings or minted)

Related