4

Driven from Let's get fancy: Text like tag? , I wrote this code:

\documentclass{article}
\usepackage{tcolorbox}
\definecolor{mycolor}{rgb}{0.122, 0.435, 0.698}

\newtcbox{\mybox}{nobeforeafter,colframe=mycolor,colback=mycolor!10!white,boxrule=0.5pt,arc=4pt,
  boxsep=-3pt,left=6pt,right=6pt,top=6pt,bottom=6pt,tcbox raise base}

\begin{document}
\mybox{C{}\verb!++!}
\end{document}

The error:

! Missing } inserted.
<inserted text>
}
l.9 \mybox{C{}\verb!++!}

This works with normal text inside the box, but because of the fancy way I am trying to write C++ and the fancy textbox, I am getting fancy² and I overflow! :) Any ideas?

gsamaras
  • 1,443

2 Answers2

5

You can use \texttt{++} instead, can't you?

enter image description here

\documentclass{article}
\usepackage{tcolorbox}
\definecolor{mycolor}{rgb}{0.122, 0.435, 0.698}

\newtcbox{\mybox}{nobeforeafter,colframe=mycolor,colback=mycolor!10!white,boxrule=0.5pt,arc=4pt,
  boxsep=-3pt,left=6pt,right=6pt,top=6pt,bottom=6pt,tcbox raise base}

\begin{document}
\mybox{C\texttt{++}}
\end{document}
Torbjørn T.
  • 206,688
4

I hope, at least this compiles for the O.P. ;-)

\tcboxverb is designed for such small boxes with verbatim content.

I've added a myboxstyle TikZ style for this.

\documentclass{article}
\usepackage[most]{tcolorbox}
\definecolor{mycolor}{rgb}{0.122, 0.435, 0.698}

%\newtcbox{\mybox}{nobeforeafter,colframe=mycolor,colback=mycolor!10!white,boxrule=0.5pt,arc=4pt,
%  boxsep=-3pt,left=6pt,right=6pt,top=6pt,bottom=6pt,tcbox raise base}

\tcbset{myboxstyle/.style={%
nobeforeafter,colframe=mycolor,colback=mycolor!10!white,boxrule=0.5pt,arc=4pt,
  boxsep=-3pt,left=6pt,right=6pt,top=6pt,bottom=6pt,tcbox raise base
}}

\begin{document}
\tcboxverb[myboxstyle]{C++}

\tcboxverb[myboxstyle]{#include <iostream>}
\end{document}

enter image description here