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.

John
  • 528
  • 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 Dec 27 '19 at 15:41
  • It is a modified \documentclass{article}. – John Dec 27 '19 at 16:51
  • You can surely add an example that is just of the critical size without using 300 nodes, can't you? –  Dec 27 '19 at 18:40
  • You are right, now added. – John Dec 27 '19 at 19:28
  • I find that @Arnaud's suggestion works: `\scalebox{2}{\begin{tikzpicture}[x=5mm,y=5mm] \node[draw] at (0, 0) {tikz rectangle};

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

    \end{tikzpicture}}`

    –  Dec 27 '19 at 19:37
  • It does indeed work, however in my case I would need to shrink all fonts and shape sizes too. If there is no "proper" way to do it, I will use it. – John Dec 27 '19 at 19:53
  • You can use `\scalebox{2}{\begin{tikzpicture}[x=5mm,y=5mm,nodes={scale=1/2,transform shape}] \node[draw] at (0, 0) {tikz rectangle};

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

    \end{tikzpicture}}` to shrink the nodes automatically. If you mean by "proper way" to circumvent the TeX limits on the maximal dimension once and for all, I think this would require to rewrite TeX.

    –  Dec 27 '19 at 20:00
  • Ah, and you may want to use something like this to transform the line widths, too. –  Dec 27 '19 at 20:02
  • So is this limit to the figure size of tikz set in stone then? How was it chosen? – John Dec 27 '19 at 21:21
  • @Grants The limits of TikZ are the same as those of TeX... – Paul Gaborit Dec 28 '19 at 08:13
  • 2
    @Grants Max length: 16383.99998pt (5.75832m) ! You second node is at (600cm,0cm) = (6m, 0m) ! – Paul Gaborit Dec 28 '19 at 08:19

2 Answers2

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

ZhiyuanLck
  • 4,516
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