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'm just starting out with Tikz, and find it amazing - but a bit overwhelming too. So here is an absolute beginners question:

I copied this form somebody:

% Draw inside tables:
% Some options common to all the nodes and paths
\tikzstyle{every picture}+=[remember picture,baseline]
\tikzstyle{every node}+=[inner sep=0pt,anchor=base,
minimum width=1.8cm,align=center,text depth=.25ex,outer sep=1.5pt]
\tikzstyle{every path}+=[thick, rounded corners]
 here

It was meant for drawing circles around tables or columns in a LaTeX table like this (there is a counter defined, so I can use numbers in referencing the tabnodes):

\begin{table}[htbp]
\begin{tabular}{ ...
\tabnode{$null?(s)$} & \tabnode{true} & \tabnode{false} ...
\end{tabular}
\begin{tikzpicture}[overlay]
% Define the circle paths
\draw [black](3.north west) -- (5.north east) -- 
(5.south east) -- (3.south west)  -- cycle;
...
\end{tikzpicture}
\end{table}

This worked just fine, until I started to add other, independent, Tikz graphics to the document. Then, of course, the "options common to all the nodes and paths" caused problems, since they should not apply to the new independent graphs too.

So my question is: how do I, after changing the "every picture", "every node","every path" definitions to, say, "overlay_picture", "overlay_node" and "overlay_path", apply these new definitions to the table definition?

EDIT:

(1) tabular overlay works, independent graphics not:

\documentclass[german, a4paper, table]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,shadows,arrows}
\usepackage{tkz-graph}
\usepackage{tabularx}


%% (1) Draw inside tables :
%% Some options common to all the nodes and paths
\tikzstyle{every picture}+=[remember picture,baseline]
\tikzstyle{every node}+=[inner sep=0pt,anchor=base,
minimum width=1.8cm,align=center,text depth=.25ex,outer sep=1.5pt]
\tikzstyle{every path}+=[thick, rounded corners]

%% (2) Draw inside tables :
% \tikzset{mytablestyle/.style={% Now everything inside these braces are local to mytablestyle
%          every picture/.style={remember picture,baseline},
%          every node/.append style={
%                          inner sep=0pt,anchor=base,
%                          minimum width=1.8cm,align=center,
%                          text depth=.25ex,outer sep=1.5pt},
%                          every path/.append style={thick, rounded corners}
%         }
% }


% tikz definitions for other, independent pictures
\tikzstyle{abstract}=[rectangle, draw=black, rounded corners,
fill=blue!40, drop shadow, text centered, anchor=north, text=white,
text width=3cm]

\tikzstyle{comment}=[rectangle, draw=black, rounded corners,
fill=green, drop shadow, text centered, anchor=north, text=white, text
width=3cm]

\tikzstyle{myarrow}=[->, >=open triangle 90, shorten >=3mm, thick]

\tikzstyle{line}=[-, thick]


\begin{document} 

%%% table with overlay
% Introduce a new counter for counting the nodes needed for circling
\newcounter{nodecount}
% Command for making a new node and naming it according to the nodecount counter
\newcommand\tabnode[1]{\addtocounter{nodecount}{1} \tikz \node (\arabic{nodecount}) {#1};}

% table
\begin{table}[htbp]
  \centering
\begin{tabular}{ l@{\hspace{8mm}} !{\vrule width 1.5pt}
    @{\hspace{10mm}} c@{\hspace{10mm}} c@{\hspace{10mm}}}
  & \multicolumn{2}{l}{\large{constructor of s}} \\
  \large{observations} & \tabnode{$nil$} & \tabnode{$adjoin(s', n)$}\\ 
    \noalign{\hrule height 1.5pt}
\tabnode{$null?(s)$} & \tabnode{true} & \tabnode{false} \\
\tabnode{$head(s)$} & \tabnode{\textbf{error}} & \tabnode{n\vphantom{h}}\\ 
\tabnode{$tail(s)$} & \tabnode{\textbf{error}} & \tabnode{s'} \\ 
\end{tabular}
\begin{tikzpicture}[overlay]
% Define the circle paths
\draw [black](3.north west) -- (5.north east) -- 
(5.south east) -- (3.south west)  -- cycle;
\draw [black](6.north west) -- (8.north east) -- 
(8.south east) -- (6.south west)  -- cycle;
\draw [black](9.north west) -- (11.north east) -- 
(11.south east) -- (9.south west)  -- cycle;
\end{tikzpicture}
\end{table}


% independent tikz graphic
\begin{figure}[htp]
 \centering
\begin{tikzpicture}[node distance=2cm]
    \node (Fahrzeug) [abstract, rectangle split, rectangle split parts=2]
        {
            \textbf{Fahrzeug}
            \nodepart{second}fortbewegen()
        };
    \node (Landfahrzeug) [abstract, rectangle split, rectangle split
    parts=2, below left=of Fahrzeug]
        {
            \textbf{Landfahrzeug}
            \nodepart{second}override \\ fortbewegen()
        };
    \node (Wasserfahrzeug) [abstract, rectangle split, rectangle split
    parts=2, below right=of Fahrzeug]
        {
            \textbf{Wasserfahrzeug}
            \nodepart{second}override \\ fortbewegen()
        };

   \node (Amphibienfahrzeug) [abstract, rectangle split, rectangle
   split parts=2, below right=of Landfahrzeug]
        {
          \textbf{Amphibien-}\\
          \textbf{fahrzeug}
            \nodepart{second}\phantom{()}
        };

    \draw[myarrow] (Landfahrzeug.north) --  (Fahrzeug.south);
    \draw[myarrow] (Wasserfahrzeug.north) --  (Fahrzeug.south);
    \draw[myarrow] (Amphibienfahrzeug.north) --  (Landfahrzeug.south);
    \draw[myarrow] (Amphibienfahrzeug.north) --  (Wasserfahrzeug.south);
\end{tikzpicture}
\end{figure}
\end{document} 

Output:

Table overlays work

(2) Independent graphics work, but table overlays not:

\documentclass[german, a4paper, table]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,shadows,arrows}
\usepackage{tkz-graph}
\usepackage{tabularx}


%% (1) Draw inside tables :
%% Some options common to all the nodes and paths
% \tikzstyle{every picture}+=[remember picture,baseline]
% \tikzstyle{every node}+=[inner sep=0pt,anchor=base,
% minimum width=1.8cm,align=center,text depth=.25ex,outer sep=1.5pt]
% \tikzstyle{every path}+=[thick, rounded corners]

% (2) Draw inside tables :
\tikzset{mytablestyle/.style={% Now everything inside these braces are local to mytablestyle
         every picture/.style={remember picture,baseline},
         every node/.append style={
                         inner sep=0pt,anchor=base,
                         minimum width=1.8cm,align=center,
                         text depth=.25ex,outer sep=1.5pt},
                         every path/.append style={thick, rounded corners}
        }
}


% tikz definitions for other, independent pictures
\tikzstyle{abstract}=[rectangle, draw=black, rounded corners,
fill=blue!40, drop shadow, text centered, anchor=north, text=white,
text width=3cm]

\tikzstyle{comment}=[rectangle, draw=black, rounded corners,
fill=green, drop shadow, text centered, anchor=north, text=white, text
width=3cm]

\tikzstyle{myarrow}=[->, >=open triangle 90, shorten >=3mm, thick]

\tikzstyle{line}=[-, thick]


\begin{document} 

%%% table with overlay
% Introduce a new counter for counting the nodes needed for circling
\newcounter{nodecount}
% Command for making a new node and naming it according to the nodecount counter
\newcommand\tabnode[1]{\addtocounter{nodecount}{1} \tikz \node (\arabic{nodecount}) {#1};}

% table
\begin{table}[htbp]
  \centering
\begin{tabular}{ l@{\hspace{8mm}} !{\vrule width 1.5pt}
    @{\hspace{10mm}} c@{\hspace{10mm}} c@{\hspace{10mm}}}
  & \multicolumn{2}{l}{\large{constructor of s}} \\
  \large{observations} & \tabnode{$nil$} & \tabnode{$adjoin(s', n)$}\\ 
    \noalign{\hrule height 1.5pt}
\tabnode{$null?(s)$} & \tabnode{true} & \tabnode{false} \\
\tabnode{$head(s)$} & \tabnode{\textbf{error}} & \tabnode{n\vphantom{h}}\\ 
\tabnode{$tail(s)$} & \tabnode{\textbf{error}} & \tabnode{s'} \\ 
\end{tabular}
\begin{tikzpicture}[overlay]
% Define the circle paths
\draw [black](3.north west) -- (5.north east) -- 
(5.south east) -- (3.south west)  -- cycle;
\draw [black](6.north west) -- (8.north east) -- 
(8.south east) -- (6.south west)  -- cycle;
\draw [black](9.north west) -- (11.north east) -- 
(11.south east) -- (9.south west)  -- cycle;
\end{tikzpicture}
\end{table}


% independent tikz graphic
\begin{figure}[htp]
 \centering
\begin{tikzpicture}[node distance=2cm]
    \node (Fahrzeug) [abstract, rectangle split, rectangle split parts=2]
        {
            \textbf{Fahrzeug}
            \nodepart{second}fortbewegen()
        };
    \node (Landfahrzeug) [abstract, rectangle split, rectangle split
    parts=2, below left=of Fahrzeug]
        {
            \textbf{Landfahrzeug}
            \nodepart{second}override \\ fortbewegen()
        };
    \node (Wasserfahrzeug) [abstract, rectangle split, rectangle split
    parts=2, below right=of Fahrzeug]
        {
            \textbf{Wasserfahrzeug}
            \nodepart{second}override \\ fortbewegen()
        };

   \node (Amphibienfahrzeug) [abstract, rectangle split, rectangle
   split parts=2, below right=of Landfahrzeug]
        {
          \textbf{Amphibien-}\\
          \textbf{fahrzeug}
            \nodepart{second}\phantom{()}
        };

    \draw[myarrow] (Landfahrzeug.north) --  (Fahrzeug.south);
    \draw[myarrow] (Wasserfahrzeug.north) --  (Fahrzeug.south);
    \draw[myarrow] (Amphibienfahrzeug.north) --  (Landfahrzeug.south);
    \draw[myarrow] (Amphibienfahrzeug.north) --  (Wasserfahrzeug.south);
\end{tikzpicture}
\end{figure}
\end{document} 

Here is the output again, after compiling two times (sorry for the overly big output graphics):

Independent graphics work, overlay not

share|improve this question
    
You can try to put the tabular inside a node. –  Harish Kumar Dec 9 '12 at 1:30
    
Sorry, I don't understand. I want to apply the tikzstyle "overlay_picture" only to certain pictures, the tikzstyle "overlay_node" only to the nodes in these pictures, and the tikzstyle "overlay_path" only to path in these pictures. How do I write this in the table definition? –  user17106 Dec 9 '12 at 1:36

1 Answer 1

up vote 4 down vote accepted

You probably have those declarations in the preamble which is anywhere before \begin{document} command. So those settings are being applied to every TikZ picture. What you can do is to create a custom style for those table and related parts that was working until now.

An example is

\tikzset{mytablestyle/.style={% Now everything inside these braces are local to mytablestyle
         every picture/.style={remember picture,baseline},
         every node/.append style={
                         inner sep=0pt,anchor=base,
                         minimum width=1.8cm,align=center,
                         text depth=.25ex,outer sep=1.5pt
                         },
                         every path/.append style={thick, rounded corners}
        }
}

Then you can include this style in your table related pictures and the rest won't be affected.

You probably have a \tikz command or a \begin{tikzpicture} in the definition of tabnode commands too. Add this style via \tikz[mytablestyle] or

\begin{tikzpicture}[mytablestyle]
....
\begin{tikzpicture}

and they will keep on working but the general style of the pictures won't feel it. To see whay I've used \tikzset and why your example has \tikzstyle, see Should \tikzset or \tikzstyle be used to define TikZ styles?

share|improve this answer
    
Thanks for the answer, I just tried it, copying the \tkset into the preamble, and using \begin{tikzpicture}[mytablestyle,overlay] in the tables, but then the overlay doesn't work anymore, the circles are drawn at the side of the table, not around rows or columns as intended. –  user17106 Dec 9 '12 at 1:59
    
@user17106 Then we need to work on a MWE. Can you make up an example starting from \documentclass{article} to \end{document} and involves one of these tables and style definitions? –  percusse Dec 9 '12 at 2:06
    
OK, it took me a while, but I edited my question and included MWE's and output that should illustrate the problem. –  user17106 Dec 9 '12 at 2:38
    
thanks again, but this does not work here, it still looks like in the second output above, although I tried and compiled several times. –  user17106 Dec 9 '12 at 3:27
    
@user17106 As I've said in the question you have to add mytablestyle to the tikz command in \newcommand\tabnode and also to the tikzpicture after the tabular otherwise the options are not passed to those. –  percusse Dec 9 '12 at 3:30

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.