0

I use the following lines in my preamble to format section inside a colored box:

\titleformat{name=\section,numberless}
    {\normalfont\Large\bfseries}
    {}
    {0em}
    {\colorbox{mainColor}{
    \parbox{\dimexpr\linewidth-2\fboxsep\relax}
    {\textcolor{white}{#1}}}}

Output (\section{Feedback} with mainColor as blue!80):

output

I am now writing a class file, and I want to use the same style for my section as I always used in my document. However, using the same code in a .cls file produce this error:

Illegal parameter number in definition of \ttlf@section ^^I^^I{ 
You can't use `macro parameter character #' in horizontal mode
^^I^^I\section{Une section !}

The problem is when i try to get the section name with #1. I don't know why, but it look like I can't do it in a .cls file but it is correct inside a .tex file.

Full class file: https://pastebin.com/dQpstaHG

  • 1
    If you want to use the explicit argument #1 for the section name in \titleformat, you have to load package titlesec with option explicit. But then you have to use #1 in the \titleformat settings for other section level formats too. – esdd Apr 3 '17 at 13:06
  • @esdd: Thank you, I have been trying for a whole day to solve this :) – Nakrule Apr 3 '17 at 13:57

Your Answer

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

Browse other questions tagged or ask your own question.