0

How do I ensure that the texts at the nodes or at the edges stand where they should be rather than running across the figure? I would like it if I can box the nodes.

Here is what I am trying to do:

\documentclass[border=1pt]{standalone}
\usepackage{tikz}
\begin{document}

\begin{figure}
\begin{tikzpicture}

\draw [black, thick] (0,0)   node {    Ethiopia} -- (4,0)   node {   Egypt} -- (8,4)   node {      South Sudan} -- (4,4)   node {   Sudan}  -- (0,0)  -- (8,4); 
\draw [black, thick] (4, 0) -- (4, 4);
\draw[-] (0,0) -- node[below, red, thick] {hostile} (4,0);
\draw[-] (4,0) -- node[below, blue, thick] {friendly} (8,4);
\draw[-] (8,4) -- node[above, red, thick] {hostile} (4,4);
\draw[-] (4,4) -- node[above, blue, thick] {friendly} (0,0);
\draw[-] (0,0) -- node[left, blue, thick] {friendly} (8,4);
\draw[-] (4,0) -- node[right, blue, thick] {friendly} (4,4);



\end{tikzpicture}
\caption{Relations in January 2020} \label{fig: Relations in 2020}
\end{figure}

\begin{figure}
\begin{tikzpicture}

\draw [black, thick] (0,0)   node {    Ethiopia} -- (4,0)   node {   Egypt} -- (8,4)   node {      South Sudan} -- (4,4)   node {   Sudan}  -- (0,0)  -- (8,4); 
\draw [black, thick] (4, 0) -- (4, 4);
\draw[-] (0,0) -- node[below, red, thick] {hostile} (4,0);
\draw[-] (4,0) -- node[below, blue, thick] {friendly} (8,4);
\draw[-] (8,4) -- node[above, blue, thick] {friendly} (4,4);
\draw[-] (4,4) -- node[above, blue, thick] {hostile} (0,0);
\draw[-] (0,0) -- node[left, blue, thick] {unknown} (8,4);
\draw[-] (4,0) -- node[right, blue, thick] {friendly} (4,4);


\end{tikzpicture}
\caption{Relations in January 2021} \label{fig: Relations in 2020}
\end{figure}
\end{document}

1 Answer 1

2

Is something like this what you want?

enter image description here

I'd suggest to place nodes (positioning library with on grid option) and use them as reference to easily drawn the edges instead of absolute coordinates. Using nodes, edges stop drawing at their borders.

\documentclass[border=1pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture}
\begin{scope}[on grid]
\node[draw] (Ethiopia) {Ethiopia};
\node[draw, right=4cm of Ethiopia] (Egypt) {Egypt};
\node[draw, above=4cm of Egypt] (Sudan) {Sudan};
\node[draw, right=4cm of Sudan] (SSudan) {South Sudan};
\end{scope}
\draw[-] (Ethiopia) edge node[below, red, thick] {hostile} (Egypt)
                         edge node[sloped, above, blue, thick] {friendly} (Sudan)
                         edge node[sloped, above, pos=.25, blue, thick] {friendly} (SSudan);
\draw[-] (Egypt) edge node[above, sloped, near start, blue, thick] {friendly} (Sudan)
                        edge node[below, sloped, blue, thick] {friendly} (SSudan);
\draw[-] (Sudan) edge node[above, red, thick] {hostile} (SSudan);
\end{tikzpicture}
\end{document}

You must log in to answer this question.

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