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.

I have learnt TikZ several months ago and I almost forgot because I seldom use it. I have a simple and easy object to draw as follows.

enter image description here

% incm.tex
\documentclass{minimal}
\usepackage[paperwidth=4cm,paperheight=3cm,margin=0bp]{geometry}

\usepackage{pstricks}
\psset{linewidth=0.01cm}
\pagecolor{cyan}
\begin{document}
\noindent%
\begin{pspicture}(\paperwidth,\paperheight)
\psframe(\paperwidth,\paperheight)
\pscircle*[linecolor=red](2,1.5){1.5}
\end{pspicture}
\end{document}

Note: the gray thick frame is not a part of object to draw, it is Adobe Acrobat background. :-)

Could you translate the above code in TikZ with exactly the same dimension?

I ask this because I am investigating another issue here. I want to check whether or not the issue is specific to PSTricks.


For those who cannot parse the PSTricks code above, the following is the description.

  1. I prepare a paper size of 4 cm wide and 3 cm tall.
  2. A canvas occupies the paper size without spaces.
  3. A black thin frame occupies the canvas, its rule equals to 0.01cm.
  4. A red disk is at the center of canvas. The top and bottom rules of the black thin frame become the tangent lines of the red disk.

Caution

In PSTricks, the outer part of a stroke is used to measure the dimension. It is not the case in TikZ because TikZ uses the middle.


Optional requirement, could you try the following compilation steps as well?

latex %1
dvips -R -t unknown %1
ps2pdf -dAutoRotatePages#/None -dCompatibilityLevel#1.5 -dPDFSETTINGS#/prepress %1.ps
pdftops -eps %1.pdf

I have tried Leo's solution but I got two pages with one overfull \hbox. One is blank and one contains cropped version of object shown above.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted
\documentclass{minimal}
\usepackage[paperwidth=4cm,paperheight=3cm,margin=0bp]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagecolor{cyan}
\parindent=0pt
\tikzset{every picture/.style={line width=0.2cm}}
\begin{document}
\begin{tikzpicture}[remember picture]
\coordinate (delta) at (.5\pgflinewidth,.5\pgflinewidth);
\draw ($(current page.south west) + (delta)$)
  rectangle ($(current page.north east) - (delta)$);
\fill[red] (current page.center) circle (.5\paperheight);
\end{tikzpicture}
\end{document}

enter image description here

I guess this result is what you want. I use a very thick line to show the border clearly. But the code needs caculation and is ugly for me.

share|improve this answer
    
I think it is \filldraw instead of \fill. Does \pscircle* draw and fill or only fill? I think it does both. –  Martin Scharrer Jul 11 '11 at 11:25
    
@Leo: Please see my last update above. Thanks. –  xport Jul 11 '11 at 11:33
    
@Leo: Have you considered that TikZ uses the middle part of its stroke? –  xport Jul 11 '11 at 11:38
1  
@Martin: The starred version will use the stroke color as the fill color when filling the region. –  xport Jul 11 '11 at 11:44
1  
@xport: I'm not sure which method should I use to avoid the picture to be put into the second page. There're many ways, but none satisfy me. (XeTeX will produce a one page pdf. It ignores the slight overfull.) –  Leo Liu Jul 11 '11 at 11:55
show 9 more comments

Assuming that you want to get pdf's in the end, I would suggest the external library of tikz (compile with pdflatex --shell-escape, it will put the pictures in separate files name `file-figure0.pdf etc).

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize % activat

\tikzset{every picture/.style={line width=0.01cm}}
\begin{document}
\noindent
\begin{tikzpicture}
\filldraw[fill=cyan] (0,0) rectangle (4cm,3cm);
\fill[red] (2,1.5) circle (1.5);
\end{tikzpicture}

\end{document}

or use the preview package (it will put everything in one file):

\documentclass{minimal}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\begin{document}

\begin{preview}
\begin{tikzpicture}
\filldraw[fill=cyan] (0,0) rectangle (4cm,3cm);
\fill[red] (2,1.5) circle (1.5);
\end{tikzpicture}
\end{preview}

\begin{preview}
\begin{tikzpicture}
\filldraw[fill=cyan] (0,0) rectangle (2cm,3cm);
\fill[red] (1,1.5) circle (0.5);
\end{tikzpicture}
\end{preview}
\end{document}
share|improve this answer
    
Thanks for your effort. Leo's answer has been accepted and it has shown that the cyan thin strip at the top cannot be avoided. –  xport Jul 11 '11 at 12:44
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.