\cventry 与 \url 一起使用 %

\cventry 与 \url 一起使用 %

我正在使用\url内的命令\cventry。不幸的是,我的网址包含 %。此符号似乎会导致此错误:

 Paragraph ended before \\cventry was complete. []

我能做什么呢?

这里有一些代码:

\cventry{Test 1}{}{}{}{\url{http://example.com/2Fs40993} No Problem}
\cventry{Test 2}{}{}{}{\url{http://example.com/%2Fs40993} Problem}

答案1

您可以%用 来掩盖\

请使用以下 MWE 检查部分测试。您将在其中找到:

\cventry{Test 2}{}{}{}{\url{http://example.com/\%2Fs40993} Problem}{}

为了避免错误消息,请参阅最后添加的一对{}

完成 MWE:

\documentclass[11pt,a4paper,sans]{moderncv} 

\moderncvstyle{classic} 
\moderncvcolor{blue} 

% character encoding
 \usepackage[utf8]{inputenc} 

% adjust the page margins
\usepackage[scale=0.75]{geometry}

%\usepackage{url}

% personal data
\name{John}{Doe} 
\title{Resumé title}
\address{street and number}{postcode city}{country}% optional, 
\phone[mobile]{+1~(234)~567~890}                   % optional, 
\phone[fixed]{+2~(345)~678~901}
\phone[fax]{+3~(456)~789~012}
\email{[email protected]}                               % optional, remove / comment the line if not wanted
\homepage{www.johndoe.com}                         % optional, remove / comment the line if not wanted
\social[linkedin]{john.doe}                        % optional, remove / comment the line if not wanted
\social[twitter]{jdoe}                             % optional, remove / comment the line if not wanted
\social[github]{jdoe}                              % optional, remove / comment the line if not wanted
\extrainfo{additional information}                 % optional, remove / comment the line if not wanted
\photo[64pt][0.4pt]{example-image-a}               % optional, 
\quote{Some quote}                                 % optional, 

\setlength{\footskip}{66pt}


%----------------------------------------------------------------------------------
%            content
%----------------------------------------------------------------------------------
\begin{document}

%-----       resume       ---------------------------------------------------------
\makecvtitle

\section{Education}
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}  % arguments 3 to 6 can be left empty
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}

\section{Master thesis}
\cvitem{title}{\emph{Title}}
\cvitem{supervisors}{Supervisors}
\cvitem{description}{Short thesis abstract}

\section{Test}
\cventry{Test 1}{}{}{}{\url{http://example.com/2Fs40993} No Problem}{}
\cventry{Test 2}{}{}{}{\url{http://example.com/\%2Fs40993} Problem}{}

\end{document}

部分测试的结果如下:

在此处输入图片描述

正如@egreg 的评论所提到的,您也可以使用\urldef如下命令:

\urldef{\testurl}\url{http://example.com/%2Fs40993}
\cventry{Test 3}{}{}{}{\testurl}{}

结果与上面相同。

相关内容