0

I'm using the following code but when I want to add \includegraphics{example-image-duck} to argument of section or subsection I got error in this case @Skillmon suggest to add \protect which gives \section{\protect\includegraphics{example-image-duck}} but even though I got error besides I get another error from that code as soon as I use \tableofcontents.

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage[Lenny]{fncychap}
\usepackage{graphics}
\usepackage{graphicx}
\usepackage{float}
\usepackage[explicit]{titlesec}
\usepackage{soul}

\definecolor{titleblue}{HTML}{4a7aa4}

\title{Sections and Chapters}
\author{Educ}
\date{\today}

\newbox\TitleUnderlineTestBox
\newcommand*\TitleUnderline[1]
  {%
    \bgroup
    \setbox\TitleUnderlineTestBox\hbox{\colorbox{titleblue}\strut}%
    \setul{\dimexpr\dp\TitleUnderlineTestBox-.3ex\relax}{.3ex}%
    \ul{#1}%
    \egroup
  }
\newcommand*\SectionNumberBox[1]
  {%
    \colorbox{titleblue}
      {%
        \makebox[2.5em][c]
          {%
            \color{white}%
            \strut
            \csname the#1\endcsname
          }%
      }%
    \TitleUnderline{\ \ \ }%
  }
\titleformat{\section}
  {\Large\bfseries\sffamily\color{titleblue}}
  {\SectionNumberBox{section}}
  {0pt}
  {\TitleUnderline{#1}}
\titleformat{\subsection}
  {\large\bfseries\sffamily\color{titleblue}}
  {\SectionNumberBox{subsection}}
  {0pt}
  {\TitleUnderline{#1}}

\begin{document}

\maketitle
\tableofcontents
\chapter{Lenny}
\chapter{Lenny}
\section{Use this Tools \includegraphics[width=1cm]{example-image-duck} to obtain random points in Geogebra}
\section{Plya's Problem-Solving Cycle}
\subsection{Understand the problem}
\subsection{Devise a Plan}
\subsection{Carry Out the Plan}
\subsection{Look Back}
\section{Second Section}

\section
  {Really long section name that is really long, so long it takes two rows}

\end{document}
  • No need to load graphics if you then load graphicx. – Skillmon May 1 '18 at 11:37
  • \protect\includegraphics works fine for me. But you should delete the old toc. – Ulrike Fischer May 1 '18 at 11:39
  • works fine with \protect\includegraphics[width=1cm]{example-image-duck} – user36296 May 1 '18 at 11:40
  • @UlrikeFischer funny. I used article in my tests (because the first question was using article), and there I get the error ! Argument of \@mkboth has an extra }.. As soon as I use report everything works fine. – Skillmon May 1 '18 at 11:43
  • 2
    @Skillmon you could get the correct line by adding a \mbox around the graphics (to hide it from soul). But with article it will fail for the \section inside \tableofcontents. I would never use soul here -- much too fragile. – Ulrike Fischer May 1 '18 at 11:54

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.