2

The line \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);, which is of course taken from Drawing on an image with TikZ, nowadays generates an error. I must admit I have not kept up with LaTeX, specifically TikZ, that much. Why does this not work?

Picture of wrong output

enter image description here

Error message

! Arithmetic overflow.
\pgf@pathgrid ...de \c@pgf@counta by\c@pgf@countb 
                                                  \relax \pgfutil@tempdima =...
l.42 ... lines,xstep=.1,ystep=.1] (0,0) grid (1,1)
                                                  ; %%% --- this is the firs...
I can't carry out that multiplication or division,
since the result is out of range.

MWE for extra-picture.pdf

\documentclass[
]{standalone}

\usepackage{
    tikz,
}

\usepackage{lmodern}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\begin{document}
\begin{tikzpicture}
\filldraw[fill=black!50] (0,0) rectangle (4,2);
\end{tikzpicture}
\end{document}

MWE

\documentclass[
fontsize=11pt,
DIV=12,
]{standalone}

\usepackage{
    tikz,
}

\usetikzlibrary{
    calc,
}

\usepackage{lmodern}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\begin{document}
\begin{tikzpicture}[
every node/.style={
    node font=\sffamily,
},
month/.style={
    rectangle,
    draw=black,
    very thick,
    fill=black!40,
},
normal/.style={
    draw,
    font=\small,
    rectangle,
},
]
\node [month, anchor=west] (AAA) at (0,0) {kkkkk};
\node [normal, anchor=west] (AAAstuff) at ($(AAA.east)+(1cm,0)$) {Text};

\node[anchor=west, inner sep=0] (ENVimage) at ($(AAAstuff.east)+(2cm,0)$) {\includegraphics[width=2cm]{extra-picture.pdf}};
\begin{scope}[x={(ENVimage.south east)},y={(ENVimage.north west)}]
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1); %%% --- this is the first line that yields the non-working MWE
%\draw[help lines,] (0,0) grid (1,1);
%\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
%\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
%\node[fill=white] at (0.5,0.5) {111111};
\end{scope}

\end{tikzpicture}
\end{document}
henry
  • 6,594

1 Answers1

2

I guess you want something like this.

\documentclass[
fontsize=11pt,
DIV=12,
]{standalone}

\usepackage{
    tikz,
}

\usetikzlibrary{
    calc,
}

\usepackage{lmodern}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\begin{document}
\begin{tikzpicture}[
every node/.style={
    node font=\sffamily,
},
month/.style={
    rectangle,
    draw=black,
    very thick,
    fill=black!40,
},
normal/.style={
    draw,
    font=\small,
    rectangle,
},
]
\node [month, anchor=west] (AAA) at (0,0) {kkkkk};
\node [normal, anchor=west] (AAAstuff) at ($(AAA.east)+(1cm,0)$) {Text};

\node[anchor=west, inner sep=0] (ENVimage) at ($(AAAstuff.east)+(2cm,0)$)
{\includegraphics[width=2cm]{example-image-duck.pdf}};
\begin{scope}[shift={(ENVimage.south west)},x={(ENVimage.south east)},y={(ENVimage.north west)}]
\draw[help lines,xstep=0.1,ystep=0.1] (0,0) grid (1,1); %%% --- this is the first line that yields the non-working MWE
%\draw[help lines,] (0,0) grid (1,1);
%\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
%\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
%\node[fill=white] at (0.5,0.5) {111111};
\end{scope}

\end{tikzpicture}
\end{document}

enter image description here

I think you used the code that puts a grid on top of an image at the origin, but your image is not at the origin, so I added shift={(ENVimage.south west)} and there is no issue.

  • 1
    And the genius I am, I made the background gray as well, so one could-should use \draw[red,help lines,xstep=0.1,ystep=0.1] (0,0) grid (1,1); to make the grid lines distinguishable. :) Thanks! – henry Jan 03 '19 at 00:05