在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}

結果:

在此輸入影像描述

相關內容