1

I am making a table where I want simple tikz line drawings in the cells. This is my first attempt to use tikz so I am likely to have made all sorts of mistakes. This is my attempt:

\documentclass[]{article}
\usepackage{tikz}

\begin{document} 
\begin{table}[]
    \centering
    \begin{tabular}{c|c|c}
        Apple & Apple & Apple\\
        \hline
        \begin{tikzpicture}
        \coordinate node[circle,fill,inner sep=1pt,label=] (A) at (0,0);
        \coordinate node[circle,fill,inner sep=1pt,label=] (B) at (1,1);
        \draw (A) -- (B);
        \end{tikzpicture}&    \begin{tikzpicture}
        \coordinate node[circle,fill,inner sep=1pt,label=] (A) at (1,0);
        \coordinate node[circle,fill,inner sep=1pt,label=] (B) at (0,1);
        \draw (A) -- (B);
        \end{tikzpicture}   &   \begin{tikzpicture}
        \coordinate node[circle,fill,inner sep=1pt,label=] (A) at (0,0);
        \coordinate node[circle,fill,inner sep=1pt,label=] (B) at (1,1);
        \coordinate node[circle,fill,inner sep=1pt,label=] (C) at (2,1);
        \draw (A) -- (B) -- (C);
        \end{tikzpicture}  
        \end{tabular}
    \caption{Caption}
\end{table}
\end{document}

It does in fact works however:

  • It gives me an error message "Package tikz Error: A node must have a (possibly empty) label text". How should I fix that?
  • It seems very wordy for such a simple task. Do I really need a separate tikzpicture environment for each cell for example?
  • 1
    Yes, because of \coordinate node..... – user121799 Mar 12 '19 at 17:17
5

If you use nodes, you need to give them some content, even a {} is allowed. But you do not really need to use nodes to fill some circles. And yes, you need to start a tikzpicture whenever you want to have one, or you could use the shorthand \tikz{...}.

\documentclass[]{article}
\usepackage{tikz}

\begin{document}


\begin{table}[]
    \centering
    \begin{tabular}{c|c|c}
        Apple & Apple & Apple\\
        \hline
        \tikz{\draw[fill] (0,0) circle[radius=1pt] -- (1,1) circle[radius=1pt];
        \path (0,1.2);}
        &    
        \tikz{\draw[fill] (1,0) circle[radius=1pt] -- (0,1) circle[radius=1pt];
        \path (0,1.2);}
        &   
        \tikz{\draw[fill] (0,0) circle[radius=1pt] -- (1,1) circle[radius=1pt]
        -- (2,1) circle[radius=1pt];\path (0,1.2);}
        \end{tabular}
    \caption{Caption}
\end{table}
\end{document}

enter image description here

| improve this answer | |
  • Thank you! However the vertical spacing between the top of the lines and the long horizontal line has disappeared. How can that be put back? – Anush Mar 12 '19 at 17:26
  • @Anush I am not sure there was a padding but it easy to add one. (There are zillions of possibilities.) – user121799 Mar 12 '19 at 17:34
  • Have you just created an invisible point at coordinate (0,1.2) using \path? – Anush Mar 12 '19 at 17:38
  • @Anush Yes. That is one possible way. – user121799 Mar 12 '19 at 17:39
  • Thank you. I am completely new to this so even one way is great to learn :) – Anush Mar 12 '19 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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