3

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?

1

3 Answers 3

9

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}
8

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}

enter image description here

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

1
  • 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. Sep 7, 2011 at 11:15
5

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.

1
  • 1
    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. Sep 7, 2011 at 11:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .