Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to create a PID controller block diagram similar to the one here. At the moment my diagram looks as depicted below. What I still need is to right-and-left align the text inside the rectangular nodes, i.e. I'd like the letters P, I, D to be left and the equations right aligned. How do I accomplish that? Also, could you please tell me how to make the circle a little smaller?

enter image description here

\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em, text width=2.5cm]
\tikzstyle{sum}=[draw, fill=blue!20, shape=circle, node distance=2.5cm]
\begin{figure}[htbp]
\centering
    \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
        \node [int] (kp) {P $k_p e(t)$};
        \node [int] (ki) [below of=kp] {I $k_i \int{e(t)dt}$};
        \node [int] (kd) [below of=ki] {D $k_d \frac{e(t)}{dt}$};
        \node [sum] (sum) [right of=ki] {$\sum$};
        \node [coordinate] (joint1) [left of=ki, node distance=2cm]{};
        \node [coordinate] (begin) [left of=joint1, node distance=2cm]{};
        \node [coordinate] (end) [right of=sum, node distance=2cm]{};
        \draw[-] (begin) -- node {$e(t)$} (joint1);
        \draw[->] (joint1) |- (kp.west);
        \draw[->] (joint1) -- (ki);
        \draw[->] (joint1) |- (kd);
        \draw[->] (kp.east) -| node [pos=0.95] {$+$} (sum.north);
        \draw[->] (ki.east) -- node [pos=0.8] {$+$} (sum.west);
        \draw[->] (kd.east) -| node [pos=0.95] {$+$} (sum.south);
        \draw[->] (sum.east) -- (end);
    \end{tikzpicture}   
\end{figure}
share|improve this question
3  
Please make sure that the code is compilable. Ideally by making it a small, self-contained document, but at least by including all necessary definitions (the sum and int styles are missing here). –  Jake May 9 '12 at 16:17
    
Right, sorry, corrected. –  mmm May 9 '12 at 16:20
add comment

1 Answer

up vote 10 down vote accepted

You can use \hfill between the letter and the equation to get simultaneous left and right adjustment. This only works if you specify the text width explicitly, though (as you've done in your code).

For decreasing the size of the circle, you'll have to decrease the inner sep (which is set to 2pt by default). If you want the node to be smaller still, you'll have to choose a smaller font size (using font=\small, for instance), or scale the node using scale=<value>.

Here's a minimal example (this is also the preferred form of posting code like yours in a question, since it saves people the trouble of guessing the required libraries/packages, and makes sure that the code is actually complete):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em, text width=2.5cm]
\tikzstyle{sum}=[draw, fill=blue!20, shape=circle, inner sep=1pt, node distance=2.5cm]
\begin{figure}[htbp]
\centering
    \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
        \node [int] (kp) {P\hfill$k_p e(t)$};
        \node [int] (ki) [below of=kp] {I\hfill$k_i \int{e(t)dt}$};
        \node [int] (kd) [below of=ki] {D\hfill$k_d \frac{e(t)}{dt}$};
        \node [sum] (sum) [right of=ki] {$\sum$};
        \node [coordinate] (joint1) [left of=ki, node distance=2cm]{};
        \node [coordinate] (begin) [left of=joint1, node distance=2cm]{};
        \node [coordinate] (end) [right of=sum, node distance=2cm]{};
        \draw[-] (begin) -- node {$e(t)$} (joint1);
        \draw[->] (joint1) |- (kp.west);
        \draw[->] (joint1) -- (ki);
        \draw[->] (joint1) |- (kd);
        \draw[->] (kp.east) -| node [pos=0.95] {$+$} (sum.north);
        \draw[->] (ki.east) -- node [pos=0.8] {$+$} (sum.west);
        \draw[->] (kd.east) -| node [pos=0.95] {$+$} (sum.south);
        \draw[->] (sum.east) -- (end);
    \end{tikzpicture}   
\end{figure}

\end{document}
share|improve this answer
    
Forgotten to drop a human-to-human thank you before (apart of accepting the answer), so: Thanks Jake, that helped! –  mmm May 10 '12 at 6:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.