Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

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

3 Answers 3

up vote 7 down vote accepted

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}
share|improve this answer

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

share|improve this answer
    
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.

share|improve this answer
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. –  Yuriy Petrovskiy Sep 7 '11 at 11:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.