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}
graphicsif you then loadgraphicx. – Skillmon May 01 '18 at 11:37\protect\includegraphicsworks fine for me. But you should delete the old toc. – Ulrike Fischer May 01 '18 at 11:39\protect\includegraphics[width=1cm]{example-image-duck}– samcarter_is_at_topanswers.xyz May 01 '18 at 11:40articlein my tests (because the first question was usingarticle), and there I get the error! Argument of \@mkboth has an extra }.. As soon as I usereporteverything works fine. – Skillmon May 01 '18 at 11:43\protect\includegraphics. Compilation works, but the line under the caption ends at the image. – Skillmon May 01 '18 at 11:45uleminstead ofsoulwhich should be more robust (at the expense of worse on screen display and breaking automatic hyphenation). Just for anybody interested in it. – Skillmon Feb 22 '19 at 21:53