我非常注重细节,可能需要一些帮助来对齐节点内的文本。
在我的 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
左图已更正,右图与您的 MWE 一致。主要区别在于:
- 增加的是
inner sep
- 字体大小在样式中定义
state
\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}
附录: 为了练习,对节点进行相对定位,并对其着色。只是为了好玩 :-)。
\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}