错误:在包含目录的部分或子部分的参数中添加 includegraphics

错误:在包含目录的部分或子部分的参数中添加 includegraphics

我正在使用以下代码,但是当我想添加\includegraphics{example-image-duck}到节或小节的参数时,在这种情况下我收到错误,@Skillmon 建议添加\protect\section{\protect\includegraphics{example-image-duck}}但即使我收到错误,此外,只要我使用 \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}

相关内容