I want to add a frame to a picture. i start to draw the picture by tikz. after drawing, it is the time adding frame. now, how can i know the following two points to add the frame, assuming that frame's width is equal to the page's width:
- how can i get the lower left corner's coordinate of the picture?
- how can i get how high the picture is?
if i have these two points, i can draw a rectangle for the frame. or is any other way to realize this purpose?
@Thorsten: just adding fbox
seemed not to be enough.
\documentclass[titlepage,a4paper]{article}
\usepackage{tikz}
\usepackage[lmargin=2.500000cm,rmargin=2.500000cm,tmargin=2.500000cm,bmargin=2.500000cm]{geometry}
\begin{document}
\section[General remarks]{General remarks}
\subsection[Geometry and coordinate system]{Geometry and coordinate system}
The main layout of the structure is adopted:\\
\fbox{
\begin{tikzpicture}[scale=1,thick]
\useasboundingbox (0,0) rectangle (70mm,5);
\begin{scope}[shift={(20mm,0)}]
\foreach \xoffset in {0,5.2}
{
\begin{scope}[shift={(\xoffset,0)}]
\draw[xstep=1,ystep=1] (0,0) grid (5,5);
\end{scope}
}
\end{scope}
\end{tikzpicture}
}
\end{document}
based on Martin
's comment, following code is added. as a newbie, it took me some time to find a way to add some spacing around picture. so this might save time for other newbies.
\documentclass[titlepage,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[lmargin=2.500000cm,rmargin=2.500000cm,tmargin=2.500000cm,bmargin=2.500000cm]{geometry}
\begin{document}
\section[General remarks]{General remarks}
\subsection[Geometry and coordinate system]{Geometry and coordinate system}
The main layout of the structure is adopted:\\
\begin{tikzpicture}[scale=1,thick]
\begin{scope}[shift={(20mm,0)}]
\foreach \xoffset in {0,5.2}
{
\begin{scope}[shift={(\xoffset,0)}]
\draw[xstep=1,ystep=1] (0,0) grid (5,5);
\end{scope}
}
\end{scope}
\coordinate (B) at (current bounding box.south west);
\draw[line width=10pt]
let
\p2 = ($(B) - (10mm,10mm)$)
in
(current bounding box.north east) ++(10mm,10mm) rectangle (\p2);
\end{tikzpicture}
\end{document}
another method uses backgrounds
. please refer to Andrew
's comment at the below.
Best Answer
There is also the
background library
(not sure which version of PDF/TikZ this arrived in, it's in PGF2.10). From the manual (section 25 in PGF2.10):It then gives various examples, from drawing a grid behind a picture to drawing a rectangle. In the simplest case, we can just supply the option
framed
to thetikzpicture
environment to get a simple rectangular frame. Using thebackground rectangle
style, we can make it a little more fancy (though as the manual says, no-one in their right mind would use this particular framing).Code:
Picture:
There are, of course, several options to change the background, in particular to change how far from the picture the frame is. See Section 25 of the manual (2.10 version) for details.