
我正在隨機地進行實驗,並想知道是否在章節標題中插入一些 TikZ。
與article
, 這
\documentclass{article}
\usepackage{tikz}
\newcommand{\my}{\tikz\draw (0,0) circle (5pt);}
\begin{document}
\section{Introduction \protect\my}
\end{document}
作品。
但如果我使用moderncv
,這個
\documentclass{moderncv}
\usepackage{tikz}
\moderncvstyle{classic}
\newcommand{\my}{\tikz\draw (0,0) circle (5pt);}
\begin{document}
\section{Introduction \protect\my}
\end{document}
不起作用。
為什麼?
答案1
hyperref
這是和tikz
、 和moderncv
負載之間的衝突hyperref
。
解決方案涉及使用\texorpdfstring
來定義您的命令。
像這樣的事情:
\texorpdfstring{tikz code}{alternative (empty)}
您的 MWE 應如下圖所示:
\documentclass{moderncv}
\usepackage{tikz}
\moderncvstyle{classic}
\newcommand{\my}{\texorpdfstring{\tikz\draw (0,0) circle (5pt);}{}}
\firstname{John}
\familyname{Doe}
\begin{document}
\section{Introduction \protect\my}
\end{document}