\path [line] (switches) -- node {[[1, 0, 1], [0, 1, 0], [0, 1, 0], [0, 1, 0]]} (switches-ind);
将文本放在行的右侧,上方则放在行的左侧。我怎样才能将其精确地放在行的中间?
编辑:这是我的文档的完整示例。
\documentclass[
a4paper,
DIV = 12,
fleqn,
liststotoc,
bibtotoc,
idxtotoc]{scrreprt}
\usepackage[pdftex]{graphicx} %% Grafikeinbindung
\usepackage{subfigure} %% Bilder => Unterbilder (a),(b),.. innerhalb einer Figure
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
% Define block styles
\definecolor{foreground}{HTML}{6200EE}
\definecolor{background}{HTML}{03DAC5}
\tikzstyle{decision} = [diamond, draw, text=white, fill=foreground,
text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=foreground, text=white,
text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{input-block} = [rectangle, draw, fill=background,
text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=background, node distance=3cm,
minimum height=2em]
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}[node distance = 3cm, auto]
% Place nodes
\node [block] (serial) {calculate serial modules};
\node [input-block, left of=serial] (voltage) {desired voltage};
\node [input-block, above of=serial] (cell-voltage) {cell voltage};
\node [input-block, right of=serial] (number-cells) {number of cells};
\node [block, below of=serial] (steps) {calculate steps};
\node [block, below of=steps] (config) {compute switch config};
\node [block, below of=config] (switches) {compute switch position};
\node [block, below of=switches] (switches-ind) {set switch position};
% Draw edges
\path [line] (serial) -- node {3} (steps);
\path [line] (steps) -- node {[1, 1, 2, 3]} (config);
\path [line] (config) -- node {[1, 0, 0, 0]} (switches);
\path [line] (switches) -- node [midway] {[[1, 0, 1], [0, 1, 0], [0, 1, 0], [0, 1, 0]]} (switches-ind);
\path [line,dashed] (voltage) -- node {12} (serial);
\path [line,dashed] (cell-voltage) -- node {4} (serial);
\path [line,dashed] (number-cells) -- node [above] {4} (serial);
\end{tikzpicture}
\end{figure}
\end{document}
答案1
我猜你正在寻找这样的东西:
如果将边缘节点样式定义为并从选项中[fill=white, anchor=center]
删除选项,您可以使用代码获得类似的结果。auto
tikzpicture
*题外话:我将使用quotes
边缘标签库,将边缘引号定义为:
every edge quotes/.style = {fill=white, inner sep=2pt, font=\footnotesize, anchor=center},
我还建议使用chains
和positioning
库来定位节点:
\documentclass[tikz, border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
positioning,
quotes}
% Define block styles
\definecolor{foreground}{HTML}{6200EE}
\definecolor{background}{HTML}{03DAC5}
\begin{document}
\begin{tikzpicture}[
node distance = 12mm and 11mm,
start chain = A going below,
block/.style args = {#1/#2}{draw, rounded corners, fill=#1, text=#2,
text width=5em, minimum height=3*\baselineskip, align=center,
font=\linespread{0.84}\selectfont, on chain=A},
block/.default = foreground/white,
every edge/.style = {draw,-{Straight Barb[angle=60:2pt 3]}},
every edge quotes/.style = {fill=white, inner sep=2pt, font=\footnotesize, anchor=center},
]
% Place nodes
\node [block=background/black] {cell voltage}; % A-1
\node [block] {calculate serial modules};
\node [block] {calculate steps};
\node [block] {compute switch config};
\node [block] {compute switch position};
\node [block] {set switch position}; % A-6
%
\node [block=background/black, left=of A-2] {desired voltage}; % A-7
\node [block=background/black, right=of A-2] {number of cells}; % A-8
% Draw edges
\path (A-1) edge[dashed,"$4$"] (A-2)
(A-2) edge["$3$"] (A-3)
(A-3) edge["${[1,1,2,3]}$"] (A-4)
(A-4) edge["${[1,0,0,0]}$"] (A-5)
(A-5) edge["${\bigl[[1,0,1], [0,1,0], [0,1,0], [0,1,0]\bigr]}$"] (A-6)
(A-7) edge[dashed,"$12$"] (A-2)
(A-8) edge[dashed,"$4$" '] (A-2)
;
\end{tikzpicture}
\end{document}