5

I'm using the tikz package in LaTeX to construct a feedback loop for a control system as a part of a paper on control systems. The problem I'm running into is that I would like to place symbols under the arrows between the blocks in addition to the symbols which are currently above the arrows. For example I would like to place a symbol for $phi$ below the arrow, under the $tau$ symbol. I have no idea how to achieve this since I'm fairly new to LaTeX and tikz. Any help would be appreciated.

I've embedded all of my code below, as well as a snapshot of how the feedbackloop currently looks with the code.

enter image description here

\documentclass[class=minimal,border=15pt]{standalone}


\usepackage[utf8]{inputenc}
\usepackage[swedish]{babel}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}


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

\begin{tikzpicture}[auto, node distance=2cm,>=latex']
 \node [input, name=input] {};
 \node [sum, right of=input] (sum) {};
 \node [block, right of=sum] (controller) {Regulator};
 \node [block, right of=controller, node distance=3cm] (motor) {G$_{motor}$};
 \node [block, right of=motor, pin={[pinstyle]above:Störningar},
        node distance=3cm] (system) {Dynamik$_{\varphi}$};

 \draw [->] (controller) -- node[name=u] {$u$} (motor);
 \node [output, right of=system] (output) {};
 \node [block, below of=motor] (msystem) {Mätsystem};

 \draw [draw,->] (input) -- node {$\varphi_{ref}$} (sum);
 \draw [->] (sum) -- node {$e$} (controller);
 \draw [->] (motor) -- node {$\tau$} (system);
 \draw [->] (system) -- node [name=y] {$\varphi$}(output);
 \draw [->] (y) |- (msystem);
 \draw [->] (msystem) -| node[pos=0.99] {$-$}  node [near end] {$\varphi_m$} (sum);
\end{tikzpicture}

\end{document} 

migrated from stackoverflow.com May 14 '13 at 20:23

This question came from our site for professional and enthusiast programmers.

5

You can use multiple label keys in the options for a node:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[mynode/.style={draw,circle,minimum size=2cm}]
\node[mynode,label=left:$a$,label=right:$b$,label=60:$c$,label=220:$d$] {};
\end{tikzpicture}

\end{document}

enter image description here

In your case, you need an additional precaution since you declared auto globally, so you need to use auto=false for the node that will have multiple labels:

\documentclass[class=minimal,border=15pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[swedish]{babel}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows}

\tikzset{
block/.style = {draw, fill=gray!3, rectangle, minimum height=3em, minimum width=6em},
sum/.style = {draw, fill=gray!3, circle, node distance=1cm},
input/.style = {coordinate},
output/.style = {coordinate},
pinstyle/.style={pin edge={to-,thin,black}}
}

\begin{document}

\begin{tikzpicture}[node distance=1cm,>=latex']
 \node [input, name=input] {};
 \node [sum, right = of input] (sum) {};
 \node [block, right = of sum] (controller) {Regulator};
 \node [block, right = of controller, node distance=3cm] (motor) {G$_{motor}$};
 \node [block, right  = of motor, pin={[pinstyle]above:Störningar},
        node distance=3cm] (system) {Dynamik$_{\varphi}$};

 \draw [->] (controller) -- node[name=u,auto] {$u$} (motor);
 \node [output, right=of system] (output) {};
 \node [block, below  = of motor] (msystem) {Mätsystem};
 \draw [draw,->] (input) -- node[auto] {$\varphi_{ref}$} (sum);
 \draw [->] (sum) -- node[auto] {$e$} (controller);
 \draw [->] (motor) -- node[auto=false,label=below:$\varphi$,label=above:$\tau$] {}  (system);
 \draw [->] (system) -- node [auto,name=y] {$\varphi$}(output);
 \draw [->] (y) |- (msystem);
 \draw [->] (msystem) -| node[auto,pos=0.99] {$-$}  node [auto,near end] {$\varphi_m$} (sum);
\end{tikzpicture}

\end{document} 

enter image description here

Notice also that I replaced the old \tikzstyle for the newer \tikzset syntax.

1

I think something like

\draw [->] (motor) edge node[above] {$\tau$} node[below] {$\phi$} (system);

should do this

0
\usetikzlibrary{arrows.meta, positioning, calc}
\tikzset{%
port/.style     = {inner sep=0pt, font=\tiny},
sum/.style n args = {4}{draw, circle, node distance = 2cm, minimum size=.6cm, alias=sum,
    append after command={
        (sum.45) -- (sum.225)
        (sum.135) -- (sum.315)
        node at (sum.north) [port, below=1pt] {\textbf{#1}}
        node at (sum.west) [port, right=1pt] {\textbf{#2}}
        node at (sum.south) [port, above=1pt] {\textbf{#3}}
        node at (sum.east) [port, left=1pt] {\textbf{#4}}
    },
},
}
\begin{center}
\begin{tikzpicture}
    \draw node at (0, 0) [sum={}{+}{–}{}] (sum1) {}
    node [tf, right = of sum1] (tf1) {$G_C(s)$}
    node [tf, right = of tf1] (tf2) {$G_P(s)$}
    node at ($(tf2) + (1,0)$) [branch] (circ1) {};
    \draw[-Latex] (-1.5, 0) -- node [label = {[above, pos = .4]:$R(s)$}] () {} (sum1.west);
    \draw[-Latex] (tf1.east) -- (tf2.west);
    \draw[-Latex] (tf2.east) -- node [label = {[above, pos = .75]:$Y(s)$}] () {} ($(circ1)+(1,0)$);
    \draw[-Latex] (sum1.east) -- (tf1.west);
    \draw[-Latex] (circ1) -- ($(circ1) - (0, 1)$) -| (sum1.south);
\end{tikzpicture}
\end{center}

Sample control system.

This is someone else's code, I just modified it a little bit. I couldn't find the original post. So kudos to him/her, whoever posted this code's original form.

  • 1
    Please -- as usual here -- make your code snippet compilable for a fast proof ... – Mensch May 4 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy