TransWikia.com

Unwanted spacing between text and tikzpicture caused by "non-visual" code lines

TeX - LaTeX Asked on January 14, 2021

I want to show some subgraphs of a certain graph. I want them side by side and labeled.
This is what I’ve got:
enter image description here

I can’t provide working LaTeX-code, since I have implemented the graphdrawing functionality in Lua, but here is what it looks like:

defcoords{(0,0), (1,0), (1, 1), (0,1)}
defedges{1/2, 2/3, 3/4, 4/1, 2/4}
def scale {0.8}
def pos {center}
begin{center}
     scalebox{scale}{(1)xgraph{coords}{edges}{2/3, 3/4}{pos}} 
     scalebox{scale}{(2)xgraph{coords}{edges}{1/2, 4/1}{pos}}
     scalebox{scale}{(3)xgraph{coords}{edges}{}{pos}}
end{center}

The xgraph macro is:

directlua{gd = require("lua/graphdrawing")}
newcommand{xgraph}[5][]{
    begingroup
    edefvertexcoords{#2}
    edefedges{#3}
    edefblankedges{#4}
    defpositioning{#5}
    %
    directlua{
        v, e = gd.get_graph_objects("vertexcoords", "edges", "blankedges")
        vertex_data = gd.tikzify(v)
        edge_data = gd.tikzify(e)}
    edefvertexdata{directlua{tex.print(vertex_data)}}
    edefedgedata{directlua{tex.print(edge_data)}}
    %
    begin{tikzpicture}[scale = 1.5, nodes={circle,draw}, baseline=(current bounding box.positioning)]
        foreach x/y/style [count=i] in vertexdata {
            node[style] (i) at (x, y) {i};
        }
        foreach i/j/style in edgedata {
            draw[style] (i)--(j);
        }
        draw [red] (current bounding box.south west) rectangle (current bounding box.north east);
    end{tikzpicture}
    endgroup
}

As you can see from the picture, there is unwanted spacing between the labels and the TikZ pictures, in such a way that the labels seem to pair up with the wrong pictures. Note that I have added the bounding boxes of the TikZ pictures, so that is not what causes the problem.
Eventually I figured out that the problem is the LaTeX-code that comes in the beginning of the xgraph macro, but before the TikZ-picture environment. When I placed this code inside the TikZ figure (quite unnatural in my opinion), the issue was resolved.

My question is: how can LaTeX code which is not supposed to generate output (variable definitions, directlua blocks), cause spaces in the document? What is the best way to resolve it? Having everything in the TikZ figure seems inelegant, is this really the standard way of doing it?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP