在 moderncv 中自定义 \section 后 moderntimeline 出现问题

在 moderncv 中自定义 \section 后 moderntimeline 出现问题

我自定义了\section命令,moderncv使部分标题的颜色淡化。但现在这会弄乱我的moderntimeline,并移动它的标签。我已经发现这是由于\usetikzlibrary{positioning}。有人能弄清楚如何使用我的自定义\section而不影响moderntimeline吗?

\documentclass{moderncv}
\usepackage[firstyear=2007,lastyear=2015]{moderntimeline}
\usepackage{tikz}
\usetikzlibrary{fadings,patterns,positioning,fit,calc}

\tikzset{
  zero sep/.style = {inner sep=0pt, outer sep=0pt},
}

\moderncvstyle{classic}

\makeatletter
\renewcommand\section[1]{%
  \par\addvspace{2.5ex}%
  \phantomsection{}% reset the anchor for hyperrefs
  \addcontentsline{toc}{section}{#1}%
  \pgfmathsetmacro\randref{rand}
  \begin{tikzfadingfrompicture}[name=tikzsection \randref]
    \node[fill=white,anchor=south east,zero sep,minimum width=5cm,minimum height=2.5mm] (box node){};
    \node [text=white,anchor=base west,text depth=5pt,text height=12pt,zero sep,
    font=\normalfont\Large\bfseries,right=10pt of box node,
    text width=12cm,align=left] (text node) {\strut#1\strut};
    \node [fit={(box node)(text node)
      },zero sep] (myfit) {};
    \path let \p1=(myfit.south west), \p2=(myfit.north east), \n1={\x2-\x1}, \n2={\y2-\y1} in
    \pgfextra{\xdef\lenx{\n1} \xdef\leny{\n2}};
  \end{tikzfadingfrompicture}
    \begin{tikzpicture}[baseline=.5*5pt-.5*12pt]
      \path[path fading=tikzsection \randref, fit fading=false,left color=blue, right color=black]
      (-.5*\lenx,-.5*\leny) rectangle ++(\lenx,\leny);
    \end{tikzpicture}%
    \par\nobreak\addvspace{1ex}\@afterheading%
}
\makeatother 

例子

\begin{document}

\section{First section}
\tlcventry{2008}{2009}{Student in aerospace engineering}{University of Atlantis}{Atlantis}{}{Majors: Aqua Systems, Fluid Mechanics}
\section{Second muuuuch longer section}
Some text
\section{Short}
Some text

\end{document}

答案1

这似乎是 中的一个错误moderntimeline。我建议您就此问题联系软件包作者。

我能够将问题追溯到 的定义,具体来说,是用于排版起始年份的样式\tltextstart的定义;原始定义是tl@startyear

\newcommand{\tltextstart}[2][base west]{%
   \tikzset{
       tl@startyear/.style={
           font=#2,
           name=tl@startyear,
           above=\tl@textstartabove,
           inner xsep=0pt,
           anchor=#1,
       }
   }
}

问题是,\tl@textstartabove使用 时似乎无法正确更新\tlcventry。解决方法是使用

\tikzset{
     tl@startyear/.style={
         font=\scriptsize,
         name=tl@startyear,
         above=\tl@width+1pt,
         inner xsep=0pt,
         anchor=base west,
     }
}

完整示例:

\documentclass{moderncv}
\usepackage[firstyear=2007,lastyear=2015]{moderntimeline}
\usepackage{tikz}
\usetikzlibrary{fadings,patterns,positioning,fit,calc}

\tikzset{
  zero sep/.style = {inner sep=0pt, outer sep=0pt},
}

\moderncvstyle{classic}

\makeatletter
\tikzset{
     tl@startyear/.style={
         font=\scriptsize,
         name=tl@startyear,
         above=\tl@width+1pt,
         inner xsep=0pt,
         anchor=base west,
     }
}

\renewcommand\section[1]{%
  \par\addvspace{2.5ex}%
  \phantomsection{}% reset the anchor for hyperrefs
  \addcontentsline{toc}{section}{#1}%
  \pgfmathsetmacro\randref{rand}
  \begin{tikzfadingfrompicture}[name=tikzsection \randref]
    \node[fill=white,anchor=south east,zero sep,minimum width=5cm,minimum height=2.5mm] (box node){};
    \node [text=white,anchor=base west,text depth=5pt,text height=12pt,zero sep,
    font=\normalfont\Large\bfseries,right=10pt of box node,
    text width=12cm,align=left] (text node) {\strut#1\strut};
    \node [fit={(box node)(text node)
      },zero sep] (myfit) {};
    \path let \p1=(myfit.south west), \p2=(myfit.north east), \n1={\x2-\x1}, \n2={\y2-\y1} in
    \pgfextra{\xdef\lenx{\n1} \xdef\leny{\n2}};
  \end{tikzfadingfrompicture}
    \begin{tikzpicture}[baseline=.5*5pt-.5*12pt]
      \path[path fading=tikzsection \randref, fit fading=false,left color=blue, right color=black]
      (-.5*\lenx,-.5*\leny) rectangle ++(\lenx,\leny);
    \end{tikzpicture}%
    \par\nobreak\addvspace{1ex}\@afterheading%
}
\makeatother 

\firstname{John}
\lastname{Doe}

\begin{document}

\section{First section}
\tlcventry{2008}{2009}{Student in aerospace engineering}{University of Atlantis}{Atlantis}{}{Majors: Aqua Systems, Fluid Mechanics}
\section{Second much longer section}
Some text
\section{Short}
Some text

\end{document}

结果:

在此处输入图片描述

相关内容