1

I'd like to draw a MPM graph for a course. I used tikz, and defined the text of the nodes as a tabular. Everything is fine, except for one thing : the arcs don't touch the border of the tabular. I suppose it has to do with the fact that LaTeX adds some extra space around the tables, but I'm sure one of you is going to help me find how to delete this extra space :-)

This is the part of the code that illustrate my problem :

\documentclass{article}
\usepackage{tikz}
\begin{document}
  \begin{center}
    \begin{tikzpicture}
      \node (A) at (0,0) {
        \begin{tabular}{|c|c|}
          \hline
          \multicolumn{2}{|c|}{\textbf{A\ (2)}} \\
          \hline
          $0$ & $0$ \\
          \hline
          $0$ & $0$ \\
          \hline
        \end{tabular}};
      \node (B) at (3,2) {
        \begin{tabular}{|c|c|}
          \hline
          \multicolumn{2}{|c|}{\textbf{B\ (3)}} \\
          \hline
          $2$ & $3$ \\
          \hline
          $1$ & $0$ \\
          \hline
        \end{tabular}};
      \draw[->,>=latex,thick] (A) -- (B);
    \end{tikzpicture}
  \end{center}
\end{document}

Thanks for any help. Maybe I'm doing this all wrong...

4
  • 2
    Welcome to TeX.SX! To highlight code-blocks, either indent them by four spaces or use the {} symbol on the gui. Rather than posting snippets of code it is better to give a full minimal working example as it's much easier to help you if we have working code to start from. A MWE should compile and be as small as possible to demonstrate your problem. This said, you probably just need to use \node[inner sep=0pt]...
    – user30471
    Oct 27, 2018 at 2:09
  • You are right, my posting is incorrect... But you are also marvelous, because your tip just solved the problem. Now that I know where to search in the ocumentation, it will be much easier. Thanks again :-) Oct 27, 2018 at 2:13
  • Yes, problem is that even though the manual is very comprehensive it's big and hence hard to find things:)
    – user30471
    Oct 27, 2018 at 2:22
  • I edited my post so that it fits the minimal requirements in terms of quality. Thanks for your help guys. Much appreciated :) Oct 27, 2018 at 13:12

1 Answer 1

3

Here's a way of reducing code duplication using pics -- see section 18.2 of the tikz manual (version 3.0.1a).

\documentclass{article}
\usepackage{tikz}
\tikzset{
  pics/table/.style args={#1,#2,#3,#4,#5,#6}{
    code = {
      \node[inner sep=0pt] (#1) at (0,0) {
        \begin{tabular}{|c|c|}
          \hline
          \multicolumn{2}{|c|}{\textbf{#1 (#2)}} \\
          \hline
          $#3$ & $#4$ \\
          \hline
          $#5$ & $#6$ \\
          \hline
        \end{tabular}};
    }
  }
}
\begin{document}

  \begin{tikzpicture}
    \pic at (0,0) {table={A,2,0,0,0,0}};
    \pic at (3,2) {table={B,3,2,3,1,0}};
    \draw[->,>=latex,thick] (A.north east) -- (B.south west);
  \end{tikzpicture}

\end{document}

...and here is the output:

enter image description here

1
  • Djezus, that's Jedi level 4, and I'm just a padawan :-P Thanks a lot, I'll study this in my next incarnation... Oct 27, 2018 at 13:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .