调整(beamer)tikz 链中的节点颜色

调整(beamer)tikz 链中的节点颜色

关于此处发布的问题和答案,修改 beamer 中的时间线,我该如何调整此代码以允许不同颜色的节点?

举个例子,随着时间的推移和事件的发展,我希望能够按顺序为节点点着色:

黄色 - 黄色 - 蓝色 - 蓝色 - 蓝色 - 蓝色 - 蓝色

答案1

在的定义中\Task作如下修改:

\node[inner=#1,font=\footnotesize\sffamily\color{textcolor}, fill=#1]
    (c\the\numexpr\value{task}+1\relax) {};

然后您可以将可选参数设为填充颜色:

\Task[red]{Enseignant\\(M, L, Prépa, Secondaire) \\ 2009-2012}

默认值仍为circlecolor

在此处输入图片描述

请注意,我假设您实际上并不想要圆圈内有文字,这是之前使用可选参数的方式。

答案2

您可以使用overlay-beamer-stylestikz 库随着时间的推移为圆圈着色:

\documentclass[svgnames]{beamer}

\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

%\usepackage[margin=3cm]{geometry}
\usepackage{ragged2e}
\usepackage{fourier}
\usepackage{tikz} 
\usetikzlibrary{chains,shapes.arrows,fit}

\definecolor{arrowcolor}{RGB}{201,216,232}% color for the arrow filling
\definecolor{circlecolor}{RGB}{79,129,189}% color for the inner circles filling
\colorlet{textcolor}{white}% color for the text inside the circles
\colorlet{bordercolor}{white}% color for the outer border of circles

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\usetikzlibrary{overlay-beamer-styles}

\newcounter{task}

\newlength\taskwidth% width of the box for the task description
\newlength\taskvsep% vertical distance between the task description and arrow

\setlength\taskwidth{2.5cm}
\setlength\taskvsep{17pt}

\def\taskpos{}
\def\taskanchor{}

\newcommand\task[1]{%
  {\parbox[t]{\taskwidth}{\scriptsize\Centering#1}}}

\tikzset{
inner/.style={
  on chain,
  circle,
  inner sep=4pt,
  fill=circlecolor,
  line width=1.5pt,
  draw=bordercolor,
  text width=1.2em,
  align=center,
  text height=1.25ex,
  text depth=0ex,
  background default fill=circlecolor
},
on grid
}

\newcommand\Task[2][]{%
\node[inner xsep=0pt] (c1) {\phantom{A}};
\stepcounter{task}
\ifodd\thetask\relax
  \renewcommand\taskpos{\taskvsep}\renewcommand\taskanchor{south}
\else
  \renewcommand\taskpos{-\taskvsep}\renewcommand\taskanchor{north}
\fi
\node[inner,#1,font=\footnotesize\sffamily\color{textcolor}]    
  (c\the\numexpr\value{task}+1\relax) {};
\node[anchor=\taskanchor,yshift={\taskpos*2}] 
  at (c\the\numexpr\value{task}+1\relax) (x) {\task{#2}};
\draw[blue] (c\the\numexpr\value{task}+1\relax) -- (x);
}

\newcommand\drawarrow{% the arrow is placed in the background layer 
                                                     % after the node for the tasks have been placed
\ifnum\thetask=0\relax
  \node[on chain] (c1) {}; % if no \Task command is used, the arrow will be drawn
\fi
\node[on chain] (f) {};
\begin{pgfonlayer}{background}
\node[
  inner sep=10pt,
  single arrow,
  single arrow head extend=0.8cm,
  draw=none,
  fill=arrowcolor,
  fit= (c1) (f)
] (arrow) {};
\fill[white] % the decoration at the tail of the arrow
  (arrow.before tail) -- (c1|-arrow.west) -- (arrow.after tail) -- cycle;
\end{pgfonlayer}
}

\newenvironment{timeline}[1][node distance=.75\taskwidth]
  {\par\noindent\begin{tikzpicture}[start chain,#1]}
  {\drawarrow\end{tikzpicture}\par}

\begin{document}

\begin{frame}
\begin{columns}
\column{13cm}
\setcounter{task}{0}
\begin{timeline}[node distance=.57\taskwidth]
\Task[background fill=yellow,fill on=<+->]{Maitrise Physique\\Magistère Mécanique\\ 1997-2005}
\Task[background fill=yellow,fill on=<+->]{Chercheur associé\\ 2005-2007}
\Task[background fill=blue,fill on=<+->]{Doctorant\\Enseignant \\ 2007-2009}
\Task[background fill=blue,fill on=<+->]{Enseignant\\(M, L, Prépa, Secondaire) \\ 2009-2012}
\Task[background fill=blue,fill on=<+->]{Doctorant\\Enseignant \\ 2012-2013}
\Task[background fill=blue,fill on=<+->]{Deux stages post-doctoraux\\2014-2016}
\Task[background fill=blue,fill on=<+->]{ATER/LRU \\ Depuis 2016}
\end{timeline}

\vspace{1cm}

\end{columns}
\end{frame}

\end{document}

在此处输入图片描述

相关内容