tags:

views:

110

answers:

1

I can draw a hyperlinked shape in tikz using the following code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{hyperref}

\begin{document}
\begin{tikzpicture}
\node {%
\href{http://www.stackoverflow.com}{% 
\begin{tikzpicture} 
\filldraw[blue] circle(1cm) node [white] {Click}; 
\end{tikzpicture}}}; 
\end{tikzpicture}

\end{document}

Now I would like to organize my shapes using the matrix, and have one of the shapes hyperlinked. It almost works, but I am not able to align the hyperlinked shape with the rest of the shapes, and it is bigger than the other shapes:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{hyperref}

\begin{tikzpicture}
\matrix [matrix of nodes, row sep = 1cm, column  sep=1cm, nodes={circle, draw}]  
{%    First  row:
1           & 2 \\
%    second row:
\path node {\href{http://www.stackoverflow.com}{% 
\begin{tikzpicture} 
\node {3}; 
\end{tikzpicture}}}; & 4\\
};

\end{tikzpicture}
\end{document}

I get the following result:

alt text

My question is: How could I align shape 3 in the picture above with the other shapes, and get rid of the outer circle?

+1  A: 

I think you're aiming too high and your second {tikzpicture} is messing up your layout. What do you think about the code below? Is that what you've been looking for?

\documentclass{article}
\usepackage{tikz}
  \usetikzlibrary{matrix}
\usepackage[pdftex,active,tightpage]{preview}
  \PreviewEnvironment{tikzpicture}
\usepackage{hyperref}
\begin{document}
\begin{tikzpicture}
  \matrix [matrix of nodes, row sep = 1cm, column  sep=1cm, nodes={circle, draw}]  
    {%
    1 & 2\\%
    \href{http://stackoverflow.com}{3} & 4\\%
    };
\end{tikzpicture}
\end{document}

BTW: the \PreviewEnvironment{tikzpicture} is not really needed, but it makes for a nice, cropped pdf...

Habi
Thanks. I knew about the option of hyperlinking the node text, but was still hoping that it would be hyperlink shapes as well (even if pdf-hyperlinks are all rectangular).
learnr
Oh, I loved this! I didn't know you could crop the figure, and I was always using scale= to try and fit the picture to the page. Thank you heaps :)
Vivi
you're welcome!
Habi