1

I am using the package tikz-network (https://ctan.org/pkg/tikz-network?lang=en).

Following is my code:

\begin{figure}[h]
\begin{center}
\begin{tikzpicture}[scale=0.5]
    %\SetVertexStyle[fontsize=\large]
    \Vertices[IdAsLabel,size=0.5,color=white]{data/vertices4x4.csv}
    \Edges[]{data/edges1_4x4.csv}
\end{tikzpicture}
\end{center}
\end{figure}

Where data/vertices4x4.csv is

id, x, y
0;0, 0, 0
0;1, 0, -2
0;2, 0, -4
0;3, 0, -6
1;0, 2, 0
1;1, 2, -2
1;2, 2, -4
1;3, 2, -6
2;0, 4, 0
2;1, 4, -2
2;2, 4, -4
2;3, 4, -6
3;0, 6, 0
3;1, 6, -2
3;2, 6, -4
3;3, 6, -6

and data/edges1_4x4.csv is

u, v, bend, style
0;0, 1;0, 0, dashed
0;1, 1;1, 0, dashed
0;2, 1;2, 0, dashed
0;3, 1;3, 0, dashed
1;0, 2;0, 0, dashed
1;1, 2;1, 0, dashed
1;2, 2;2, 0, dashed
1;3, 2;3, 0, dashed
2;0, 3;0, 0, dashed
2;1, 3;1, 0, dashed
2;2, 3;2, 0, dashed
2;3, 3;3, 0, dashed
3;0, 0;0, 190, dashed
3;1, 0;1, 190, dashed
3;2, 0;2, 190, dashed
3;3, 0;3, 190, dashed

If I keep the angle 190 in edges1_4x4.csv, I get an extra (approx. 5cm) margin in my tikz picture. While, if I keep this angle to be 50, there is no such margin. Can you please tell me a way to remove the extra margin in case of angle 190?

1 Answers1

2

Welcome. I can't reproduce 5cm extra, but it is known that the bounding box for Bezier curves is to generous. One ad hoc fix is to adjust it by hand. This can be done with the command

\path[use as bounding box] (-1,-7) rectangle (7,0.8);

where the coordinates of the rectangle are adjusted by hand in this case. A less cumbersome solution is to exclude the edges from the bounding box. This can be achieved by putting the command in an overlay scope,

\begin{scope}[overlay]
\Edges[]{edges1_4x4.csv}
\end{scope}

Full MWE:

\documentclass[a4paper,12pt]{article}
\usepackage[margin=1cm]{geometry}
\usepackage{filecontents}
\begin{filecontents*}{vertices4x4.csv}
id, x, y
0;0, 0, 0
0;1, 0, -2
0;2, 0, -4
0;3, 0, -6
1;0, 2, 0
1;1, 2, -2
1;2, 2, -4
1;3, 2, -6
2;0, 4, 0
2;1, 4, -2
2;2, 4, -4
2;3, 4, -6
3;0, 6, 0
3;1, 6, -2
3;2, 6, -4
3;3, 6, -6
\end{filecontents*}
\begin{filecontents*}{edges1_4x4.csv}
u, v, bend, style
0;0, 1;0, 0, dashed
0;1, 1;1, 0, dashed
0;2, 1;2, 0, dashed
0;3, 1;3, 0, dashed
1;0, 2;0, 0, dashed
1;1, 2;1, 0, dashed
1;2, 2;2, 0, dashed
1;3, 2;3, 0, dashed
2;0, 3;0, 0, dashed
2;1, 3;1, 0, dashed
2;2, 3;2, 0, dashed
2;3, 3;3, 0, dashed
3;0, 0;0, 190, dashed
3;1, 0;1, 190, dashed
3;2, 0;2, 190, dashed
3;3, 0;3, 190, dashed
\end{filecontents*}
\usepackage{tikz-network}
\begin{document}
\begin{figure}[h]
\centering
\fbox{\begin{tikzpicture}[scale=0.5]
    %\SetVertexStyle[fontsize=\large]
    \Vertices[IdAsLabel,size=0.5,color=white]{vertices4x4.csv}
    \Edges[]{edges1_4x4.csv}
\end{tikzpicture}}
\caption{Original bounding box.}
\end{figure}
\begin{figure}[h]
\centering
\fbox{\begin{tikzpicture}[scale=0.5]
    \path[use as bounding box] (-1,-7) rectangle (7,0.8);
    %\SetVertexStyle[fontsize=\large]
    \Vertices[IdAsLabel,size=0.5,color=white]{vertices4x4.csv}
    \Edges[]{edges1_4x4.csv}
\end{tikzpicture}}
\caption{Modified bounding box.}
\end{figure}
\begin{figure}[h]
\centering
\fbox{\begin{tikzpicture}[scale=0.5]
    %\SetVertexStyle[fontsize=\large]
    \Vertices[IdAsLabel,size=0.5,color=white]{vertices4x4.csv}
    \begin{scope}[overlay]
    \Edges[]{edges1_4x4.csv}
    \end{scope}
\end{tikzpicture}}
\caption{Edges overlay.}
\end{figure}
\end{document}

enter image description here

The \fboxes are only to guide the eye.