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?

4
  • You can't use verbatim code like this in the command argument of tcbox
    – user31729
    Commented May 28, 2016 at 14:45
  • The error I get from that code is ! LaTeX Error: \verb illegal in command argument.. Commented May 28, 2016 at 14:47
  • Oh damn, any workaround @ChristianHupfer to keep tcbox and still have a fancy C++ text?
    – gsamaras
    Commented May 28, 2016 at 14:47
  • \tcboxverb is what you want
    – user31729
    Commented May 28, 2016 at 14:47

2 Answers 2

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}
1
  • This works. Christian's solution should work for newer installations than mine's!
    – gsamaras
    Commented May 28, 2016 at 14:54
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

1
  • l.14 \tcboxverb gets an undefined control sequence. You can't escape your faith Christian. Danke!
    – gsamaras
    Commented May 28, 2016 at 14:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .