3

I have a large diagram which I have implemented in TikZ, currently the size is 16042 × 457. If I try to add more nodes and extend the diagram horizontally, I get the Dimension too large! error and cannot compile the document. Is there a way to go around this and make the diagram larger?

I am aware that I am not providing a MWE but it is tricky as the diagram has about 300 nodes, and without them I cannot replicate the error.

Edit: here is a sample of code which gives this error:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\usetikzlibrary{calc}
\usepackage[paperwidth=\maxdimen,paperheight=\maxdimen]{geometry}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}

\begin{tikzpicture}
\node[draw] at (0, 0) {tikz rectangle};

\node[draw] at (600, 0) {tikz circle};
\end{tikzpicture}

\end{document}

Change 600 to 500 or less, and the error disappears.

11
  • 2
    Maybe you can divide all dimensions by 10 and put the whole tikzpicture within a \scalebox{10}{...} ? Not sure it will work though. Also, I'm curious which class of document you are working on that fits such a big picture.
    – Arnaud
    Commented Dec 27, 2019 at 15:41
  • It is a modified \documentclass{article}.
    – John
    Commented Dec 27, 2019 at 16:51
  • You can surely add an example that is just of the critical size without using 300 nodes, can't you?
    – user194703
    Commented Dec 27, 2019 at 18:40
  • You are right, now added.
    – John
    Commented Dec 27, 2019 at 19:28
  • 2
    @Grants Max length: 16383.99998pt (5.75832m) ! You second node is at (600cm,0cm) = (6m, 0m) ! Commented Dec 28, 2019 at 8:19

2 Answers 2

3

\maxdimen is the largest legal <dimen> that supported by TeX-dimensions (±16383.99999pt).

According to pgfmanual 56.1 Fixed Point Arithmetic Library Overview

In addition the range of values that can be computed is very small: ±16383.99999. Conversely, the fp package has a reasonably high accuracy, and can perform computations over a wide range of values (approximately ±9.999 × 1017),

while for dimensions:

The pgf mathematical engine will still be used to evaluate lengths, such as 10pt or 3em, so it is not possible for an length to exceed the range of values supported by TEX-dimensions (±16383.99999pt), even though the resulting expression is within the range of fp. So, for example, one can calculate 3cm*10000, but not 3*10000cm.

TikZ library fpu is like fp but have higher accuracy and is faster and more efficient. So we can do some test with fpu.

\documentclass{article}
\usepackage{pgf}
\usepgflibrary{fpu}

\begin{document}

\pgfset{fpu, fpu/output format=fixed}
\pgfmathparse{1cm * 600}
\begin{tabular}{rcl}
  \verb|\maxdimen| & is & \the\maxdimen.\\
  600cm & is & \pgfmathresult pt.
\end{tabular}
% \pgfmathparse{600cm} % error!

\end{document}

enter image description here

1
  • So there is no way to make something larger than 16383.99999pt by 16383.99999pt?
    – John
    Commented Sep 24, 2020 at 10:52
0

You don't need to shrink your fonts or dimensions, TikZ doesn't use floating point numbers, so, when you don't set units it can overflow.

By setting a x and y dimensional value to the units, it will allow to work just fine without shrinking your fonts.


\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\usetikzlibrary{calc}
\usepackage[paperwidth=\maxdimen,paperheight=\maxdimen]{geometry}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}

\begin{tikzpicture}[x=0.2cm, y=0.2cm]
\node[draw] at (0, 0) {tikz rectangle};

\node[draw] at (600, 0) {tikz circle};
\end{tikzpicture}

\end{document}

right side left side

4
  • Keep in mind that you are just moving the goalpost. TikZ has this fundamental limit of how large a number it can handle. Commented Dec 28, 2019 at 0:44
  • But this changes the sizes of my nodes, too?
    – John
    Commented Dec 28, 2019 at 14:23
  • It defines a width and height for x and y. So, when you say (3,2) it means (0.6cm. 0.4cm) if x=0.2 y=0.2. Commented Jan 1, 2020 at 3:24
  • Like @Paul Gaborit said on his comment, there is a hard limit on the maximum height and width... tex.stackexchange.com/a/151903/120176 Commented Jan 1, 2020 at 3:26

You must log in to answer this question.

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