# Margins in \framebox

I have the following code:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\framebox{\begin{tikzpicture}[color=black, line width=0.4mm]
\draw (0,0) rectangle (5mm,5mm);
\end{tikzpicture}}
\end{document}


Result is

The question is: How to remove margins around the box in tikzpicture environment?

-
On second thought, this seems to be a duplicate of TikZ add frame to a picture. – Martin Scharrer Sep 7 '11 at 11:01

You can also use the \frame macro instead which draws a tight frame around it. For special content inside nodes, e.g. verbatim, I recommend the \Frame macro from my recent realboxes package.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\frame{\begin{tikzpicture}[color=black, line width=0.4mm]
\draw (0,0) rectangle (5mm,5mm);
\end{tikzpicture}}%
\end{document}

-

Tikz provides you with the means to put a frame around your picture, even without a margin:

\documentclass[parskip]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{backgrounds}

\begin{document}

\begin{tikzpicture}[show background rectangle,inner frame sep=0mm]
\draw (0,0) ellipse (25mm and 15mm);
\end{tikzpicture}

\end{document}


Refer to the tikz manual, "25 Background Library" for further options

-
Thank you for answer. The problem was with using framebox. Nevertheless it is also useful to me as I had not known about such options of tikzpicture. – Yuriy Petrovskiy Sep 7 '11 at 11:15

The margins you are seeing are produced by two different reasons. First of all I guess that your input code was

\framebox{
\begin{tikzpicture}[color=black, line width=0.4mm]
\draw (0,0) rectangle (5mm,5mm);
\end{tikzpicture}
}


that has two spurious spaces. Indeed, if the code is as shown in your message, the outer rectangle becomes a square. There's the parameter \fboxsep that stores the separation from the frame to the contents in a \framebox, its default value is 3pt. To get no separation you can write

\begingroup\setlength{\fboxsep}{0pt}%
\fbox{\begin{tikzpicture}
<TikZ commands>;
\end{tikxpicture}}\endgroup


so that the change to \fboxsep will hold only inside the group.

-
Now I understand the problem - I used wrong tools and got the wrong result. This solution works good, but solution with \frame{} is more elegant. Thank you for explanation. – Yuriy Petrovskiy Sep 7 '11 at 11:08