3

I'm new to tikz and I managed to create the following picture which looks fine if the code is inserted directly into the document.

enter image description here

I've been using a lot of tikz figures and so I decided to create standalone figures to include within the document. However, this particular figure has the bottom, left and right borders of the last row cut off somehow. And I'm not entirely sure why. What seems strange though is some of the boxes seem to have overlapping borders or they are not properly aligned somehow, I've just noticed this; not sure if it is related.

enter image description here

Here is an MWE of the main latex file and standalone tikz.

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{standalone}
\usetikzlibrary{trees, matrix}
\usetikzlibrary{arrows.meta}

\tikzset{
    every matrix/.style={
        inner sep=-\pgflinewidth,
        matrix of math nodes,
        column sep=-\pgflinewidth,
        nodes={
            draw=black,
            font=\color{black},
            minimum size=.75cm,
            anchor=center
        }
    }
}

\begin{document}

\begin{figure}
  \includestandalone{trie_visual}
\end{figure}

\end{document}

And the standalone:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{trees, matrix, arrows.meta}

\tikzset{
    every matrix/.style={
        matrix of math nodes,
        nodes={
            draw=black,
            font=\color{black},
            minimum size=.75cm,
            anchor=center
        }
    }
}

\begin{document}
\begin{tikzpicture}
\tikzstyle{root} = [circle,draw=black, thick]

\node[root] (r0) at (0,2){root};
\matrix (l0) at (0,0) {a & ... & z\\};

\matrix (l10) at (-2,-2) {a & ... & z\\};
\matrix (l11) at (1,-2) {a & ... & z\\};
\matrix (l12) at (4,-2) {a & ... & z\\};

\matrix (l20) at (-3,-4) {a & ... & z\\};
\matrix (l21) at (0,-4) {a & ... & z\\};
\matrix (l22) at (3,-4) {a & ... & z\\};
\matrix (l23) at (6,-4) {a & ... & z\\};

  \path[-{Latex[length=3mm]}]
    (r0.south) edge (l0-1-2.north)
    (l0-1-1.south) edge (l10-1-2.north)
    (l0-1-2.south) edge (l11-1-2.north)
    (l0-1-3.south) edge (l12-1-2.north)

    (l10-1-2.south) edge (l20-1-2.north)
    (l10-1-3.south) edge (l21-1-2.north)
    (l11-1-2.south) edge (l22-1-2.north)
    (l12-1-2.south) edge (l23-1-2.north);
\end{tikzpicture}
\end{document}
4
  • What about trying \documentclass[margin=2mm]{standalone}? – Sigur Dec 14 '20 at 14:09
  • I had the same idea, @Sigur, but it didn't make a difference with \includestandalone in the main document. – AlexG Dec 14 '20 at 14:20
  • 2
    What is wrong with \includegraphics? – Sigur Dec 14 '20 at 16:44
  • 2
    @Sigur, nothing apparently!! That worked! From what I read I thought I had to exclusively use \includestandalone. Thanks! If you post this as the answer I'll gladly accept. – John Dec 14 '20 at 16:55
2

I can't reproduce your problem. Using recent MikTeX (upgraded few days ago) i got the following result:

enter image description here

For above image I a weebit improve style for matrix, but it is not a soure your problem):

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, matrix, trees}

\tikzset{
    every matrix/.style = {matrix of math nodes,
                           nodes={draw,
                                  minimum size=.75cm,
                                  anchor=center},
                           column sep=-\pgflinewidth
                          },
            root/.style = {circle,draw, thick}
        }
\usepackage{standalone}
\usepackage{lipsum}

\begin{document}
\lipsum[1]
\begin{figure}[ht]
    \centering
    \includestandalone{sub}
\end{figure}
\lipsum[2]
\end{document}

and standalone picture is:

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, matrix, trees}

\tikzset{
    every matrix/.style = {matrix of math nodes,
                           nodes={draw,
                                  minimum size=.75cm,
                                  anchor=center},
                           column sep=-\pgflinewidth % <---
                          },
            root/.style = {circle,draw, thick}
        }

\begin{document}
\begin{tikzpicture}
\node[root] (r0) at (0,2){root};
\matrix (l0) at (0,0) {a & ... & z\\};

\matrix (l10) at (-2,-2) {a & ... & z\\};
\matrix (l11) at (1,-2) {a & ... & z\\};
\matrix (l12) at (4,-2) {a & ... & z\\};

\matrix (l20) at (-3,-4) {a & ... & z\\};
\matrix (l21) at (0,-4) {a & ... & z\\};
\matrix (l22) at (3,-4) {a & ... & z\\};
\matrix (l23) at (6,-4) {a & ... & z\\};

  \path[-{Latex[length=3mm]}]
    (r0.south) edge (l0-1-2.north)
    (l0-1-1.south) edge (l10-1-2.north)
    (l0-1-2.south) edge (l11-1-2.north)
    (l0-1-3.south) edge (l12-1-2.north)

    (l10-1-2.south) edge (l20-1-2.north)
    (l10-1-3.south) edge (l21-1-2.north)
    (l11-1-2.south) edge (l22-1-2.north)
    (l12-1-2.south) edge (l23-1-2.north);
\end{tikzpicture}
\end{document}

Off-topic: since your image actually presen a tree, I would consider to use forest package:

Addendum: Solution with use of the `forest package:

  • main file:
\documentclass[12pt]{article}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\newcommand\mpnc[2]{\nodepart{one}      $#1$
                    \nodepart{two}      $\dots$
                    \nodepart{three}    $#2$
                    }
\usepackage{standalone}
\usepackage{lipsum}

\begin{document}
\lipsum[1]
\begin{figure}[ht]
    \centering
    \includestandalone{sub}
\end{figure}
\lipsum[2]
\end{document}

sub file

\documentclass{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\newcommand\mpnc[2]{\nodepart{one}      $#1$
                    \nodepart{two}      $\dots$
                    \nodepart{three}    $#2$
                    }

\begin{document}
    \begin{forest}
for tree = {
    rectangle split,
    rectangle split horizontal,
    rectangle split parts=3,
    draw,
    %
    parent anchor=south,
    child anchor=north,
    edge = {-Stealth, semithick, shorten >=1mm, shorten <=1mm},
    l sep=12mm,
    s sep=3mm,
    calign=edge midpoint,
    where level=2{s sep=1mm}{}% insert diferent `s sep` at bottom of the tree
            }
[root, %circle, draw, thick
    [{\mpnc{q}{z}}
        [{\mpnc{q}{z}}
            [{\mpnc{q}{z}}]
            [{\mpnc{q}{z}}]
        ]
        [{\mpnc{q}{z}}
            [{\mpnc{q}{z}}]
        ]
        [{\mpnc{q}{z}}
            [{\mpnc{q}{z}}]
        ]
    ]
] 
    \end{forest}
\end{document}

enter image description here

Note: I change the standalone file name from trie_visual to sub since later is name of test container for such cases ...

1
  • I'm not sure what changed exactly, maybe the style was my problem :-). But this worked and also got rid of the double borders between some of the cells. I'll look into the forest package. Thanks! – John Dec 14 '20 at 17:30

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.