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.

Why does this code generates a rectangle, not a square?

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \draw[scale=rnd] (0,0) rectangle (1,1);
\end{tikzpicture}
\end{document}
share|improve this question

1 Answer 1

up vote 6 down vote accepted

Every coordinate of (1,1) is multiplied with the value of scale. So you have two values x and y which will be multiplied with rnd. And of course rnd isn't equal for x and y.

To use rnd as an option of scale you can do the following:

\documentclass[12pt]{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\pgfmathparse{rnd}
    \draw[scale=\pgfmathresult] (0,0) rectangle (1,1);
\end{tikzpicture}
\begin{tikzpicture}
    \draw[scale=1] (0,0) rectangle (1,1);
\end{tikzpicture}
\end{document}
share|improve this answer
    
Thanks! Is there a way to scale the square properly without using a variable? –  Jill-Jênn Vie Aug 5 '12 at 11:39
    
@Jill-JênnVie: You can use scale=2. Or what do you mean? –  Marco Daniel Aug 5 '12 at 11:56
    
I mean, the same random scale affecting both x and y. –  Jill-Jênn Vie Aug 5 '12 at 12:09
    
@Jill-JênnVie: You can use the option cm –  Marco Daniel Aug 5 '12 at 12:11
    
And how to factor the random number in \draw[cm={rnd,0,0,rnd,(0,0)}] (0,0) rectangle (1,1);? –  Jill-Jênn Vie Aug 5 '12 at 12:28

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.