Wie korrigiere ich diesen Diagrammblock?

Wie korrigiere ich diesen Diagrammblock?

Bildbeschreibung hier eingeben

\tikzstyle{block} = [draw, fill=blue!20, rectangle, 
minimum height=3em, minimum width=6em]
\tikzstyle{sum} = [draw, fill=blue!20, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

% The block diagram code is probably more verbose than necessary
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
% We start by placing the blocks
\node [input, name=input] {};
\node [sum, right of=input] (sum) {};
\node [block, right of=sum] (controller) {Controller};
\node [block, right of=controller, pin={[pinstyle]above:Disturbances},
node distance=3cm] (system) {System};
% We draw an edge between the controller and system block to 
% calculate the coordinate u. We need it to place the measurement block. 
\draw [->] (controller) -- node[name=u] {$u$} (system);
\node [output, right of=system] (output) {};
\node [block, below of=system] (measurements) {Measurements};
\node [block, left of=measurements ] (sensor) {Sensor};
\draw [<-] (measurements) -- node[name=k] {$k$} (sensor);
% Once the nodes are placed, connecting them is easy. 
\draw [draw,->] (input) -- node {$r$} (sum);
\draw [->] (sum) -- node {$e$} (controller);
\draw [->] (system) -- node [name=y] {$y$}(output);
\draw [->] (y) |- (measurements);
\draw [->] (sensor) -| node[pos=0.99] {$-$} 
node [near end] {$y_m$} (sum);
\end{tikzpicture}

Antwort1

Ersetzen left of=measurementsdurch below=of controller.

Drei kleine Anmerkungen:

  • Die Tasten left of, right ofetc. sind veraltet. Es wird jetzt empfohlen, left=of ...anstelle von left of=...etc. zu verwenden. Dies erfordert \usetikzlibrary{positioning}. Diese Änderung ist mehr als eine Vertauschung von Buchstaben. Die neue Positionierung ist robuster und flexibler als die alte Methode.

  • Sie können block/.style = {...}(als Option für tikzpictureoder als Argument für \tikzset) anstelle von schreiben \tikzstyle{block} = [...]. So wie ich es verstehe, entspricht die erste Methode (die ich unten auch verwendet habe) eher den aktuellen Tikz-Konventionen. Die zweite Methode ist eine eher singuläre Syntax, die sonst nirgendwo in Tikz verwendet wird.

  • Wie Zarko in den Kommentaren angemerkt hat, kann der Knotenabstand in x- und y-Richtung unterschiedlich gewählt werden, indem man beispielsweise angibt node distance=1cm and 2cm: .

Bildbeschreibung hier eingeben

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}
\tikzset
  {block/.style =
    {draw, fill=blue!20, rectangle, minimum height=3em, minimum width=6em},
   sum/.style = {draw, fill=blue!20, circle, node distance=1cm},
   input/.style = {coordinate},
   output/.style = {coordinate},
   pinstyle/.style = {pin edge={to-,thin,black}}
  }

\begin{document}
% The block diagram code is probably more verbose than necessary
\begin{tikzpicture}[auto, node distance=1cm and 2cm,>=latex']
% We start by placing the blocks
\node [input, name=input] {};
\node [sum, right=of input] (sum) {};
\node [block, right=of sum] (controller) {Controller};
\node [block, right=of controller, pin={[pinstyle]above:Disturbances},
node distance=3cm] (system) {System};
% We draw an edge between the controller and system block to 
% calculate the coordinate u. We need it to place the measurement block. 
\draw [->] (controller) -- node[name=u] {$u$} (system);
\node [output, right=of system] (output) {};
\node [block, below=of system] (measurements) {Measurements};
\node [block, below=of controller] (sensor) {Sensor};
\draw [<-] (measurements) -- node[name=k] {$k$} (sensor);
% Once the nodes are placed, connecting them is easy. 
\draw [draw,->] (input) -- node {$r$} (sum);
\draw [->] (sum) -- node {$e$} (controller);
\draw [->] (system) -- node [name=y] {$y$}(output);
\draw [->] (y) |- (measurements);
\draw [->] (sensor) -| node[pos=0.99] {$-$} 
node [near end] {$y_m$} (sum);
\end{tikzpicture}
\end{document}

Antwort2

Als Ergänzung zugernot(nicht so sehr) „ausführliche“ Antwort, hoffentlich ist sie prägnanter :) Darin verwende ich calceine quotesBibliothek:

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows, calc, positioning, quotes}
\tikzset{
     block/.style = {rectangle, draw, fill=blue!20, minimum height=3em, minimum width=6em},
       sum/.style = {circle, draw, fill=blue!20},
 every pin/.style = {pin edge={<-,black}},
                > = latex'
        }

\begin{document}
    \begin{tikzpicture}[auto, 
    node distance = 6mm and 12mm]
% placing the blocks
\coordinate (in);
\node (sum)             [sum, right=of in] {};
\node (controller)      [block, right=of sum]           {Controller};
\node (system)          [block, pin=above:Disturbances, 
                         right=of controller]           {System};
\coordinate[right=of system] (out);
\node (measurement)     [block, below=of controller]    {Measurements};
\node (sensor)          [block, below=of system]        {Sensor};
% edges between blocks
\draw[->]   (in)            edge ["$r$"] (sum)
            (sum)           edge ["$e$"] (controller)
            (controller)    edge["$u$"]  (system)
            (system)        edge["$y$"]  (out)
            (sensor)        edge["$k$"] (measurement)
            (measurement)   -|  (sum)
                            node [pos=0.75] {$y_m$}
                            node [pos=0.95] {$-$};
\draw[->]   ($(system.east)!0.5!(out)$) |- (sensor);
\end{tikzpicture}
\end{document}

Bildbeschreibung hier eingeben

Bearbeiten:Änderung unter BerücksichtigungCarLaTeXKommentar, Kommentare im Code sind jetzt aussagekräftiger. Ich glaube immer noch, dass meine vorgeschlagene Reihenfolge der Blöcke „Sensor“ und „Messung“ richtig ist. Solange diese Blöcke jedoch nicht linear sind, ist die Reihenfolge nicht wesentlich :)

Antwort3

Ich denke, Sie könnten auch ein TikZ verwenden matrix.

Bitte beachten Sie, dass arrowsdie Bibliothek veraltet ist. Aus dem TikZ- und PGF-Handbuch, Abs. 16.1:

Anmerkung: Die Bibliotheken arrows und arrows.spaced sind veraltet. Verwenden Sie stattdessen/zusätzlich arrows.meta, was Ihnen alles ermöglicht, was die alten Bibliotheken boten, und noch viel mehr. Die alten Bibliotheken funktionieren jedoch immer noch und Sie können sogar alte und neue Pfeilspitzen mischen (die alten Pfeilspitzen können allerdings nicht auf die im Rest dieses Abschnitts beschriebenen Weisen konfiguriert werden; wenn Sie beispielsweise scale=2 für einen Latex-Pfeil angeben, hat dies keine Auswirkung, während es bei Latex-Pfeilen deren Größe wie erwartet verdoppelt.)

Darüber hinaus sollte, wie gernot bereits sagte, \tikzsetanstelle von verwendet werden \tikzstyle(sieheHier).

\documentclass{book}
\usepackage{tikz}   
\usetikzlibrary{arrows.meta,matrix,positioning}

\begin{document}

\tikzset{%
    block/.style={draw, fill=blue!20, rectangle, 
    minimum height=3em, text width=7em,align=center},
    sum/.style={draw, fill=blue!20, circle},
    pinstyle/.style={pin edge={latex-,thin,black}},
    mylabup/.style={midway,above},
    >=latex,
    }   
\begin{tikzpicture}
    \matrix[column sep=3em, row sep=4ex]{%
    \coordinate (input);
    &
    \node [sum] (sum) {};
    &
    \node [block] (controller) {Controller};
    &
    \node [block, pin={[pinstyle]above:Disturbances}] (system) {System};
    &
    \coordinate (output);
\\
    &
    &
    \node [block] (sensor) {Sensor};
    &
    \node [block] (measurements) {Measurements};
    \\
    };
    \draw [->] (controller) -- node[mylabup] {$u$} (system);
    \draw [->] (measurements) -- node[mylabup] {$k$} (sensor);
    \draw [->] (input) -- node[mylabup] {$r$} (sum);
    \draw [->] (sum) -- node[mylabup] {$e$} (controller);
    \draw [->] (system) -- node [name=y,mylabup] {$y$} (output);
    \draw [->] (y) |- (measurements);
    \draw [->] (sensor) -| 
node [near end, left] {$y_m$} (sum);

\node[below left = -2pt and -1pt of sum] {$-$};
\end{tikzpicture}
\end{document}

Bildbeschreibung hier eingeben

verwandte Informationen