
pdf
섹션 이름 옆에 문자 그대로 아이콘(파일)을 삽입하려고 합니다 .
나는 작은 방패 아이콘이 있는 곳에 있기를 원합니다 <Icon>
.
이 이미지를 생성하는 코드는 다음과 같습니다.
\subsection{Sentinel $<$Icon$>$}\icon{static/sentinel.pdf}
\icon
내부 를 추가하려고하면 \subsection
:
\subsection{Sentinel \icon{static/sentinel.pdf}}
오류가 발생합니다.
! Missing \endcsname inserted.
<to be read again>
\csname\endcsname
l.42 ...ction{Sentinel \icon{static/sentinel.pdf}}
?
! Emergency stop.
<to be read again>
\csname\endcsname
l.42 ...ction{Sentinel \icon{static/sentinel.pdf}}
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on generated//manual.log.
make: *** [all] Error 1
가능하다면 목차에 아이콘이 표시되지 않고 목차의 링크가 계속 작동하는 것이 좋을 것입니다.
\icon
에 의해 정의됩니다
\newcommand{\icon}[1]{\begingroup
\setbox0=\hbox{\includegraphics[height=12pt,keepaspectratio]{#1}}%
\parbox{\wd0}{\box0}\endgroup}
답변1
이온 이 필요합니다 \protect
. 그런데 그 복잡한 것을 \newcommand
단순화할 수 있습니다.
\documentclass{article}
\usepackage{graphicx}
\newcommand{\icon}[1]{\includegraphics[height=12pt]{#1}}
\begin{document}
\section{Some section here}
\subsection{Sentinel \protect\icon{example-image-a}}
\end{document}
많은 경우 를 원하지 않는다면 \protect
다음과 같은 가능성이 있습니다. 먼저 를 robust
사용 하여 만듭니다 etoolbox
.
\documentclass{article}
\usepackage{graphicx}
\usepackage{etoolbox}
\newcommand{\icon}[1]{\includegraphics[height=12pt]{#1}}
\robustify{\icon}
\begin{document}
\section{Some section here}
\subsection{Sentinel \icon{example-image-a}}
\end{document}
또는 다음과 같이 \newrobustcmd
( etoolbox
다시부터) 사용하십시오.
\usepackage{etoolbox}
\newrobustcmd{\icon}[1]{\includegraphics[height=12pt]{#1}}
또는 다음과 같은 선택적 인수를 사용하십시오.
\subsection[<opt argument>]{Sentinel \icon{example-image-a}}
등....
사용하는 경우 경고 및 여파를 제거하기 위해 hyperref
사용해야 할 수도 있습니다 .\texorpdfstring{\icon{example-image-a}}{}
\documentclass{article}
\usepackage{graphicx}
\usepackage{etoolbox}
\usepackage{hyperref}
\newrobustcmd{\icon}[1]{\includegraphics[height=12pt]{#1}}
\begin{document}
\section{Some section here}
\subsection{Sentinel \texorpdfstring{\icon{example-image-a}}{}}
\end{document}