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 try to use the TikZ's Fitting Library with coordinates but it didn't compile.

In the manual of TikZ we got

This option must be given to a node path command. The coordinates or nodes should be a sequence of Tik Z coordinates or node names, one directly after the other without commas (like with the plot coordinates path operation). Examples as (1,0) (2,2) or (a) (1,0) (b), where a and b are nodes.

So I try

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}
    \node (foo) at (0,0) {foo};
    \node (bar) at (2,0) {bar};
    \node[draw, fit=(0,0) (2,0)] {};
\end{tikzpicture}
\end{document}

and got the following error:

! Undefined control sequence.
\pgfmathsetlength ...\pgfmath@onquick #2\pgfmath@ 
                                              {\begingroup \pgfmath@sele...
l.9         \node[draw, fit=(0,0) (2,0)]
                                     {};

If I use node labels instead of coordinates, as below, I got no error.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}
    \node (foo) at (0,0) {foo};
    \node (bar) at (2,0) {bar};
    \node[draw, fit=(foo) (bar)] {};
\end{tikzpicture}
\end{document}

I'm using

$ pdflatex --version
pdfTeX 3.1415926-2.4-1.40.13 (TeX Live 2012)
kpathsea version 6.1.0
...

with

$ tlmgr info pgf 
package:     pgf
...
installed:   Yes
revision:    22614
cat-version: 2.10
cat-date:    2010-10-27 12:56:09 +0200
cat-license: lppl1.3
collection:  collection-pictures
...
share|improve this question
1  
Welcome to TeX.SE. –  Peter Grill Nov 22 '12 at 23:08
2  
Put the coordinates in braces to hide the comma: fit={(1,2) (2,3)}. –  Andrew Stacey Nov 22 '12 at 23:08
add comment

1 Answer

up vote 3 down vote accepted

Use braces around co-ordinates - fit={(0,0) (2,0)}:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}
    \node  (foo) at (0,0) {foo};
    \node (bar) at (2,0) {bar};
    \node[draw, fit={(0,0) (2,0)}] {};
\end{tikzpicture}
\end{document}

enter image description here

The picture is ugly as the nodes will stretch beyond the co-ordinates to accommodate text.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}
    \node [draw=red,inner sep=0pt] (foo) at (0,0) {foo};
    \node [draw=red,inner sep=0pt] (bar) at (2,0) {bar};
    \node[draw=blue, fit={(0,0) (2,0)}] {};
\end{tikzpicture}
\end{document}

enter image description here

The better way is to use labels:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}
    \node [draw=red] (foo) at (0,0) {foo};
    \node [draw=red] (bar) at (2,0) {bar};
    \node[draw=blue, fit=(foo) (bar)] {};
\end{tikzpicture}
\end{document}

enter image description here

Here, the entire nodes are enclosed unlike the co-ordinates.

share|improve this answer
add comment

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.