![错误:在包含目录的部分或子部分的参数中添加 includegraphics](https://linux22.com/image/375248/%E9%94%99%E8%AF%AF%EF%BC%9A%E5%9C%A8%E5%8C%85%E5%90%AB%E7%9B%AE%E5%BD%95%E7%9A%84%E9%83%A8%E5%88%86%E6%88%96%E5%AD%90%E9%83%A8%E5%88%86%E7%9A%84%E5%8F%82%E6%95%B0%E4%B8%AD%E6%B7%BB%E5%8A%A0%20includegraphics.png)
我正在使用以下代码,但是当我想添加\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}