Tikz: Расположение стрелок

Tikz: Расположение стрелок

У меня проблема с правильным расположением 2 стрелок с правой стороны. Я хочу, чтобы они были "посередине".

GSM

Код:

\documentclass[12pt,a4paper]{scrartcl}
\begin{document}
\usetikzlibrary{decorations.markings}
\usepackage{tikz}
\begin{figure}[htbp]
\centering
\begin{minipage}[b]{.4\linewidth}
    \begin{tikzpicture}
    \node (System) [draw,minimum size=24mm] {Motor};
    \coordinate[above left = of System.west] (a1);
    \coordinate[below = 7mm of a1] (a2);
    \coordinate[below = 7mm of a2] (a3);
    \coordinate[below = 6.5mm of a3] (a4);
    \coordinate[above right= of System.east] (b1);
    \foreach \i [count=\xi from 1] in {2,...,5}
        \coordinate[below=of b\xi] (b\i);
    \foreach \i [count=\xi from 1] in {$u_\mathrm{a}$,$i_\mathrm{a}$,$u_\mathrm{f}$,$i_\mathrm{f}$}
    \draw[-latex'] (a\xi) node[left] {\i} -- (a\xi-| System.west);
    \foreach \i [count=\xi from 1] in {$n$,$M$}
        \draw[-latex'] (System.east |- b\xi) -- (b\xi) node[right] {\i};
    \end{tikzpicture}
    \caption{GSM als Motor}
    \label{fig:gsmmotor}
\end{minipage}
\qquad
\begin{minipage}[b]{.4\linewidth}
    \begin{tikzpicture}
        \node (System) [draw,minimum size=24mm] {Generator};
        \coordinate[above left = of System.west] (a1);
        \coordinate[below = 7mm of a1] (a2);
        \coordinate[below = 7mm of a2] (a3);
        \coordinate[below = 6.5mm of a3] (a4);
        \coordinate[above right= of System.east] (b1);
        \foreach \i [count=\xi from 1] in {2,...,5}
            \coordinate[below=of b\xi] (b\i);
        \foreach \i [count=\xi from 1] in {$n$,$M$,$u_\mathrm{f}$,$i_\mathrm{f}$}
        \draw[-latex'] (a\xi) node[left] {\i} -- (a\xi-| System.west);
        \foreach \i [count=\xi from 1] in {$u_a$,$i_a$}
            \draw[-latex'] (System.east |- b\xi) -- (b\xi) node[right] {\i};
        \end{tikzpicture}
        \caption{GSM als Generator}
        \label{fig:gsmgenerator}
\end{minipage}
\end{figure}
\end{document}

как мне отцентрировать стрелки?

Спасибо!

решение1

На основемой ответ:

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning}

\begin{document}
    \begin{figure}[htbp]
    \centering
\begin{minipage}[b]{.4\linewidth}
\centering
    \begin{tikzpicture}[
node distance = 3mm and 12mm
                        ]
\node (System) [draw,minimum size=24mm] {Motor};
%
\coordinate[above  left = of System.west, label=left:$u_a$]   (a2);
\coordinate[above   = 6mm of a2, label=left:$i_a$]            (a1);
\coordinate[below  left = of System.west, label=left:$u_f$] (a3);
\coordinate[below   = 6mm of a3, label=left:$u_f$]          (a4);
%
\coordinate[above right = of System.east, label=right:$n$] (b1);
\coordinate[below right = of System.east, label=right:$M$] (b2);
%
\foreach \i in {1,...,4}{\draw[-Latex]   (a\i) -- (a\i -| System.west);}
\foreach \i in {1,2}{\draw[-Latex]   (b\i -| System.east) -- (b\i);}
    \end{tikzpicture}
\caption{GSM als Motor}
\label{fig:mimo}
\end{minipage}
\hfil
\begin{minipage}[b]{.4\linewidth}
\centering
    \begin{tikzpicture}[
node distance = 3mm and 12mm
                        ]
\node (System) [draw,minimum size=24mm] {Generator};
%
\coordinate[above  left = of System.west, label=left:$n$]   (a2);
\coordinate[above   = 6mm of a2, label=left:$M$]            (a1);
\coordinate[below  left = of System.west, label=left:$u_3$] (a3);
\coordinate[below   = 6mm of a3, label=left:$u_2$]          (a4);
%
\coordinate[above right = of System.east, label=right:$u_a$] (b1);
\coordinate[below right = of System.east, label=right:$i_a$] (b2);
%
\foreach \i in {1,...,4}{\draw[-Latex]   (a\i) -- (a\i -| System.west);}
\foreach \i in {1,2}{\draw[-Latex]   (b\i -| System.east) -- (b\i);}
    \end{tikzpicture}
\caption{GSM als Generator}
\label{fig:mimo}
\end{minipage}
    \end{figure}
\end{document}

введите описание изображения здесь

решение2

Для этого не нужны никакие библиотеки, ни сложные команды. С помощью pos=<fraction>можно добавить координату в некоторой дробной позиции соответствующих ребер, а затем добавить стрелки и узлы. Все это так же просто, как сказать

\path (System.south west) -- (System.north west)  
    foreach \X/\Z  in {0.05/i_f,0.35/u_f,0.65/M,0.95/n}
    {coordinate[pos=\X](aux)  (aux) edge[latex-] ++ (-1,0) 
    node[left=1cm]{$\Z$}};

МВЭ:

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{tikz}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{minipage}[b]{.4\linewidth}
  \begin{tikzpicture}
    \node (System) [draw,minimum size=24mm] {Motor};
    \path (System.south west) -- (System.north west)  
    foreach \X/\Z  in {0.05/i_f,0.35/u_f,0.65/M,0.95/n}
    {coordinate[pos=\X](aux)  (aux) edge[latex-] ++ (-1,0) 
    node[left=1cm]{$\Z$}};
    \path (System.south east) -- (System.north east)  
    foreach \X/\Z in {0.3/u_a,0.7/i_a}
    {coordinate[pos=\X] (aux) (aux) edge[-latex] ++ (1,0) node[right=1cm]{$\Z$}};
  \end{tikzpicture}
  \caption{GSM als Motor.}
 \label{fig:gsmmotor}
\end{minipage}
\qquad
\begin{minipage}[b]{.4\linewidth}
  \begin{tikzpicture}
    \node (System) [draw,minimum size=24mm] {Motor};
    \path (System.south west) -- (System.north west)  
    foreach \X/\Z  in {0.05/i_f,0.35/u_f,0.65/M,0.95/n}
    {coordinate[pos=\X](aux)  (aux) edge[latex-] ++ (-1,0) 
    node[left=1cm]{$\Z$}};
    \path (System.south east) -- (System.north east)  
    foreach \X/\Z in {0.3/u_a,0.7/i_a}
    {coordinate[pos=\X] (aux) (aux) edge[-latex] ++ (1,0) node[right=1cm]{$\Z$}};
  \end{tikzpicture}
  \caption{GSM als Generator.}
  \label{fig:gsmgenerator}
\end{minipage}
\end{figure}
\end{document}

введите описание изображения здесь

решение3

  1. Чтобы разместить две стрелы всередина, я считал, что вы хотели(Надеюсь, я не ошибаюсь)эти две стрелки указывают натретийидве третистороны. Для этого я использую библиотеку calc, которая позволяет мне точно локализовать эти третьи стороны:

    \coordinate (u) at ($(System.north east)!.3333!(System.south east)$);
    \coordinate (i) at ($(System.north east)!.6666!(System.south east)$);

Скриншот

  1. Чтобы разместить arrowгоризонтально, я сначала размещаю текст на rightкаждойтретийузла «Система», затем нарисуйте стрелку с синтаксисом edge:

          \node[right =of u]{$n$}edge[<-](u);  
          \node[right =of i]{$M$}edge[<-](i);
    
  2. Я позволил себе разместить две фигуры рядом с TikZ. Для этого я поместил каждую из них в окружение scopeи сдвинул вторую с помощью xshift=7cm. Я дал имя каждому окружению области видимости: local bounding box=motorи local bounding box=generator, что позволяет мне очень легко разместить текст под ним.

    \begin{scope}[local bounding box=motor]
    % code for figure 1
    % ...
    \end{scope}
    \node [anchor=north,text width=6cm]at (motor.south) {\captionof{figure}{GSM als Motor}}; % caption text

    \begin{scope}[xshift=7cm,local bounding box=generator] % code for figure 2 % .... \end{scope} \node [anchor=north,text width=6cm]at (generator.south) {\captionof{figure}{GSM als Generator}}; % caption text

  3. Чтобы не нумеровать цифры вручную, как подчеркнутоТорбьёрн ТВ моем первом решении я использую пакет capt-of, который позволяет нумеровать неплавающие объекты.

  4. Итак, я прокомментировал все строки вашего кода, которые я больше не использую (не удаляя их).

Переведено с помощью www.DeepL.com/Translator

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{tikz,capt-of}
\usetikzlibrary{decorations.markings,positioning,arrows,calc}
\begin{document}


%\begin{figure}[htbp]
\centering
%\begin{minipage}[b]{.4\linewidth}
\begin{tikzpicture}
    \begin{scope}[local bounding box=motor]
    \node (System) [draw,minimum size=24mm] {Motor};
    \coordinate[above left = of System.west] (a1);
    \coordinate[below = 7mm of a1] (a2);
    \coordinate[below = 7mm of a2] (a3);
    \coordinate[below = 6.5mm of a3] (a4);
    \coordinate[above right= of System.east] (b1);
    \foreach \i [count=\xi from 1] in {2,...,5}
        \coordinate[below=of b\xi] (b\i);
    \foreach \i [count=\xi from 1] in {$u_\mathrm{a}$,$i_\mathrm{a}$,$u_\mathrm{f}$,$i_\mathrm{f}$}
        \draw[-latex'] (a\xi) node[left] {\i} -- (a\xi-| System.west);
%   \foreach \i [count=\xi from 1] in {$n$,$M$}
%        \draw[-latex'] (System.east |- b\xi) -- (b\xi) node[right] {\i};   

    \coordinate (u) at ($(System.north east)!.3333!(System.south east)$);
    \coordinate (i) at ($(System.north east)!.6666!(System.south east)$);
    \node[right =of u]{$n$}edge[<-](u);  
    \node[right =of i]{$M$}edge[<-](i);    
    \end{scope}
    %\node[anchor=north,yshift=-5mm] at (motor.south){Figure\,1: GSM als Motor};
   \node [anchor=north,text width=6cm]at (motor.south) {\captionof{figure}{GSM als Motor}};
%    \end{tikzpicture}
%    \caption{GSM als Motor}
%    \label{fig:gsmmotor}
%\end{minipage}
%\qquad
%\begin{minipage}[b]{.4\linewidth}
%    \begin{tikzpicture}

\begin{scope}[xshift=7cm,local bounding box=generator]
    \node (System) [draw,minimum size=24mm] {Generator};
    \coordinate[above left = of System.west] (a1);
    \coordinate[below = 7mm of a1] (a2);
    \coordinate[below = 7mm of a2] (a3);
    \coordinate[below = 6.5mm of a3] (a4);
    \coordinate[above right= of System.east] (b1);
    \foreach \i [count=\xi from 1] in {2,...,5}
            \coordinate[below=of b\xi] (b\i);
    \foreach \i [count=\xi from 1] in {$n$,$M$,$u_\mathrm{f}$,$i_\mathrm{f}$}
        \draw[-latex'] (a\xi) node[left] {\i} -- (a\xi-| System.west);
%   \foreach \i [count=\xi from 1] in {$u_a$,$i_a$}
%       \draw[-latex'] (System.east |- b\xi) -- (b\xi) node[right] {\i};

    \coordinate (u) at ($(System.north east)!.3333!(System.south east)$);
    \coordinate (i) at ($(System.north east)!.6666!(System.south east)$);
    \node[right =of u]{$u_a$}edge[<-](u);  
    \node[right =of i]{$i_a$}edge[<-](i);
 \end{scope}
%\node[anchor=north,yshift=-5mm] at (generator.south){Figure\,2: GSM als Generator};
\node [anchor=north,text width=6cm]at (generator.south) {\captionof{figure}{GSM als Generator}};
\end{tikzpicture}
%        \caption{GSM als Generator}
        \label{fig:gsmgenerator}
%\end{minipage}
%\end{figure}
\end{document}

Связанный контент