0

i'm trying to customize the title of sections in my document using the packages tikz and titlesec.

Unfortunately, that does not work and i need some help to solve my problem.

I get this error :

! Argument of \tikz@next has an extra }.
<inserted text>
\par
l.25 \section{Problem}
I've run across a `}' that doesn't seem to match anything.

Here is my code :

\documentclass[a4paper, 11pt]{article}
\usepackage[francais]{babel}    
\usepackage[utf8]{inputenc}     
\usepackage[T1]{fontenc}        

\usepackage{titlesec}           
\usepackage[x11names]{xcolor}   
\usepackage{tikz}
\titleformat{\section}
    {\normalfont\Large\sffamily\bfseries\color{CadetBlue4}}
    {%
        \tikz[anchor=base,baseline,outer sep=0pt]               
        \node[anchor=base,rectangle,rounded corners,fill=CadetBlue4]
        {\normalfont\Large\sffamily\bfseries{\textcolor{CadetBlue2!20}{\thesection}}};%
    }{0em}{}

\begin{document}
\tikz[anchor=base,baseline,outer sep=0pt]
\node[anchor=base,rectangle,rounded corners,fill=CadetBlue4]
{\normalfont\Large\sffamily\bfseries{\textcolor{CadetBlue2!20}{That works}}};

\section{Problem}

\end{document}

Thank you for your help.

  • 2
    Welcome to TeX.SX! Is that the exact error you get when running your MWE? It ran perfectly fine without any errors or warnings here (up to date MikTeX 2.9). Maybe your TeX distribution needs updating. (I'm a bit confused because the error message mentions line 25, while your MWE only has 24 lines.) – moewe Oct 7 '15 at 8:21
  • you can use \begin{tikzpicture}...\end{tikzpicture} – touhami Oct 7 '15 at 14:58
3

It ran fine for me too, but you can try the following simpler code to get the same result with tcolorbox (which anyway relies on tikz):

\documentclass[a4paper, x11names, 11pt]{article}
\usepackage[francais]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tcolorbox}
\usepackage{titlesec}

\titleformat{\section}
    {\normalfont\Large\sffamily\bfseries\color{CadetBlue4}}
    {\tcbox[colback=CadetBlue4, colframe=CadetBlue4, coltext=CadetBlue2!20, on line, boxsep=0pt, left=4pt, right=4pt, top=4pt, bottom=4pt]{\thesection}}{0.2em}{}

\begin{document}

\section{Problem}

\end{document} 

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.