1

I need the nodes to not overlap and I don't know what to do. I tried altering the paper size, the font size and the minimum node size. I would adjust the coordinates to have enough space between the nodes but then they no longer fit on the page. Is there a way to get a bigger page or is there a completly different solution?

Here's my code:

(I actually have five times as many nodes as I posted here, I shortened the code for a better overview)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,decorations.pathmorphing,
backgrounds,positioning,fit,petri}
\begin{document}
\begin{tikzpicture}
[knoten/.style={circle,draw=black,fill=white,thick,minimum size=5mm}]
\node[knoten] (100440122122) at (-2.3050251367735135,-2.127287738803567)  {Bous};
\node[knoten] (100420113113) at (-5.24540261832908,2.1132145700854146) {Merzig,Kreisstadt};
\node[knoten] (100440114114) at (-5.343622401662404,0.33221152119648956) {Rehlingen-Siersburg};
\node[knoten] (100450111111) at (4.9851298716709325,-0.2559058854702032) {Bexbach,Stadt};
\node[knoten] (100410511511) at (2.077483109670924,-1.0254955010256834) {Friedrichsthal,Stadt};
\node[knoten] (100410516516) at (1.1544429856709257,-1.1347092788035258) {Quierschied};
\node[knoten] (100430114114) at (3.8074926165598186,-0.602704172136883) {Neunkirchen,Kreisstadt};
\node[knoten] (100440121121) at (-4.8337606849957435,-1.0308406943591932) {Wallerfangen};
\node[knoten] (100440118118) at (-2.032046527217957,-1.4421910654701706) {Schwalbach};
\node[knoten] (100460112112) at (1.7300380514487106,1.9577006767520475) {Marpingen};
\node[knoten] (100410518518) at (1.814984774115366,-1.713832856581236) {Sulzbach/Saar,Stadt};
\node[knoten] (100450113113) at (4.324141119226477,-5.46156871658129) {Gersheim};
\end{tikzpicture}
\end{document}

enter image description here

Haflad
  • 33
  • 1
    To save at least some space, you could introduce line breaks in the text as described here: Manual/automatic line breaks and text alignment in TikZ nodes – leandriis Jul 05 '18 at 08:21
  • How did you come up with the coordinates? You could position them relative to each other to make them non-ovelapping. – John Kormylo Jul 05 '18 at 13:01
  • @JohnKormylo The nodes are real cities and I scaled the real coordinates down. I could of course scale them bigger but if I divide the coordinates by a smaller number the nodes at the right do no longer fit on the page. There would be a bit more space to the left but somehow I cannot scale them in a way that there is as much space to the left as there is to the right. If I could move the whole picture a few cm to the right I could scale the picture up a bit. – Haflad Jul 05 '18 at 14:06
  • You can apply scales and font changes within tikz. Ultimately you might wind up offsetting the names and using arrows. See also https://tex.stackexchange.com/questions/399116/ideal-shape-of-elliptical-nodes. – John Kormylo Jul 05 '18 at 18:05

1 Answers1

1

The nodes will be dimensioned according to the size of the text, here an option that allows you to change the size of each node, but in turn reduces the size of the text, if you want to keep the size of the text, there is also the option that keeps the text and It allows you to draw a circle according to the size you want, which can indicate some type of value.

For the case of document size you can use the standalone class, which allows you to draw whatever you get in the output according to what you draw. Then you can import the pdf document generated using the graphics library, and include the drawing as any image, without losing the vector properties of the drawing made in tikz.

USING:

\draw[knoten] (-5.0269,-1.2254) circle (0.5cm) node (100440122122){Bous};
\draw[knoten] (-8.7754,5.1376) circle (1cm) node (100420113113){Merzig,\\Kreisstadt};
\draw[knoten] (-8.0377,2.0813) circle (1cm) node (100440114114){Rehlingen-Siersburg};
\draw[knoten] (6.1592,1.6599) circle (1cm) node (100450111111){Bexbach,\\Stadt};
\draw[knoten] (2.2251,0.811) circle (1cm) node (100410511511){Friedrichsthal,\\Stadt};
\draw[knoten] (-1.8769,-5.3392)circle (1cm) node (100410516516){Quierschied};
\draw[knoten] (4.4419,1.4106) circle (1.2cm) node (100430114114){Neunkirchen\\Kreis\\stadt};
\draw[knoten] (-7.0226,0.624) circle (1cm) node (100440121121){Wallerfangen};
\draw[knoten] (-4.446,-0.1781) circle (1.5cm) node (100440118118){Schwalbach};
\draw[knoten] (1.3201,5.106) circle (1cm) node (100460112112){Marpingen};
\draw[knoten] (1.3887,-0.3528) circle (1cm) node (100410518518){Sulzbach/Saar,\\Stadt};
\draw[knoten] (4.9395,-6.1119) circle (2cm) node (100450113113){Gersheim};

RESULT: enter image description here

USING: A drawing command definition \Knoten that uses scope and transform shape...

\Knoten(-5.0269,-1.2254)[0.8]{Bous};
\Knoten(-8.7754,5.1376)[1]{Merzig, \\Kreisstadt};
\Knoten(-8.0377,2.0813)[0.8]{Rehlingen\\Siersburg};
\Knoten(6.1592,1.6599)[0.8]{Bexbach, \\Stadt};
\Knoten(2.2251,0.811)[0.5]{Friedrichsthal,\\ Stadt};
\Knoten(-1.8769,-5.3392)[1]{Quierschied};
\Knoten(4.4419,1.4106)[0.8]{Neunkirchen,\\ Kreisstadt};
\Knoten(-7.0226,0.624)[0.9]{Wallerfangen};
\Knoten(-4.446,-0.1781)[0.8]{Schwalbach};
\Knoten(1.3201,5.106)[1]{Marpingen};
\Knoten(1.3887,-0.3528)[0.6]{Sulzbach/Saar,\\ Stadt};
\Knoten(4.9395,-6.1119)[1]{Gersheim};

RESULT: enter image description here

MWE:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usepackage{graphicx}
\begin{document}
    \begin{tikzpicture}[
        %Environment styles
        knoten/.style={%Style for normal shapes
            fill=green,
            fill opacity=.2,
            draw opacity=0.2,
            text opacity=1,
            align=center
        }   
    ]
    %New Tikz Objet
    \def\Knoten(#1)[#2]#3{%#1: Position#2: Identifier.
        \begin{scope}[shift={(#1)},scale=#2, every node/.append style={transform shape}] % using to make coordinate objet.
        \node[
            draw,
            circle,
            fill=blue,
            fill opacity=.2,
            draw opacity=1,
            text opacity=1,
            align=center
        ] at (0,0){#3};  %set this coordinate as anode
        \end{scope}
    }
    % Background map obtained from google maps.
    \node[inner sep=0pt] (FIG1) at (0,0) {\includegraphics[scale=1]{MAP}};
    % Scaling the shapes.
    \Knoten(-5.0269,-1.2254)[0.8]{Bous};
    \Knoten(-8.7754,5.1376)[1]{Merzig, \\Kreisstadt};
    \Knoten(-8.0377,2.0813)[0.8]{Rehlingen\\Siersburg};
    \Knoten(6.1592,1.6599)[0.8]{Bexbach, \\Stadt};
    \Knoten(2.2251,0.811)[0.5]{Friedrichsthal,\\ Stadt};
    \Knoten(-1.8769,-5.3392)[1]{Quierschied};
    \Knoten(4.4419,1.4106)[0.8]{Neunkirchen,\\ Kreisstadt};
    \Knoten(-7.0226,0.624)[0.9]{Wallerfangen};
    \Knoten(-4.446,-0.1781)[0.8]{Schwalbach};
    \Knoten(1.3201,5.106)[1]{Marpingen};
    \Knoten(1.3887,-0.3528)[0.6]{Sulzbach/Saar,\\ Stadt};
    \Knoten(4.9395,-6.1119)[1]{Gersheim};

    %IF you use TikzEdt, you can find the coordinates draggin an overlay. 
%   \draw[knoten] (-5.0269,-1.2254) circle (0.5cm) node (100440122122){Bous};
%   \draw[knoten] (-8.7754,5.1376) circle (1cm) node (100420113113){Merzig,\\Kreisstadt};
%   \draw[knoten] (-8.0377,2.0813) circle (1cm) node (100440114114){Rehlingen-Siersburg};
%   \draw[knoten] (6.1592,1.6599) circle (1cm) node (100450111111){Bexbach,\\Stadt};
%   \draw[knoten] (2.2251,0.811) circle (1cm) node (100410511511){Friedrichsthal,\\Stadt};
%   \draw[knoten] (-1.8769,-5.3392)circle (1cm) node (100410516516){Quierschied};
%   \draw[knoten] (4.4419,1.4106) circle (1.2cm) node (100430114114){Neunkirchen\\Kreis\\stadt};
%   \draw[knoten] (-7.0226,0.624) circle (1cm) node (100440121121){Wallerfangen};
%   \draw[knoten] (-4.446,-0.1781) circle (1.5cm) node (100440118118){Schwalbach};
%   \draw[knoten] (1.3201,5.106) circle (1cm) node (100460112112){Marpingen};
%   \draw[knoten] (1.3887,-0.3528) circle (1cm) node (100410518518){Sulzbach/Saar,\\Stadt};
%   \draw[knoten] (4.9395,-6.1119) circle (2cm) node (100450113113){Gersheim};

    \end{tikzpicture}
\end{document}

If you save the code in a tex archive named as examplehelp33.tex; when you compile you can obtain examplehelp33.pdf and then you can include it in your main document, try with the code below:

 % arara: pdflatex: {synctex: yes, action: nonstopmode}

\documentclass[a4paper]{article}
\usepackage[top=2cm,bottom=2cm,left=3cm,right=2cm]{geometry}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{backgrounds}

\begin{document}
\lipsum[1-2]

    \begin{figure}[!h]
        \centering
        \includegraphics[width=\textwidth]{examplehelp33} 
        \caption{Imported pdf using graphicx}
    \end{figure}

\lipsum[3-4]    

    \begin{figure}[!h]
        \centering
        \begin{tikzpicture}
        \node[inner sep=0pt] (FIG1) at (0,0) {\includegraphics[scale=0.8,angle=90]{examplehelp33}};
        \end{tikzpicture}
        \caption{Imported pdf within Tikz environment}
    \end{figure}

\end{document}

RESULT:

NOTE: some border is added in the pdf output from the tikz code by \documentclass[border=5mm]{standalone}. cou can erase this opcode or defining as 0mm. enter image description here

J Leon V.
  • 11,533
  • 16
  • 47