5

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}

2 Answers 2

6

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!

1
  • 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. Apr 7, 2013 at 2:47
6

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

2
  • @Karlsstudents Oh, I thought it would be like one line. It's fine then. Thanks! Apr 7, 2013 at 4:28
  • I forgot to remove \makeatletter. Apr 7, 2013 at 12:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .