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.

How can I draw rectangles of any size and any placement on the current page?

    \PassOptionsToPackage{dvipsnames}{xcolor} 
    \documentclass[landscape]{article}
    \usepackage{tikz,graphicx}
    \usepackage{pgf}
    \usepgflibrary{decorations.shapes}
    \usetikzlibrary{shapes.geometric, decorations.shapes,decorations.markings, shapes, fit, arrows, positioning, trees, mindmap, calc}
    \begin{document}
    \begin{tikzpicture}[remember picture, overlay]

    \draw [line width=1mm,opacity=.25] (current page.center) rectangle (3cm);

    \end{tikzpicture}
    \end{document}
share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

It's a bit hard to understand your question, so I have to make an informed guess. Here is an example in which multiple circles and boxes are drawn, relative to the actual size of the page, as you have it right now:

\PassOptionsToPackage{dvipsnames}{xcolor} 
\documentclass[landscape]{article}
\usepackage{tikz,graphicx}
\usepackage{pgf}
\usepgflibrary{decorations.shapes}
\usetikzlibrary{shapes.geometric, decorations.shapes,decorations.markings, shapes, fit, arrows, positioning, trees, mindmap, calc}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]

\draw [line width=1mm,opacity=.25] (current page.center) circle (3cm);

\draw [line width=1mm,opacity=.25] ($(current page.center)+(3,0)$) circle (3cm);

\draw [line width=1mm,opacity=.5] ($(current page.center)+(5,1)$) rectangle ($(current page.center)+(7,3)$);

\end{tikzpicture}
\end{document}

The example uses TikZ coordinate calculations to use positioning relative to the page center. Is this what you want? If not, please clarify. Since you are using "remember picture", don't forget to compile twice!

share|improve this answer
1  
I'm trying to draw random boxes all over the paper basically. Varying sizes and varying locations. I had circle in the code because rectangle in place of circle wouldn't run, and I didn't know what I had to change. –  AlanH Apr 7 '13 at 2:47
    
+1 for this answer. –  kan Apr 7 '13 at 3:05
add comment

With PSTricks.

Ellipses and Rectangles:

enter image description here

\documentclass{article}
\usepackage{pstricks}
\usepackage[a4paper,margin=3cm]{geometry}
\pagestyle{empty}
\SpecialCoor

\makeatletter
\psset
{
    xunit=\dimexpr\textwidth/10,
    yunit=\dimexpr\textheight/10,
    linewidth=2pt,
}
\begin{document}
\noindent
\begin{pspicture}[showgrid=top](10,10)
\psLoop{20}
{
    \psframe[linecolor=red](!rand 801 mod 100 div rand 801 mod 100 div)(!rand 801 mod 100 div 2 add rand 801 mod 100 div 2 add)
    \psellipse[linecolor=orange](!rand 601 mod 100 div 2 add rand 601 mod 100 div 2 add)(!rand 1001 mod 500 div rand 1001 mod 500 div)
}
\end{pspicture}
\end{document}

Circles and Rectangles:

enter image description here

% A4 paper size 21.0cm × 29.7cm
\documentclass[pstricks,border=2cm]{standalone}
\SpecialCoor
\makeatletter
\psset
{
    linewidth=2pt,
}
\begin{document}
\noindent
\begin{pspicture}[showgrid=top](17.0,25.7)
\psLoop{10}
{
    \psframe[linecolor=red](!rand 1501 mod 100 div rand 2371 mod 100 div)(!rand 1501 mod 100 div 2 add rand 2371 mod 100 div 2 add)
    \pscircle[linecolor=orange](!2 rand 1301 mod 100 div add 2 rand 2171 mod 100 div add){!rand 1001 mod 500 div}
}
\end{pspicture}
\end{document}

About rand

Let's consider rand 501 mod 100 div that produces a real number between 0.00 and 5.00 inclusive.

enter image description here

share|improve this answer
    
@Karlsstudents Oh, I thought it would be like one line. It's fine then. Thanks! –  AlanH Apr 7 '13 at 4:28
1  
+1 for the abracadabra-like parameters. –  Yiannis Lazarides Apr 7 '13 at 8:55
    
I forgot to remove \makeatletter. –  I am who I say I am Apr 7 '13 at 12:32
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.