8

I am new to LaTeX and TikZ.

I need to draw a timeline with text written in different colors representing different parallel steps of my project.

Here's my code:

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[%
    every node/.style={
        font=\scriptsize,
        % Better alignment, see https://tex.stackexchange.com/questions/315075
        text height=1ex,
        text depth=.25ex,
    },
]

% draw horizontal line   
\draw[-] (0,0) -- (15,0);

% draw vertical lines
\foreach \x in {0,1.25,...,15}{
    \draw (\x cm,3pt) -- (\x cm,0pt);
}

\foreach \x in {0,5,...,15}{
    \draw (\x cm,3pt) -- (\x cm,8pt);
}

% place axis labels
\node[anchor=north] at (0,0) {Sep. 2024};
\node[anchor=north] at (2.5,0) {T3};
\node[anchor=north] at (5,0) {Sep. 2025};
\node[anchor=north] at (7.5,0) {T7};
\node[anchor=north] at (10,0) {Sep. 2026};
\node[anchor=north] at (12.5,0) {T11};
\node[anchor=north] at (15,0) {Sep. 2027};

% Text markers
\draw[color=black, thick] (0,0.4) -- (0,0.7) node[above, text=blue] {Step 1};
\draw[color=black, thick] (7.5,0.2) -- (7.5,0.5) node[above, text=orange] {Example};
\draw[color=black, thick] (12.5,0.2) -- (12.5,0.5) node[above, text=ForestGreen] {Enseignement};
\draw[color=black, thick] (1.25, -0.2) -- (1.25, -0.5) node[below, text=blue] {I would like a list here With different colors};


% Legend
\node[draw, circle, fill=blue, inner sep=1pt, label={right:Valorisation}] at (4,-2) {};
\node[draw, circle, fill=orange, inner sep=1pt, label={right:Recherche}] at (6.5,-2) {};
\node[draw, circle, fill=ForestGreen, inner sep=1pt, label={right:Enseignement}] at (9,-2) {};

\end{tikzpicture}
\end{document}

I have two issues.

First, for each tick I would be able to write several entries presented as a list, but I don't know how to break a line. For example in the second tick I would like to have

"I would like a list here   
 With different colors"

I tried using the "\\" within the braces but TeX doesn't recognize it.

Also, for different entries of my lsit I would like to be able to use different colors, but I feel like I can only enter one color. For instance, I would like the expression "I would like a list here" to be blue whereas "With different colors" to be orange.

Is it possible to do so?

1
  • Welcome to TeX.SE!
    – Mensch
    Commented Apr 25 at 7:39

2 Answers 2

8

If you use align=center you can use \\ in your node text.

To differentiate the colors, use \textcolor{<color>}{<text>} inside the node instead to use the text option.

\documentclass{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[%
    every node/.style={
        font=\scriptsize,
        % Better alignment, see https://tex.stackexchange.com/questions/315075
        text height=1ex,
        text depth=.25ex,
    },
]

% draw horizontal line   
\draw[-] (0,0) -- (15,0);

% draw vertical lines
\foreach \x in {0,1.25,...,15}{
    \draw (\x cm,3pt) -- (\x cm,0pt);
}

\foreach \x in {0,5,...,15}{
    \draw (\x cm,3pt) -- (\x cm,8pt);
}

% place axis labels
\node[anchor=north] at (0,0) {Sep. 2024};
\node[anchor=north] at (2.5,0) {T3};
\node[anchor=north] at (5,0) {Sep. 2025};
\node[anchor=north] at (7.5,0) {T7};
\node[anchor=north] at (10,0) {Sep. 2026};
\node[anchor=north] at (12.5,0) {T11};
\node[anchor=north] at (15,0) {Sep. 2027};

% Text markers
\draw[color=black, thick] (0,0.4) -- (0,0.7) node[above, text=blue] {Step 1};
\draw[color=black, thick] (7.5,0.2) -- (7.5,0.5) node[above, text=orange] {Example};
\draw[color=black, thick] (12.5,0.2) -- (12.5,0.5) node[above, text=ForestGreen] {Enseignement};
\draw[color=black, thick] (1.25, -0.2) -- (1.25, -0.5) node[below=3.5mm, align=center] {\textcolor{blue}{I would like a list here}\\ \textcolor{orange}{With different colors}};


% Legend
\node[draw, circle, fill=blue, inner sep=1pt, label={right:Valorisation}] at (4,-2) {};
\node[draw, circle, fill=orange, inner sep=1pt, label={right:Recherche}] at (6.5,-2) {};
\node[draw, circle, fill=ForestGreen, inner sep=1pt, label={right:Enseignement}] at (9,-2) {};

\end{tikzpicture}
\end{document}

enter image description here

2
  • Thank you very much! This is exactly what I needed.
    – Yan
    Commented Apr 25 at 8:07
  • @Yan You're welcome, and thank you for accepting my answer.
    – CarLaTeX
    Commented Apr 25 at 8:08
2

Solution

Here are a few things, you could do, and there may be more. A few remarks:

  • added some missing parts
  • reduced code noise for my eyes ;-)
  • for some reason the every node statement caused trouble, so I removed it for now
  • there are several ways to make node text break; restricting the text width is one of them, see pgfmanual on node text
  • I introduced it as a separate style runtxt
  • if you name your node of interest, here (A), things become easier
  • just anchor pseudocodish (A.south over B.north)
  • put regular LaTeX text inside, like a list
  • stack them, here with default, which is unbroken and centered

Make your choice. However, some things remain to be done:

  • positioning of your legend (may be you put it as a \pic ?)
  • your every node style needs at least a review to use it

General suggestions

As a general remark I wouldn't overdo such a diagram. Are you aware of the gantt chart, built on Tikz?

If you really have much to handle, perhaps, for the display part, you may want to peek into project management software. If you don't have it in a MS-Office world, this Open Workbench might be worth a look (https://sourceforge.net/projects/openworkbench/). // See a screenshot for a search for images for Open Workbench below.

result

\documentclass[border=3mm]{standalone}
\usepackage[dvipsnames]{xcolor} % <<<

\usepackage{tikz}

\begin{document}
 \begin{tikzpicture}[%
%       every node/.style={
%           font=\scriptsize,
%           % Better alignment, see https://tex.stackexchange.com/questions/315075
%           text height=1ex,
%           text depth=.25ex,
%       },
        runtxt/.style={text width=25mm},    % <<<
    ]
    
    % draw horizontal line   
    \draw[-] (0,0) -- (15,0);
    
    % draw vertical lines
    \foreach \x in {0,1.25,...,15}{
        \draw (\x cm,3pt) -- (\x cm,0pt);
    }
    
    \foreach \x in {0,5,...,15}{
        \draw (\x cm,3pt) -- (\x cm,8pt);
    }
    
    % place axis labels
    \node[anchor=north] at (0,0) {Sep. 2024};
    \node[anchor=north] at (2.5,0) {T3};
    \node[anchor=north] at (5,0) {Sep. 2025};
    \node[anchor=north] at (7.5,0) {T7};
    \node[anchor=north] at (10,0) {Sep. 2026};
    \node[anchor=north] at (12.5,0) {T11};
    \node[anchor=north] at (15,0) {Sep. 2027};
    
    % Text markers
    \draw[color=black, thick] 
                            (0,0.4) -- (0,0.7) 
                            node[above, text=blue] {Step 1};
    \draw[color=black, thick] 
                            (7.5,0.2) -- (7.5,0.5) 
                            node[above, text=orange] {Example};
    \draw[color=black, thick] 
                            (12.5,0.2) -- (12.5,0.5) 
                            node[above, text=ForestGreen] {Enseignement};
    \draw[color=black, thick,runtxt]                % <<<
                            (1.25, -0.2) -- (1.25, -0.5) 
                            node[below, text=blue] (A)
                                {I would like a 
                                list here With different colors};
    
    % ~~~ demonstrating some options ~~~~~~~
    \node[anchor=north,runtxt,teal] (B) at (A.south){
        \begin{itemize}         % use regular LaTeX, BUT NO \tikz
         \item if you like it
         \item and you want it
         \item put a list on it
        \end{itemize}
    };
    \node[anchor=north,red] (C1) at (B.south) {
        This could be the first row
    };
    \node[anchor=north,red!100!orange!50,fill=yellow!20] (C2) at (C1.south) {
        of your list
    };
    
    % Legend
    \node[draw, circle, fill=blue, inner sep=1pt, label={right:Valorisation}] at (4,-2) {};
    \node[draw, circle, fill=orange, inner sep=1pt, label={right:Recherche}] at (6.5,-2) {};
    \node[draw, circle, fill=ForestGreen, inner sep=1pt, label={right:Enseignement}] at (9,-2) {};

 \end{tikzpicture}
\end{document}

Impressions about Open Workbench:

OW

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .