Page LayoutSet Page Size to Figure Size

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
hkyz
Posts: 9
Joined: Wed Apr 25, 2012 9:37 am

Set Page Size to Figure Size

Post by hkyz »

I want to produce a document consisting of a single tikZ figure.

Code: Select all

\documentclass{article}
\usepackage{tikz}
\begin{document}
\pagestyle{empty}
\centering
\begin{tikzpicture}
\draw (0,0) arc (0:360:3cm);
\draw (0,0) arc (0:360:2cm);
\draw (-2,0) arc (0:360:2cm);
\draw (-1,-1) arc (0:360:2cm);
\draw (-1,+1) arc (0:360:2cm);
\end{tikzpicture}
\end{document}
I want the page to just fit the figure. (That is, the size of the page is set to the size of the figure.) I know I can use the geometry package to manually set the page size, but I am looking something automatic. Does anyone have an idea on how the page size can be automatically set to the size of the figure inside it?

Thanks.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Set Page Size to Figure Size

Post by localghost »

Just replace the »article« class by the standalone class. Refer to its manual to learn the details.


Thorsten
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Set Page Size to Figure Size

Post by Stefan Kottwitz »

Just to mention an alternative way: I sometimes use the preview package. For example, after \usepackage{tikz}:

Code: Select all

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
Stefan
LaTeX.org admin
Post Reply