1

When I compile the following piece of code, I obtain a nice timeline in a short document. But, when I try to compile the same piece of code into a longer document (a 440 pages thesis), a specific date does not appear on my timeline as illustrated in this screenshot: enter image description here I observed that the problem appears when I have two timelines in my document. One only does not produce that error. Can you help me to fix that? Thanks!

\documentclass[fontsize=12pt,%
           twoside=semi,%
           headings=small,%
           chapterprefix=true,%
           listof=flat]%
{scrbook}


\usepackage{chronosys}
%%%%%%%%%%%%%%%%%%%%TIMELINE%%%%%%%%%%%%

\usepackage{tikz}

\usetikzlibrary{arrows, calc, decorations.markings, positioning}

\makeatletter
\newenvironment{timeline}[6]{%
    % #1 is startyear
    % #2 is tlendyear
% #3 is yearcolumnwidth
% #4 is rulecolumnwidth
% #5 is entrycolumnwidth
% #6 is timelineheight

\newcommand{\startyear}{#1}
\newcommand{\tlendyear}{#2}

\newcommand{\yearcolumnwidth}{#3}
\newcommand{\rulecolumnwidth}{#4}
\newcommand{\entrycolumnwidth}{#5}
\newcommand{\timelineheight}{#6}

\newcommand{\templength}{}

\newcommand{\entrycounter}{0}

% https://tex.stackexchange.com/questions/85528/checking-whether-or-not-a-node-has-been-previously-defined
% https://tex.stackexchange.com/questions/37709/how-can-i-know-if-a-node-is-already-defined
\long\def\ifnodedefined##1##2##3{%
    \@ifundefined{pgf@sh@ns@##1}{##3}{##2}%
}

\newcommand{\ifnodeundefined}[2]{%
    \ifnodedefined{##1}{}{##2}
}

\newcommand{\drawtimeline}{%
    \draw[timelinerule] (\yearcolumnwidth+5pt, 0pt) -- (\yearcolumnwidth+5pt, -\timelineheight);
    \draw (\yearcolumnwidth+0pt, -10pt) -- (\yearcolumnwidth+10pt, -10pt);
    \draw (\yearcolumnwidth+0pt, -\timelineheight+15pt) -- (\yearcolumnwidth+10pt, -\timelineheight+15pt);

    \pgfmathsetlengthmacro{\templength}{neg(add(multiply(subtract(\startyear, \startyear), divide(subtract(\timelineheight, 25), subtract(\tlendyear, \startyear))), 10))}
    \node[year] (year-\startyear) at (\yearcolumnwidth, \templength) {\startyear};

    \pgfmathsetlengthmacro{\templength}{neg(add(multiply(subtract(\tlendyear, \startyear), divide(subtract(\timelineheight, 25), subtract(\tlendyear, \startyear))), 10))}
    \node[year] (year-\tlendyear) at (\yearcolumnwidth, \templength) {\tlendyear};
}

\newcommand{\entry}[2]{%
    % #1 is the year
    % #2 is the entry text

    \pgfmathtruncatemacro{\lastentrycount}{\entrycounter}
    \pgfmathtruncatemacro{\entrycounter}{\entrycounter + 1}

    \ifdim \lastentrycount pt > 0 pt%
        \node[entry] (entry-\entrycounter) [below of=entry-\lastentrycount] {##2};
    \else%
        \pgfmathsetlengthmacro{\templength}{neg(add(multiply(subtract(\startyear, \startyear), divide(subtract(\timelineheight, 25), subtract(\tlendyear, \startyear))), 10))}
        \node[entry] (entry-\entrycounter) at (\yearcolumnwidth+\rulecolumnwidth+10pt, \templength) {##2};
    \fi

    \ifnodeundefined{year-##1}{%
        \pgfmathsetlengthmacro{\templength}{neg(add(multiply(subtract(##1, \startyear), divide(subtract(\timelineheight, 25), subtract(\tlendyear, \startyear))), 10))}
        \draw (\yearcolumnwidth+2.5pt, \templength) -- (\yearcolumnwidth+7.5pt, \templength);
        \node[year] (year-##1) at (\yearcolumnwidth, \templength) {##1};
    }

    \draw ($(year-##1.east)+(2.5pt, 0pt)$) -- ($(year-##1.east)+(7.5pt, 0pt)$) -- ($(entry-\entrycounter.west)-(5pt,0)$) -- (entry-\entrycounter.west);
}

\newcommand{\plainentry}[2]{% plainentry won't print date in the timeline
    % #1 is the year
    % #2 is the entry text

    \pgfmathtruncatemacro{\lastentrycount}{\entrycounter}
    \pgfmathtruncatemacro{\entrycounter}{\entrycounter + 1}

    \ifdim \lastentrycount pt > 0 pt%
        \node[entry] (entry-\entrycounter) [below of=entry-\lastentrycount] {##2};
    \else%
        \pgfmathsetlengthmacro{\templength}{neg(add(multiply(subtract(\startyear, \startyear), divide(subtract(\timelineheight, 25), subtract(\tlendyear, \startyear))), 10))}
        \node[entry] (entry-\entrycounter) at (\yearcolumnwidth+\rulecolumnwidth+10pt, \templength) {##2};
    \fi

    \ifnodeundefined{invisible-year-##1}{%
        \pgfmathsetlengthmacro{\templength}{neg(add(multiply(subtract(##1, \startyear), divide(subtract(\timelineheight, 25), subtract(\tlendyear, \startyear))), 10))}
        \draw (\yearcolumnwidth+2.5pt, \templength) -- (\yearcolumnwidth+7.5pt, \templength);
        \node[year] (invisible-year-##1) at (\yearcolumnwidth, \templength) {};
    }

    \draw ($(invisible-year-##1.east)+(2.5pt, 0pt)$) -- ($(invisible-year-##1.east)+(7.5pt, 0pt)$) -- ($(entry-\entrycounter.west)-(5pt,0)$) -- (entry-\entrycounter.west);
}

\begin{tikzpicture}
    \tikzstyle{entry} = [%
        align=left,%
        text width=\entrycolumnwidth,%
        node distance=10mm,%
        anchor=west]
    \tikzstyle{year} = [anchor=east]
    \tikzstyle{timelinerule} = [%
        draw,%
        decoration={markings, mark=at position 1 with {\arrow[scale=1.5]{latex'}}},%
        postaction={decorate},%
        shorten >=0.4pt]

    \drawtimeline
}
{
    \end{tikzpicture}
    \let\startyear\@undefined
    \let\tlendyear\@undefined
    \let\yearcolumnwidth\@undefined
    \let\rulecolumnwidth\@undefined
    \let\entrycolumnwidth\@undefined
    \let\timelineheight\@undefined
    \let\entrycounter\@undefined
    \let\ifnodedefined\@undefined
    \let\ifnodeundefined\@undefined
    \let\drawtimeline\@undefined
    \let\entry\@undefined
}
\makeatother

%%%%%%%%%%%%%%%%%FIN TIMELINE%%%%%%%%%%%%%%%%%%%%%

\begin{document}


\pagestyle{headings}



\begin{table}[!]


\begin{timeline}{2014}{2017}{2cm}{2.5cm}{10cm}{5cm}
\entry{2014}{Octobre. Enregistrement}
\entry{2014}{Novembre. Transcription}
\entry{2015}{Mars. Travail}
\entry{2016}{Avril. Reprise}
\entry{2017}{Septembre. Fin}
\end{timeline}

\caption{Chronologie}

\end{table}


\begin{table}[!]


\begin{timeline}{2014}{2017}{2cm}{2.5cm}{10cm}{5cm}
\entry{2014}{Octobre. Enregistrement}
\entry{2014}{Novembre. Transcription}
\entry{2015}{Mars. Travail}
\entry{2016}{Avril. Reprise}
\entry{2017}{Septembre. Fin}
\end{timeline}

\caption{Chronologie}

\end{table}

\end{document}
4
  • do you have all these blank lines in original? I doubt it, here timeline environment definition is wrong because of the blank line between the two {...} giant constructs.
    – user4686
    Commented Sep 30, 2017 at 16:11
  • anyway, as you said, this compiles fine (once the source code is corrected as per my previous comment), hence it is hard to guess what's wrong. Edit: there is some funny invisible-year-... business going on. Are you sure the 2015 did not become "invisible" in this sens from some other code in your big document?
    – user4686
    Commented Sep 30, 2017 at 16:13
  • @jfbu What would be the right code?
    – domi
    Commented Sep 30, 2017 at 16:56
  • 1
    hard to help if all you post is something which does not display the problem you describe...
    – user4686
    Commented Sep 30, 2017 at 18:12

1 Answer 1

2

The code posted here doesn't compile for me and the \timeline macro is different to the original source, which is here: How can you create a vertical timeline? I didn't try to find where it is different.

I replaced the timeline code that was posted with the code from the original source and provide two examples. The first example shows the years for each timeline entry. This can be done using the \entry macro. The second example shows the addition of timeline entries, but without displaying the year. This is done with the \plainentry macro.

This is the result:

enter image description here

This is the MWE:

\documentclass[fontsize=12pt,%
           twoside=semi,%
           headings=small,%
           chapterprefix=true,%
           listof=flat]%
{scrbook}


%\usepackage{chronosys}
\usepackage{verbatim}

%%%%%%%%%%%%%%%%%%%%TIMELINE%%%%%%%%%%%%

\usepackage{tikz}

\usetikzlibrary{arrows, calc, decorations.markings, positioning}
% https://tex.stackexchange.com/a/197140
\makeatletter
\newenvironment{timeline}[6]
{
    % #1 is startyear
    % #2 is tlendyear
    % #3 is yearcolumnwidth
    % #4 is rulecolumnwidth
    % #5 is entrycolumnwidth
    % #6 is timelineheight

    \newcommand{\startyear}{#1}
    \newcommand{\tlendyear}{#2}

    \newcommand{\yearcolumnwidth}{#3}
    \newcommand{\rulecolumnwidth}{#4}
    \newcommand{\entrycolumnwidth}{#5}
    \newcommand{\timelineheight}{#6}

    \newcommand{\templength}{}

    \newcommand{\entrycounter}{0}

    % http://tex.stackexchange.com/questions/85528/checking-whether-or-not-a-node-has-been-previously-defined
    % http://tex.stackexchange.com/questions/37709/how-can-i-know-if-a-node-is-already-defined
    \long\def\ifnodedefined##1##2##3{%
        \@ifundefined{pgf@sh@ns@##1}{##3}{##2}%
    }

    \newcommand{\ifnodeundefined}[2]{%
        \ifnodedefined{##1}{}{##2}
    }

    \newcommand{\drawtimeline}{%
        \draw[timelinerule] (\yearcolumnwidth+5pt, 0pt) -- (\yearcolumnwidth+5pt, -\timelineheight);
        \draw (\yearcolumnwidth+0pt, -10pt) -- (\yearcolumnwidth+10pt, -10pt);
        \draw (\yearcolumnwidth+0pt, -\timelineheight+15pt) -- (\yearcolumnwidth+10pt, -\timelineheight+15pt);

        \pgfmathsetlengthmacro{\templength}{neg(add(multiply(subtract(\startyear, \startyear), divide(subtract(\timelineheight, 25), subtract(\tlendyear, \startyear))), 10))}
        \node[year] (year-\startyear) at (\yearcolumnwidth, \templength) {\startyear};

        \pgfmathsetlengthmacro{\templength}{neg(add(multiply(subtract(\tlendyear, \startyear), divide(subtract(\timelineheight, 25), subtract(\tlendyear, \startyear))), 10))}
        \node[year] (year-\tlendyear) at (\yearcolumnwidth, \templength) {\tlendyear};
    }

    \newcommand{\entry}[2]{%
        % #1 is the year
        % #2 is the entry text

        \pgfmathtruncatemacro{\lastentrycount}{\entrycounter}
        \pgfmathtruncatemacro{\entrycounter}{\entrycounter + 1}

        \ifdim \lastentrycount pt > 0 pt%
        \node[entry] (entry-\entrycounter) [below of=entry-\lastentrycount] {##2};
        \else%
        \pgfmathsetlengthmacro{\templength}{neg(add(multiply(subtract(\startyear, \startyear), divide(subtract(\timelineheight, 25), subtract(\tlendyear, \startyear))), 10))}
        \node[entry] (entry-\entrycounter) at (\yearcolumnwidth+\rulecolumnwidth+10pt, \templength) {##2};
        \fi

        \ifnodeundefined{year-##1}{%
            \pgfmathsetlengthmacro{\templength}{neg(add(multiply(subtract(##1, \startyear), divide(subtract(\timelineheight, 25), subtract(\tlendyear, \startyear))), 10))}
            \draw (\yearcolumnwidth+2.5pt, \templength) -- (\yearcolumnwidth+7.5pt, \templength);
            \node[year] (year-##1) at (\yearcolumnwidth, \templength) {##1};
        }

        \draw ($(year-##1.east)+(2.5pt, 0pt)$) -- ($(year-##1.east)+(7.5pt, 0pt)$) -- ($(entry-\entrycounter.west)-(5pt,0)$) -- (entry-\entrycounter.west);
    }

    \newcommand{\plainentry}[2]{% plainentry won't print date in the timeline
        % #1 is the year
        % #2 is the entry text

        \pgfmathtruncatemacro{\lastentrycount}{\entrycounter}
        \pgfmathtruncatemacro{\entrycounter}{\entrycounter + 1}

        \ifdim \lastentrycount pt > 0 pt%
        \node[entry] (entry-\entrycounter) [below of=entry-\lastentrycount] {##2};
        \else%
        \pgfmathsetlengthmacro{\templength}{neg(add(multiply(subtract(\startyear, \startyear), divide(subtract(\timelineheight, 25), subtract(\tlendyear, \startyear))), 10))}
        \node[entry] (entry-\entrycounter) at (\yearcolumnwidth+\rulecolumnwidth+10pt, \templength) {##2};
        \fi

        \ifnodeundefined{invisible-year-##1}{%
            \pgfmathsetlengthmacro{\templength}{neg(add(multiply(subtract(##1, \startyear), divide(subtract(\timelineheight, 25), subtract(\tlendyear, \startyear))), 10))}
            \draw (\yearcolumnwidth+2.5pt, \templength) -- (\yearcolumnwidth+7.5pt, \templength);
            \node[year] (invisible-year-##1) at (\yearcolumnwidth, \templength) {};
        }

        \draw ($(invisible-year-##1.east)+(2.5pt, 0pt)$) -- ($(invisible-year-##1.east)+(7.5pt, 0pt)$) -- ($(entry-\entrycounter.west)-(5pt,0)$) -- (entry-\entrycounter.west);
    }

    \begin{tikzpicture}
    \tikzstyle{entry} = [%
    align=left,%
    text width=\entrycolumnwidth,%
    node distance=11mm,%
    anchor=west]
    \tikzstyle{year} = [anchor=east]
    \tikzstyle{timelinerule} = [%
    draw,%
    decoration={markings, mark=at position 1 with {\arrow[scale=1.5]{latex'}}},%
    postaction={decorate},%
    shorten >=0.4pt]

    \drawtimeline
}
{
    \end{tikzpicture}
    \let\startyear\@undefined
    \let\tlendyear\@undefined
    \let\yearcolumnwidth\@undefined
    \let\rulecolumnwidth\@undefined
    \let\entrycolumnwidth\@undefined
    \let\timelineheight\@undefined
    \let\entrycounter\@undefined
    \let\ifnodedefined\@undefined
    \let\ifnodeundefined\@undefined
    \let\drawtimeline\@undefined
    \let\entry\@undefined
}
\makeatother

%%%%%%%%%%%%%%%%%FIN TIMELINE%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\pagestyle{headings}
%\begin{table}[!]

Using \verb|\entry| only 

\begin{timeline}{2014}{2017}{2cm}{2.5cm}{10cm}{5cm}
    \entry{2014}{Octobre.  Enregistrement}
    \entry{2014}{Novembre.  Transcription}
    \entry{2015}{Mars. Travail}
    \entry{2016}{Avril. Reprise}
    \entry{2017}{Septembre. Fin}
\end{timeline}

\bigskip

Using \verb|\plainentry| to blank the years for some timeline entries

\bigskip

\begin{timeline}{2014}{2017}{2cm}{2.5cm}{10cm}{5cm}
\entry{2014}{Octobre.  Enregistrement}
\entry{2014}{Novembre.  Transcription}
\plainentry{2015}{Mars. Travail}
\plainentry{2016}{Avril. Reprise}
\entry{2017}{Septembre. Fin}
\end{timeline}

%\caption{Chronologie}

%\end{table}

\end{document}
8
  • Thank you, I understand. So, how could I use only \entry?
    – domi
    Commented Oct 1, 2017 at 6:16
  • Replace everything in your code between \makeatletter and \makeatother with the timeline code I posted here. I also suggest don't load the chronosys package. You aren't using it.
    – Ross
    Commented Oct 1, 2017 at 6:22
  • I did it, but it does not work. Was the original code designed in order to set two timeline, the first with \entry, the second with \plainentry? If it was the case, shouldn't have I to remove \plainentry command from the code?
    – domi
    Commented Oct 1, 2017 at 6:41
  • Each timeline is an environment. It starts with \begin{timeline} and ends with \end{timeline}. You can have as many as is required in the document. The code between \makeatletter and \makeatother creates each timeline. Each timeline entry can either include or omit the year, depending on whether the entry was added with \entry or \plainentry, respectively. My guess is you have a timeline environment that is using \plainentry. Try searching for \plainentry, because that is what is producing entries with blank years.
    – Ross
    Commented Oct 1, 2017 at 7:22
  • 1
    @domi Only you have access to the code which produces the problem you report. You've posted code which (1) you say doesn't produce any problem at all and (2) which others find produces a problem, though not the one you report. Presumably, therefore, both the solution to the problem others find with the posted code and the problem you find with the non-posted code lie somewhere in the complement of the intersection of the subset of non-posted code which coincides with the posted code and the totality of the non-posted code or, else, with its interaction with that posted. Do you see the problem?
    – cfr
    Commented Nov 18, 2017 at 2:04

You must log in to answer this question.

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