[Tex/LaTex] Margins in \framebox

boxesframedspacingtikz-pgf

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

enter image description here

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

Best Answer

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}