라인에 노드 텍스트 배치

라인에 노드 텍스트 배치
\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]옵션을 제거하면 비슷한 결과를 얻을 수 있습니다.autotikzpicture

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}

관련 정보