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

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

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: 10335
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