\documentclass{article}
\usepackage{minted}
\usepackage[most]{tcolorbox}
\definecolor{lightgreen}{rgb}{0.56, 0.93, 0.56}
\definecolor{moonstoneblue}{rgb}{0.45, 0.66, 0.76}
\begin{document}
\begin{tcolorbox}[
enhanced,
attach boxed title to top left={xshift=6mm,yshift=-3mm},
colback=lightgreen!20,
colframe=lightgreen,
colbacktitle=lightgreen,
title=C++ Code 1.1: C++ Example,
fonttitle=\bfseries\color{black},
boxed title style={size=small,colframe=lightgreen,sharp corners},
sharp corners,
]
\begin{minted}[linenos]{cpp}
// This is a C++ code
#include<iostream>
using namespace std;
int main()
{
cout << "Hello World!";
}
\end{minted}
\end{tcolorbox}
\begin{tcolorbox}[
enhanced,
attach boxed title to top left={xshift=6mm,yshift=-3mm},
colback=moonstoneblue!20,
colframe=moonstoneblue,
colbacktitle=moonstoneblue,
title=Welcome to \TeX{} -- \LaTeX{} Stack Exchange!,
fonttitle=\bfseries\color{black},
boxed title style={size=small,colframe=moonstoneblue,sharp corners},
sharp corners,
]
\begin{minted}[linenos]{latex}
\documentclass{article}
\begin{document}
Einstein said $E=mc^2$!
\end{document}
\end{minted}
\end{tcolorbox}
\end{document}
The listings package provides a command for inline code snippets:
\documentclass{article}
\usepackage{listings}
\lstset{language = C++}
\begin{document}
In order to do this just run the
\lstinline!#include <iostream>! command
command in your terminal.
\end{document}
Instead of the exclamation mark you could use any character as delimiter, as long as it does not appear in the code snippet.
It looks like you are using minted 1.7 or earlier. Version 2.0 and later includes patches for some fancyvrb bugs. This should make firstnumber=last work correctly. (At least, it works for me.) Also, since 2.0 there is a package option langlinenos that does per-language line numbering when firstnumber=last, so that you can keep bash line numbers separate from any other code.
If this doesn't work for you with minted 2.0+, then there is probably a bug in minted.
Best Answer
Try this. Read more in The
tcolorbox
package manual.