moderntimeline:在条形图的开始和结束时对齐文本

moderntimeline:在条形图的开始和结束时对齐文本

moderntimeline 再次出现了一些问题:


\documentclass{moderncv}
\moderncvstyle{casual}
\usepackage[firstyear=1999,lastyear=2012]{moderntimeline}

\makeatletter \pgfmathsetmacro\tl@textstartabove{\tl@width-2pt} \renewcommand{\tldatelabelcventry}[8][color1]{% \pgfmathsetmacro\tl@endyear{\tl@lastyear} \pgfmathsetmacro\tl@startfraction{(#2-\tl@firstyear)/(\tl@lastyear-\tl@firstyear)}% \pgfmathsetmacro\tl@endfraction{(\tl@endyear-\tl@firstyear)/(\tl@lastyear-\tl@firstyear)}% \cventry{\tikz[baseline]{ \fill [\tl@runningcolor] (0,0) rectangle (\hintscolumnwidth,\tl@runningwidth); \fill [#1] (0,0) ++(\tl@startfraction*\hintscolumnwidth,0pt) node [tl@startyear,yshift=11pt] {#3} node {$\bullet$}; } } {#4}{#5}{#6}{#7}{#8} } \makeatother

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

\firstname{John} \familyname{Doe}

\begin{document}

\makecvtitle

\tlcventry[cyan!60!black]{2007}{2010}{test}{test}{test}{}{test} \tllabelcventry[cyan!60!black]{2007}{2010}{Test}{test}{test}{test}{}{test} \tlmaxdates{2008}{2012} \tldatelabelcventry{2008}{Okt. 2008}{Test}{}{}{}{}{} \tldatelabelcventry{2012}{Okt. 2012}{Test}{}{}{}{}{} \tldatecventry[brown]{2011}{test}{}{test}{test}{}{test}

\end{document}

产品:
在此处输入图片描述
最好有:
在此处输入图片描述

原始的现代时间线也存在类似的问题: 在此处输入图片描述

答案1

\tldatelabelcventry中的实现(可能是)似乎有问题moderntimeline.sty;以下示例中的第二个条目向左移动:

\documentclass{moderncv}
\moderncvstyle{casual}
\usepackage[firstyear=1999,lastyear=2012]{moderntimeline}

\firstname{John}
\familyname{Doe}

\begin{document}

\makecvtitle

\tldatelabelcventry{2008}{Okt. 2008}{Test}{}{}{}{}{}
\tlmaxdates{2008}{2012}
\tldatelabelcventry{2008}{Okt. 2008}{Test}{}{}{}{}{}
\tldatelabelcventry{2012}{Okt. 2012}{Test}{}{}{}{}{}

\end{document}

在此处输入图片描述

在定义中使用适当的边界框解决了对齐问题(但标签与以下文本重叠):

\documentclass{moderncv}
\moderncvstyle{casual}
\usepackage[firstyear=1999,lastyear=2012]{moderntimeline}

\makeatletter
\renewcommand{\tldatelabelcventry}[8][color1]{%
\pgfmathsetmacro\tl@endyear{\tl@lastyear}%
\pgfmathsetmacro\tl@startfraction{(#2-\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 [#1] (0,0)
        ++(\tl@startfraction*\hintscolumnwidth,0pt)
        node [tl@startyear] {#3}
        node {$\bullet$};
   }
}
{#4}{#5}{#6}{#7}{#8}
}
\makeatother


\firstname{John}
\familyname{Doe}

\begin{document}

\makecvtitle

\tldatelabelcventry{2008}{Okt. 2008}{Test}{}{}{}{}{}
\tlmaxdates{2008}{2012}
\tldatelabelcventry{2008}{Okt. 2008}{Test}{}{}{}{}{}
\tldatelabelcventry{2012}{Okt. 2012}{Test}{}{}{}{}{}

\end{document}

在此处输入图片描述

使用原始问题中的代码,除了添加适当的边界框之外,还必须对标签的位置进行一些工作:

\documentclass{moderncv}
\moderncvstyle{casual}
\usepackage[firstyear=1999,lastyear=2012]{moderntimeline}


\makeatletter
\pgfmathsetmacro\tl@textstartabove{\tl@width-2pt}
\renewcommand{\tldatelabelcventry}[8][color1]{%
\pgfmathsetmacro\tl@endyear{\tl@lastyear}%
\pgfmathsetmacro\tl@startfraction{(#2-\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 [#1] (0,0)
        ++(\tl@startfraction*\hintscolumnwidth,0pt)
        node [tl@startyear,yshift=5pt,anchor=east] {#3}
        node {$\bullet$};
   }
}
{#4}{#5}{#6}{#7}{#8}
}
\makeatother
%
\tltextstart[north]{\scriptsize}
\tltextend[south]{\scriptsize}

\firstname{John}
\familyname{Doe}

\begin{document}

\makecvtitle

\tlcventry[cyan!60!black]{2007}{2010}{test}{test}{test}{}{test}
\tllabelcventry[cyan!60!black]{2007}{2010}{Test}{test}{test}{test}{}{test}
\tlmaxdates{2008}{2012}
\tldatelabelcventry{2008}{Okt. 2008}{Test}{}{}{}{}{}
\tldatelabelcventry{2012}{Okt. 2012}{Test}{}{}{}{}{}
\tldatecventry[brown]{2011}{test}{}{test}{test}{}{test}

\end{document}

在此处输入图片描述

最后,为了获得所需的对齐,可以生成一个类似 \tldatelabelcventry但带有另一个可选参数的命令,允许指定标签的锚点;这可以借助包轻松完成xparse

\documentclass{moderncv}
\moderncvstyle{casual}
\usepackage{xparse}
\usepackage[firstyear=1999,lastyear=2012]{moderntimeline}


\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}
}
\makeatother
%
\tltextstart[north]{\scriptsize}
\tltextend[south]{\scriptsize}

\firstname{John}
\familyname{Doe}

\begin{document}

\makecvtitle

\tlcventry[cyan!60!black]{2007}{2010}{test}{test}{test}{}{test}
\tllabelcventry[cyan!60!black]{2007}{2010}{Test}{test}{test}{test}{}{test}
\tlmaxdates{2008}{2012}
\tldatelabelcventryn[west]{2008}{Okt. 2008}{Test}{}{}{}{}{}
\tldatelabelcventryn[center][red!70!black]{2010}{Okt. 2010}{Test}{}{}{}{}{}
\tldatelabelcventryn[east]{2012}{Okt. 2012}{Test}{}{}{}{}{}
\tldatecventry[brown]{2011}{test}{}{test}{test}{}{test}

\end{document}

在此处输入图片描述

答案2

快速的解决方法是在每个条目之前和之后设置标签的锚点

%set the anchor as you prefer
\tltextstart[south east]{\scriptsize}
\tltextend[north west]{\scriptsize} 
%--------

\tldatelabelcventry{2008}{Okt. 2008}{Test}{}{}{}{}{}

%------
%set it back as default
\tltextstart[south]{\scriptsize}
\tltextend[north]{\scriptsize}

相关内容