2

When trying to use a newcommand with tikz I get multiple errors (all related to the same issue though) that show the message "Dimension too large". I don't understand why is that, the code seems fine to me. I'll post it and explain a couple of points:

\documentclass[]{article}
\usepackage[a4paper, margin=1cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{rotating}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{xparse,expl3}

\usetikzlibrary{fit, arrows,backgrounds,patterns,shapes,shapes.multipart,positioning,calc,decorations.markings}
\pgfplotsset{compat=1.7}
\pagestyle{empty}

\tikzset{
    opera/.style={rectangle, align=center, text width=4cm, fill=white},
    datum/.style={font=\scriptsize, rotate=-90},
}

\newcommand*{\evento}[4][]{
        \coordinate (A) at (0,{(#1-1600)/10});
        \coordinate (B) at ({#2},{#3});%
        \node[right=of B, datum] (C) {#1};
        \node[right= of C] (D) {#4};
}


\begin{document}

    \footnotesize

    \begin{tikzpicture}[x=1cm,y=-7mm]
            \centering
       %draw horizontal line   
       \draw[|->, -latex, draw] (0,0) -- (0,39);
       \draw[-, dashed] (0,-0.5) -- (0,0);
       \draw[|->, -latex, draw] (34,0) -- (34,39);
       \draw[-, dashed] (34,-0.5) -- (34,39);

       %draw years
    \foreach \y [evaluate=\y as \year using int(1600+\y*10)] in {0,1,...,38}{ 
        \draw (0,\y) node[left=2pt,anchor=east,xshift=0,font=\scriptsize] {$\year$}; 
        \draw (-0.1,\y) -- (0.1,\y);                
        }

    \foreach \y [evaluate=\y as \year using int(1600+\y*10)] in {0,1,...,37}{ 
        \draw (0,\y) node[left=2pt,anchor=east,xshift=0,font=\scriptsize] {}; 
        \draw (0,\y+.5) -- (0.1,\y+.5);     
        }

        % 1     
        \evento{1653}{5}{2}{The Protectorate began under the Lord Protector Oliver Cromwell};

        % 2     
        % \draw (0, 5.3) edge[out=0,in=180,-*] (5,2) node[datum] {1653} node[opera]{The Protectorate began under the Lord Protector Oliver Cromwell};

    \end{tikzpicture}
\end{document}

The actual code I was trying to make is marked with 1, the number 2 is the "manual" version that is however too long, tedious to fix for each event and I like minimal code. Shouldn't the code in the New command work and provide the right coordinates for the two points to be used?

If I wrote 1653, the code (0, {(#1-1600)/10})) should bring (0,5.3), which is exactly what I want.

1
  • I didn't have a good idea for the title, so if anyone knows how/wants to improve it, feel free to do so.
    – Alenanno
    Commented Oct 1, 2013 at 17:56

1 Answer 1

3

The \evento macro takes four arguments, with the first one being optional.

\newcommand*{\evento}[4][]{

The text The Protectorate … isn’t even an argument to \evento but doesn’t show up in the document as well as the spurious ; as TikZ installs a “nullfont” that prevents this. You instead get a few warning messages in the log:

Missing character: There is no T in font nullfont!
Missing character: There is no h in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no P in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no o in font nullfont!
Missing character: There is no t in font nullfont!
[…]
Missing character: There is no w in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no ; in font nullfont!

The argument #1 will be empty (the default is used). #2 will be 1653.

Simply remove the second optional argument of \newcommand:

\newcommand*{\evento}[4]{

You must log in to answer this question.

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