Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Edit: In response to the comments, the question has been edited to include the MWE. The accepted answer (by Gonzalo) is still valid.

Here's my code:

\documentclass{article}


% *** MISC UTILITY PACKAGES ***
\usepackage{graphicx}
\usepackage[caption=false]{subfig}%The caption option has been disabled
%to avoid conflict with the IEEEtran class file.
\usepackage{tikz}

% *** MATH PACKAGES ***
\usepackage[cmex10]{amsmath}
\usepackage{amssymb}

\begin{document}
\begin{figure}[!t]
    \centering
\begin{tikzpicture} 
\node[anchor=south west, inner sep = 0] (image) at (0,0)
{\includegraphics[width=8cm]{Tulips.jpg}};
\begin {scope}[x={(image.south east)},y={(image.north west)}]
   \fill [white] (0,0) rectangle (1,1);
   \foreach \y in {0,1,...,8} { \node [anchor=east] at (0.09,0.07+0.88*\y/8) {\small {-5+5*\y}}; }
\end {scope}
\end{tikzpicture}
\caption{Nothing} 
\label{nothing}
\end{figure}
\end{document}

Here's the result:
enter image description here


I wanted the series to appear as {-5,0,5,...35}. What's being shown is {-5+5*0,-5+5*1,-5+5*2,...-5+5*8}.

How to evaluate the series before it gets printed as text?

share|improve this question
3  
Please, please, please: Post full minimal documents instead of just snippets. Finding answers is fun, completing documents is not. –  Jake Sep 27 '12 at 18:12
    
Really sorry about that. I will post MWE soon. –  Shashank Sawant Sep 27 '12 at 18:23
3  
@Jake: That's an excellent way to put it. –  Andrew Stacey Sep 27 '12 at 18:26
    
I guess you did not use standalone class for each diagram you want to draw. –  I am who I say I am Sep 27 '12 at 18:33
1  
@ShashankSawant: I have resorted to using \pgfmathsetmacro{\<name>}{<expression>} to compute expression and has found that quite useful. The evaluate= is clearly better for this case, but you should keep \pgfmathsetmacro in mind. –  Peter Grill Sep 27 '12 at 20:45
show 3 more comments

2 Answers

up vote 8 down vote accepted

You can use the evaluate=<variable> as <macro> using <formula> syntax:

\documentclass{scrartcl}
\usepackage{tikz,pgf}
\usepackage{graphicx}

\begin{document}

\begin{tikzpicture} 
\node[anchor=south west, inner sep = 0] (image) at (0,0)
{\includegraphics[width=8cm]{cat}};
\begin {scope}[x={(image.south east)},y={(image.north west)}]
  \draw [help lines,lime,xstep=.01,ystep=.01] (0,0) grid (1,1);
  \draw [help lines,orange,xstep=.05,ystep=.05] (0,0) grid (1,1);
  \draw [help lines,red,xstep=.1,ystep=.1] (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}; }

   \fill [white] (0,0) rectangle (1,1);
  \foreach \y [evaluate=\y as \yeval using -5+5*\y] in {0,...,8} { \node [anchor=east,font=\tiny] at (0.09,0.07+0.88*\y/8) {\pgfmathtruncatemacro{\yet}{\yeval}\yet}; }
\end {scope}
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
add comment

Answer to the modified question:

\documentclass{article}


% *** MISC UTILITY PACKAGES ***
\usepackage{graphicx}
\usepackage[caption=false]{subfig}%The caption option has been disabled
%to avoid conflict with the IEEEtran class file.
\usepackage{tikz}

% *** MATH PACKAGES ***
\usepackage[cmex10]{amsmath}
\usepackage{amssymb}

\begin{document}
\begin{figure}[!t]
    \centering
\begin{tikzpicture} 
\node[anchor=south west, inner sep = 0] (image) at (0,0)
{\includegraphics[width=8cm]{Tulips.jpg}};
\begin {scope}[x={(image.south east)},y={(image.north west)}]
   \fill [white] (0,0) rectangle (1,1);
%   \foreach \y in {0,1,...,8} { \node [anchor=east] at (0.09,0.07+0.88*\y/8) {\small {-5+5*\y}}; }
\foreach \y [evaluate=\y as \yeval using -5+5*\y] in {0,...,8} { \node [anchor=east,font=\small] at (0.09,0.07+0.88*\y/8) {\yeval}; }
\end {scope}
\end{tikzpicture}
\caption{Nothing} 
\label{nothing}
\end{figure}
\end{document}

The output looks like this: enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.