ModernCV 中逗号前不需要空格

ModernCV 中逗号前不需要空格

我在删除逗号前的空格时遇到了一些麻烦。

例如我有以下两个定义:

\newcommand*{\cvshortentry}[7][.25em]{}
\renewcommand*{\cvshortentry}[7][.25em]{%
    \cvitem[#1]{#2}{%year
        {\bfseries{#3}} %title 
        \ifthenelse{\equal{#4}{}}{}{, {#4}}
        \ifthenelse{\equal{#5}{}}{}{, #5}
        .\strut%
        \ifx&#6&%
        \else{\newline{}\begin{minipage}[t]{\linewidth}\small#6\end{minipage}}\fi
        \ifx&#7&%
        \else{\newline{}\begin{minipage}[t]{\linewidth}\small{\slshape#7}\end{minipage}}\fi
    }
    }


\newcommand{\publication}[6]{
    \cvitem{#1}{%year
        {#2} %authors
        {, #3} %title   
        {\slshape, #4} %journal / status
        {\small#5}
    }
}

像这样填充:

\section{Current Projects}
\cvshortentry{}{Poject Name}{Some description of the project}{\small \textcolor{bluee}{some more comments}}{}{}

\section{Selected Publications}
\publication{2018}{I.M. Lopez, J. Doe}{Title of article}{Journal}{\textcolor{bluee}{some comments}}{}

它会产生以下输出,并且在逗号前会出现不需要的空格。

在此处输入图片描述

我可能做错了什么,\cvitem但我尝试了很多不同的方法,但都无法解决。

那么,我该如何删除逗号和点之前的不需要的空格呢?

谢谢。

答案1

下次您能添加一个简短的可编译代码来代替给定的代码片段吗?

要去掉逗号前的空格,您需要在两个命令的定义中添加%或删除逗号前的空格。%

您可以省略第一行(\newcommand在下一行使用):

\newcommand*{\cvshortentry}[7][.25em]{}

您的定义\publication}[6]有错误,您只定义了 5 个参数,应该考虑参数为空的情况。

因此请将您的定义更改为:

\newcommand*{\cvshortentry}[7][.25em]{%
    \cvitem[#1]{#2}{%year
        {\bfseries{#3}}% title 
        \ifthenelse{\equal{#4}{}}{}{, {#4}}%
        \ifthenelse{\equal{#5}{}}{}{, #5}%
        .\strut%
        \ifx&#6&%
        \else{\newline{}\begin{minipage}[t]{\linewidth}\small#6\end{minipage}}\fi%
        \ifx&#7&%
        \else{\newline{}\begin{minipage}[t]{\linewidth}\small{\slshape#7}\end{minipage}}\fi%
    }%
}

\newcommand{\publication}[6]{%
    \cvitem{#1}{% year
        {#2}% authors
        {, #3}% title   
        {\slshape, #4}% journal / status
        {\ifthenelse{\equal{#5}{}}{}{\small, #5}}%
        {\ifthenelse{\equal{#6}{}}{}{, #6}}%
        .%
    }%
}

完整代码如下

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

\moderncvstyle{classic} % casual, classic, banking, oldstyle and fancy
\moderncvcolor{blue} 

\usepackage[utf8]{inputenc}

\usepackage[scale=0.75]{geometry}

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

\setlength{\footskip}{66pt}

%\newcommand*{\cvshortentry}[7][.25em]{}
\newcommand*{\cvshortentry}[7][.25em]{%
    \cvitem[#1]{#2}{%year
        {\bfseries{#3}}% title 
        \ifthenelse{\equal{#4}{}}{}{, {#4}}%
        \ifthenelse{\equal{#5}{}}{}{, #5}%
        .\strut%
        \ifx&#6&%
        \else{\newline{}\begin{minipage}[t]{\linewidth}\small#6\end{minipage}}\fi%
        \ifx&#7&%
        \else{\newline{}\begin{minipage}[t]{\linewidth}\small{\slshape#7}\end{minipage}}\fi%
    }%
}

\newcommand{\publication}[6]{%
    \cvitem{#1}{% year
        {#2}% authors
        {, #3}% title   
        {\slshape, #4}% journal / status
        {\ifthenelse{\equal{#5}{}}{}{\small, #5}}%
        {\ifthenelse{\equal{#6}{}}{}{, #6}}%
        .%
    }%
}


\begin{document}

\makecvtitle

\section{Current Projects}
\cvshortentry{}{Poject Name}{Some description of the project}{\small \textcolor{blue}{some more comments}}{}{}

\section{Selected Publications}
\publication{2018}{I.M. Lopez, J. Doe}{Title of article}{Journal}{\textcolor{blue}{some comments}}{}

\section{Education}
\cventry{year--year}{Degree}{Institution--3}{City--4}{\textit{Grade}--5}{Description--6}  % 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}

\end{document}

你得到了想要的结果:

在此处输入图片描述

相关内容