1

I'm very detail oriented and could need some help aligning my text inside my node.

In my MWE, the text in the lower part of the node is "touching" the horizontal line splitting the circle node.

How can I lower that text so it is more centered inside the lower half?

Thanks!

MWE


\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{automata,calc,positioning,shapes,arrows,decorations,decorations.pathmorphing,decorations.pathreplacing,plotmarks}
\usepackage{pgfplots}
\usepackage{graphics}
\definecolor{mygray}{gray}{0.8}

\begin{document}
    \begin{frame}
        \frametitle{Layering am Beispiel}
        \begin{columns}
            \begin{column}[t]{0.5\textwidth}
                \begin{tikzpicture}[scale=0.5,baseline=(current bounding box.north),
                    state/.style={circle split, draw, minimum size=1.5em, inner sep=0pt, text width=6mm, align=center, text depth= 1mm}]
                    \node[state] (n6) at (1,10) {\footnotesize $v_6$ \nodepart{lower} \footnotesize 10};
                    \node[state] (n4) at (4,8)  {\footnotesize $v_4$ \nodepart{lower} \footnotesize 4};
                    \node[state] (n5) at (8,9)  {\footnotesize $v_5$ \nodepart{lower} \footnotesize 15};
                    \node[state] (n1) at (11,8) {\footnotesize $v_1$ \nodepart{lower} \footnotesize 1};
                    \node[state] (n2) at (9,6)  {\footnotesize $v_2$ \nodepart{lower} \footnotesize 7};
                    \node[state] (n3) at (5,5)  {\footnotesize $v_3$ \nodepart{lower} \footnotesize 10};
                    \node[state] (n7) at (2,7)  {\footnotesize $v_7$ \nodepart{lower} \footnotesize 5};
                    \node[state] (n8) at (5,11) {\footnotesize $v_8$ \nodepart{lower} \footnotesize 1};
                    %\node[scale=1.5] at (9,11) {$G = (V, E)$};
                    %\node[scale=1.5] at (9,10) {$c = 2$};
                    
                    \draw (n1) -- (n2) node [midway] {};
                    \draw (n1) -- (n5) node [midway] {};
                    \draw (n2) -- (n5) node [midway] {};
                    \draw (n2) -- (n3) node [midway] {};
                    \draw (n4) -- (n5) node [midway] {};
                    \draw (n4) -- (n6) node [midway] {};
                    \draw (n3) -- (n4) node [midway] {};
                    \draw (n3) -- (n5) node [midway] {};
                    \draw (n3) -- (n7) node [midway] {};
                    \draw (n6) -- (n7) node [midway] {};
                    \draw (n6) -- (n8) node [midway] {};
                    \draw (n5) -- (n8) node [midway] {};
                \end{tikzpicture}
                \begin{align*}
                    F_0 &= \{v_1, v_3, v_4\} \\
                    w(F_0) &= 15\\
                \end{align*}
            \end{column}
            \begin{column}[t]{0.5\textwidth}
                \centering
                \begin{tikzpicture}[scale=0.5,baseline=(current bounding box.north),
                    state/.style={circle split, draw, minimum size=1.5em, inner sep=0pt, text width=6mm, align=center, text depth= 1mm},
                    deleted/.style={circle split, draw, minimum size=1.5em, inner sep=0pt, text width=6mm, align=center, text depth= 1mm, draw=mygray, text=mygray}]
                    \node[state] (n6) at (1,10) {\footnotesize $v_6$ \nodepart{lower} \footnotesize 10};
                    \node[state] (n4) at (4,8)  {\footnotesize $v_4$ \nodepart{lower} \footnotesize 4};
                    \node[state] (n5) at (8,9)  {\footnotesize $v_5$ \nodepart{lower} \footnotesize 15};
                    \node[state] (n1) at (11,8) {\footnotesize $v_1$ \nodepart{lower} \footnotesize 1};
                    \node[state] (n2) at (9,6)  {\footnotesize $v_2$ \nodepart{lower} \footnotesize 7};
                    \node[state] (n3) at (5,5)  {\footnotesize $v_3$ \nodepart{lower} \footnotesize 10};
                    \node[state] (n7) at (2,7)  {\footnotesize $v_7$ \nodepart{lower} \footnotesize 5};
                    \node[state] (n8) at (5,11) {\footnotesize $v_8$ \nodepart{lower} \footnotesize 1};
                    %\node[scale=1.5] at (9,11) {$G = (V, E)$};
                    
                    \draw[style={gray,draw=mygray}] (n1) -- (n2) node [midway] {};
                    \draw[style={gray,draw=mygray}] (n1) -- (n5) node [midway] {};
                    \draw (n2) -- (n5) node [midway] {};
                    \draw (n2) -- (n3) node [midway] {};
                    \draw (n4) -- (n5) node [midway] {};
                    \draw (n4) -- (n6) node [midway] {};
                    \draw (n3) -- (n4) node [midway] {};
                    \draw (n3) -- (n5) node [midway] {};
                    \draw (n3) -- (n7) node [midway] {};
                    \draw (n6) -- (n7) node [midway] {};
                    \draw (n6) -- (n8) node [midway] {};
                    \draw (n5) -- (n8) node [midway] {};
                \end{tikzpicture}
                \begin{align*}
                    F_{OPT} &= \{v_1, v_3, v_8\} \\
                    w(F_{OPT}) &= 12\\
                \end{align*}
            \end{column}
        \end{columns}
    \end{frame}
\end{document}
1

Left image is corrected, right is as in your MWE. Main differences are:

  • increased is inner sep
  • font size is defined in style for state

enter image description here

\documentclass{beamer}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta, automata,
                calc,
                positioning,
                shapes.multipart} % <---
\definecolor{mygray}{gray}{0.8}

\begin{document}
\begin{frame}
\frametitle{Layering am Beispiel}
\begin{columns}
    \begin{column}{0.5\textwidth}
\begin{tikzpicture}[scale=0.45,
state/.style = {circle split, draw, minimum size=2em, inner sep=2pt, % <---
                text depth=0.25ex, font=\small}               % <---
                            ]
\node[state] (n6) at (1,5)  {$v_6$ \nodepart{lower} 10};
\node[state] (n4) at (4,3)  {$v_4$ \nodepart{lower}  4};
\node[state] (n5) at (8,4)  {$v_5$ \nodepart{lower} 15};
\node[state] (n1) at (11,3) {$v_1$ \nodepart{lower}  1};
\node[state] (n2) at (9,1)  {$v_2$ \nodepart{lower}  7};
\node[state] (n3) at (5,0)  {$v_3$ \nodepart{lower} 10};
\node[state] (n7) at (2,2)  {$v_7$ \nodepart{lower}  5};
\node[state] (n8) at (5,6)  {$v_8$ \nodepart{lower}  1};
%%
\draw   (n1) -- (n2)
        (n1) -- (n5)
        (n2) -- (n5)
        (n2) -- (n3)
        (n4) -- (n5)
        (n4) -- (n6)
        (n3) -- (n4)
        (n3) -- (n5) 
        (n3) -- (n7) 
        (n6) -- (n7) 
        (n6) -- (n8) 
        (n5) -- (n8);
\end{tikzpicture}
    \begin{align*}
F_0     & = \{v_1, v_3, v_4\} \\
w(F_0)  & = 15
    \end{align*}
    \end{column}
%%%
    \begin{column}{0.5\textwidth}
        \centering
        \begin{tikzpicture}[scale=0.45,baseline=(current bounding box.north),
            state/.style={circle split, draw, minimum size=1.5em, inner sep=0pt, text width=6mm, align=center, text depth= 1mm},
            deleted/.style={circle split, draw, minimum size=1.5em, inner sep=0pt, text width=6mm, align=center, text depth= 1mm, draw=mygray, text=mygray}]
            \node[state] (n6) at (1,10) { $v_6$ \nodepart{lower}  10};
            \node[state] (n4) at (4,8)  { $v_4$ \nodepart{lower}  4};
            \node[state] (n5) at (8,9)  { $v_5$ \nodepart{lower}  15};
            \node[state] (n1) at (11,8) { $v_1$ \nodepart{lower}  1};
            \node[state] (n2) at (9,6)  { $v_2$ \nodepart{lower}  7};
            \node[state] (n3) at (5,5)  { $v_3$ \nodepart{lower}  10};
            \node[state] (n7) at (2,7)  { $v_7$ \nodepart{lower}  5};
            \node[state] (n8) at (5,11) { $v_8$ \nodepart{lower}  1};
            %\node[scale=1.5] at (9,11) {$G = (V, E)$};

            \draw[style={gray,draw=mygray}] (n1) -- (n2) node [midway] {};
            \draw[style={gray,draw=mygray}] (n1) -- (n5) node [midway] {};
            \draw (n2) -- (n5) node [midway] {};
            \draw (n2) -- (n3) node [midway] {};
            \draw (n4) -- (n5) node [midway] {};
            \draw (n4) -- (n6) node [midway] {};
            \draw (n3) -- (n4) node [midway] {};
            \draw (n3) -- (n5) node [midway] {};
            \draw (n3) -- (n7) node [midway] {};
            \draw (n6) -- (n7) node [midway] {};
            \draw (n6) -- (n8) node [midway] {};
            \draw (n5) -- (n8) node [midway] {};
        \end{tikzpicture}
        \begin{align*}
            F_{OPT} &= \{v_1, v_3, v_8\} \\
            w(F_{OPT}) &= 12\\
        \end{align*}
    \end{column}
\end{columns}
\end{frame}
\end{document}

Addendum: For exercise, with relative positioning of nodes, their coloring. Just for fun :-).

\documentclass{beamer}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta, automata,
                calc,
                positioning,
                shapes.multipart} % <---

\begin{document}
\begin{frame}
\frametitle{Layering am Beispiel}
\begin{columns}
\tikzset{
node distance= 5mm and 5mm,
state/.style = {circle split, draw, thick,
                fill=yellow!10,
                minimum size=2em, inner sep=2pt, % <---
                text depth=0.25ex, font=\small}               % <---
        }
    \begin{column}{0.5\textwidth}
    \centering
\begin{tikzpicture}[scale=0.5]
    \begin{scope}[nodes=state]
\node (n1)                  {$v_6$ \nodepart{lower} 10};
\node (n2)  [right=of n1]   {$v_4$ \nodepart{lower}  4};
\node (n3)  [right=of n2]   {$v_5$ \nodepart{lower} 15};
\node (n4)  [right=of n3]   {$v_1$ \nodepart{lower}  1};
\node (n5)  [below=of n1]   {$v_7$ \nodepart{lower}  5};
\node (n6)  [right=of n5]   {$v_3$ \nodepart{lower} 10};
\node (n7)  [right=of n6]   {$v_2$ \nodepart{lower}  7};
\node (n8)  [above=of n2]   {$v_8$ \nodepart{lower}  1};
    \end{scope}
%%
\draw[gray]
        (n1) -- (n2) -- (n3) -- (n4)
        (n1) -- (n5) -- (n6) -- (n7) -- (n4)
        (n2) -- (n6)
        (n3) -- (n7)
        (n1) -- (n8) -- (n3);
\end{tikzpicture}
    \begin{align*}
F_0     & = \{v_1, v_3, v_4\} \\
w(F_0)  & = 15
    \end{align*}
    \end{column}
%%%
    \begin{column}{0.5\textwidth}
    \centering
\begin{tikzpicture}[scale=0.5]
    \begin{scope}[nodes=state]
\node (n1)                  {$v_6$ \nodepart{lower} 10};
\node (n2)  [right=of n1]   {$v_4$ \nodepart{lower}  4};
\node (n3)  [right=of n2]   {$v_5$ \nodepart{lower} 15};
\node (n4)  [right=of n3]   {$v_1$ \nodepart{lower}  1};
\node (n5)  [below=of n1]   {$v_7$ \nodepart{lower}  5};
\node (n6)  [right=of n5]   {$v_3$ \nodepart{lower} 10};
\node (n7)  [right=of n6]   {$v_2$ \nodepart{lower}  7};
\node (n8)  [above=of n2]   {$v_8$ \nodepart{lower}  1};
    \end{scope}
%%
\draw[gray]
        (n1) -- (n2) -- (n3) -- (n4)
        (n1) -- (n5) -- (n6) -- (n7) -- (n4)
        (n2) -- (n6)
        (n3) -- (n7)
        (n1) -- (n8) -- (n3);
\end{tikzpicture}
    \begin{align*}
F_{\mathrm{OPT}}    & = \{v_1, v_3, v_8\} \\
w(F_{\mathrm{OPT}}) & = 12
    \end{align*}
    \end{column}
\end{columns}
\end{frame}
\end{document}

enter image description here

1
  • Perfect, thank you very much! – Rhynden Feb 21 at 13:50

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.