moderncv 中的 Moderntimeline:如何正确显示月份并添加第二条时间线?

moderncv 中的 Moderntimeline:如何正确显示月份并添加第二条时间线?

我正在尝试使用moderncv和创建我的简历Moderntimeline。基于回答我添加了新功能以在时间轴上显示月份:

\documentclass[12pt, a4paper, sans]{moderncv}
\moderncvstyle{classic}
\moderncvcolor{blue} 
\usepackage[utf8]{inputenc}
\usepackage[scale=0.91]{geometry}    % Width of the entire CV
\setlength{\hintscolumnwidth}{4.1cm} % Width of the timeline on your left
\usepackage{pdfpages/pdfpages}
\usepackage{moderntimeline/moderntimeline}
\usepackage{xpatch/xpatch}
\usepackage{color, graphicx}
\usepackage{comment}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% for timeline

\makeatletter
\pgfmathsetmacro\tl@textstartabove{\tl@width-2pt}
\NewDocumentCommand\tldatelabelcventryn{O{center}O{color1}mmmmmmm}{%
\pgfmathsetmacro\tl@endyear{\tl@lastyear}%
\pgfmathsetmacro\tl@startfraction{(#3-\tl@firstyear)/(\tl@lastyear-\tl@firstyear)}%
\pgfmathsetmacro\tl@endfraction{(\tl@endyear-\tl@firstyear)/(\tl@lastyear-\tl@firstyear)}%
 \cventry{\tikz[baseline]{%
     \useasboundingbox (0,-1.5ex) rectangle (\hintscolumnwidth,1ex);
     \fill [\tl@runningcolor] (0,0)
        rectangle (\hintscolumnwidth,\tl@runningwidth);
     \fill [#2] (0,0)
        ++(\tl@startfraction*\hintscolumnwidth,0pt)
        node [tl@startyear,yshift=5pt,anchor=#1] {#4}
        node {$\bullet$};
   }
}
{#5}{#6}{#7}{#8}{#9}
}
\newcommand\tllabelcventryn[9][color1]{%
  \gdef\Argi{#1}%
  \gdef\Argii{#2}%
  \gdef\Argiii{#3}%
  \gdef\Argiv{#4}%
  \gdef\Argv{#5}%
  \gdef\Argvi{#6}%
  \gdef\Argvii{#7}%
  \gdef\Argviii{#8}%
  \gdef\Argix{#9}%
  \auxtllabelcventryn
}
\def\auxtllabelcventryn#1{%
  \gdef\Argx{#1}%
\pgfmathsetmacro\tl@endyear{ifthenelse(\Argiii==0,\tl@lastyear,\Argiii)}
\pgfmathsetmacro\tl@startfraction{(\Argii-\tl@firstyear)/(\tl@lastyear-\tl@firstyear)}%
\pgfmathsetmacro\tl@endfraction{(\tl@endyear-\tl@firstyear)/(\tl@lastyear-\tl@firstyear)}%
 \cventry{\tikz[baseline=0pt]{
     \fill [\tl@runningcolor] (0,0)
        rectangle (\hintscolumnwidth,\tl@runningwidth);
     \useasboundingbox (0,-1.5ex)
        rectangle (\hintscolumnwidth,1ex);
     \fill [\Argi] (0,0)
        ++(\tl@startfraction*\hintscolumnwidth,0pt)
        node [tl@startyear,anchor=north east] {\Argiv} node [tl@startyear,above] {\Argv}
        rectangle (\tl@endfraction*\hintscolumnwidth,\tl@width-1pt);
     \pgfmathsetlength{\pgf@xa}{\Argiii} \ifdim\pgf@xa=0pt
        \shade [left color=\Argi] (\tl@startfraction*\hintscolumnwidth,0)
            rectangle (\tl@endfraction*\hintscolumnwidth,\tl@width);
     \else
        \fill [\Argi] (\tl@startfraction*\hintscolumnwidth,0)
            rectangle (\tl@endfraction*\hintscolumnwidth,\tl@width);
     \fi
     }
}
{\Argvi}{\Argvii}{\Argviii}{\Argix}{\Argx}%
}
\makeatother
%
\tltextstart[north]{\scriptsize}
\tltextend[south]{\scriptsize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 

\tlmaxdates{2005}{2013}      % timeline for education


\tltextstart[north]{\scriptsize}
\tltextend[south]{\scriptsize}



\begin{document}

\section{first timeline}
\tllabelcventryn[cyan!60!black]{2005}{2011}{Dec 2005}{\hspace{5.8cm} Jan 2011}{Test5}{}{}{}{test}

\vspace{50pt}

\section{second timeline}
\tllabelcventryn[cyan!60!black]{2008}{2011}{Dec 2008}{\hspace{2.8cm} Jan 2011}{Test5}{}{}{}{test}

\end{document}

在此处输入图片描述

  1. 我对开始日期有问题。我不知道如何在时间线上移动它们。\hspace{5.8cm}对他们来说不起作用,部分开始日期被截断
  2. 我需要创建单独的时间线,例如\tlmaxdates{2007}{2012}

答案1

我不太确定这是否是你想要的(并且它可能会破坏moderncv包中的其他一些格式)。

似乎只需\tlmaxdates在文档正文中重新设置即可。因此,如果您想创建另一条具有不同最小和最大年份的时间线,只需在调用之前放置此宏即可\tllabelcventryn

至于标签与日期的对齐方式,我建议开始日期左对齐,结束日期右对齐。这样可以降低标签超出时间线的风险。当然,如果时间线很短,可能会看起来有点奇怪。

考虑以下代码(我移动了第一次调用\tlmaxdates以演示您可以在主体内部多次调用它。我还添加了\name,因为否则会由于未定义的宏而出现错误。最后,我删除了一些对于此示例不必要的代码):

\documentclass[12pt, a4paper, sans]{moderncv}
\usepackage[utf8]{inputenc}
\usepackage[scale=0.91]{geometry}    % Width of the entire CV
\usepackage{moderntimeline}

\moderncvstyle{classic}
\moderncvcolor{blue} 
\setlength{\hintscolumnwidth}{4.1cm} % Width of the timeline on your left

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% for timeline

\makeatletter
\newcommand\tllabelcventryn[9][color1]{%
  \gdef\Argi{#1}%
  \gdef\Argii{#2}%
  \gdef\Argiii{#3}%
  \gdef\Argiv{#4}%
  \gdef\Argv{#5}%
  \gdef\Argvi{#6}%
  \gdef\Argvii{#7}%
  \gdef\Argviii{#8}%
  \gdef\Argix{#9}%
  \auxtllabelcventryn
}
\def\auxtllabelcventryn#1{%
  \gdef\Argx{#1}%
\pgfmathsetmacro\tl@textstartabove{\tl@width-2pt}
\pgfmathsetmacro\tl@endyear{ifthenelse(\Argiii==0,\tl@lastyear,\Argiii)}
\pgfmathsetmacro\tl@startfraction{(\Argii-\tl@firstyear)/(\tl@lastyear-\tl@firstyear)}%
\pgfmathsetmacro\tl@endfraction{(\tl@endyear-\tl@firstyear)/(\tl@lastyear-\tl@firstyear)}%
 \cventry{\tikz[baseline=0pt]{
     \fill [\tl@runningcolor] (0,0)
        rectangle (\hintscolumnwidth,\tl@runningwidth);
     \useasboundingbox (0,-1.5ex)
        rectangle (\hintscolumnwidth,1ex);
     \fill [\Argi] (0,0)
        ++(\tl@startfraction*\hintscolumnwidth,0pt)
        node [tl@startyear,anchor=north west] {\Argiv} 
        rectangle (\tl@endfraction*\hintscolumnwidth,\tl@width-1pt) node [tl@endyear,anchor=south east] {\Argv};
     \pgfmathsetlength{\pgf@xa}{\Argiii} \ifdim\pgf@xa=0pt
        \shade [left color=\Argi] (\tl@startfraction*\hintscolumnwidth,0)
            rectangle (\tl@endfraction*\hintscolumnwidth,\tl@width);
     \else
        \fill [\Argi] (\tl@startfraction*\hintscolumnwidth,0)
            rectangle (\tl@endfraction*\hintscolumnwidth,\tl@width);
     \fi
     }
}
{\Argvi}{\Argvii}{\Argviii}{\Argix}{\Argx}%
}
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
\name{John}{Doe}

\begin{document}

\tlmaxdates{2005}{2013}      % timeline for education

\section{first timeline}
\tllabelcventryn[cyan!60!black]{2005}{2011}{Dec 2005}{\hspace{5.8cm} Jan 2011}{Test5}{}{}{}{test}

\vspace{50pt}

\section{second timeline}
\tllabelcventryn[cyan!60!black]{2008}{2011}{Dec 2008}{\hspace{2.8cm} Jan 2011}{Test5}{}{}{}{test}

\tllabelcventryn[cyan!60!black]{2007}{2012}{Dec 2007}{\hspace{2.8cm} Jan 2012}{Test5}{}{}{}{test}

\tlmaxdates{2008}{2020}      % timeline for something else

\vspace{50pt}

\section{third timeline}
\tllabelcventryn[cyan!60!black]{2008}{2017}{Dec 2008}{\hspace{2.8cm} Jan 2017}{Test5}{}{}{}{test}

\end{document}

输出是这样的(可以看到第三条时间线调整了最小值和最大值):

在此处输入图片描述

相关内容