2

I have the code for a very simple open loop diagram and a closed loop diagram

enter image description here

The output line for the feedback loop under Y(s) is too short, I would like to expand it by 1 cm. However if I change the line in Tikz set from

output/.style = {coordinate,node distance=1cm},

to

output/.style = {coordinate,node distance=2cm},

Then the top figure change as well, so now the output line for the open loop diagram is now too long.

enter image description here

How do I declare multiple Tikz set for each diagram I have in Tikz? i.e. different specifications for different diagrams. Or is there another solution that I can use locally for each diagram?

Please help and may god save america.

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{arrows,calc,positioning}

\tikzset{
    block/.style = {draw, rectangle,
        minimum height=1cm,
        minimum width=2cm},
    input/.style = {coordinate,node distance=1cm},
    output/.style = {coordinate,node distance=1cm},
    arrow/.style={draw, -latex,node distance=2cm},
    pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
    sum/.style = {draw, circle, node distance=1cm},
}

\begin{document}

    \begin{figure}[ht]
        \begin{center}
            \begin{tikzpicture}[auto, node distance=1cm,>=latex']
            \node [input, name=input] {$U(s)$};
            \node [block, right=of input] (controller) {$C(s)$};
            \node [block, right=of controller] (plant) {$G(s)$};
            \node [output, right=of plant] (output) {};
            \draw [->] (input) -- node {$U(s)$} (controller);
            \draw [->] (controller) -- (plant);
            \draw [->] (plant) -- node [name = y] {$Y(s)$} (output);
            \end{tikzpicture}  
            \begin{tikzpicture}[auto, node distance=1cm,>=latex']
            \node [input, name=input] {};
            \node [sum, right=of input] (sum) {};
            \node [block, right=of sum] (controller) {$C(s)$};
            \node [block, right=2 of controller] (plant) {$G(s)$};
            \node [output, right=of plant] (output) {};
            \draw [draw,->] (input) -- node {$U(s)$} (sum);
            \draw [->] (sum) -- node {} (controller);
            \draw [->] (controller) -- node {} (plant);
            \draw [->] (plant) -- node [name=y] {$Y(s)$}(output);
            \draw [->] (y) -- ++ (0,-2) -| node [pos=0.99] {$-$} (sum);
            \end{tikzpicture}
        \end{center}
        \caption{TikzPicture}\label{fig}
    \end{figure}
\end{document}
1
  • 1
    You can change the style of output when and wherever \tikset can be issued (which is pretty much anywhere). So if you say, between the two tikzpictures: \tikzset{output/.style={node distance=2cm}} it will change from there afterwards. You can also use the optional part of the tikzpicture to this. Commented Nov 9, 2016 at 9:44

1 Answer 1

1

TikZ styles can be created/changed in the middle of the document using either \tikzset or even through the optional argument of tikzpicture the same way it was created beforehand.

So if you want the just the second picture to have a node distance of 2cm, you can just change the output style in that picture using either \tikzset inside the tikzpicture environment or the optional part of the Environment, those are both local changes.

If you want to change the setting of output globally, then use \tikzset outside of the tikzpicture, then all pictures after issuing \tikzset will inherit the style settings.

See this MWE as an example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{arrows,calc,positioning}

\tikzset{
    block/.style = {draw, rectangle,
                    minimum height=1cm,
                    minimum width=2cm},
    input/.style = {coordinate,node distance=1cm},
    output/.style = {coordinate,node distance=1cm},
    arrow/.style={draw, -latex,node distance=2cm},
    pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
    sum/.style = {draw, circle, node distance=1cm}
}

\begin{document}

    \begin{figure}[ht]
        \begin{center}
            \begin{tikzpicture}[auto, node distance=1cm,>=latex']
            \node [input, name=input] {$U(s)$};
            \node [block, right=of input] (controller) {$C(s)$};
            \node [block, right=of controller] (plant) {$G(s)$};
            \node [output, right=of plant] (output) {};
            \draw [->] (input) -- node {$U(s)$} (controller);
            \draw [->] (controller) -- (plant);
            \draw [->] (plant) -- node [name = y] {$Y(s)$} (output);
            \end{tikzpicture}

%           \tikzset{output/.style = {node distance=2cm}} %<< global change (uncomment to see the difference)

            \begin{tikzpicture}[auto,
                                node distance=1cm,
                                >=latex',
                                output/.style = {node distance=2cm}] % << local change
            \tikzset{output/.style = {node distance=2cm}} %<< also local change
            \node [input, name=input] {};
            \node [sum, right=of input] (sum) {};
            \node [block, right=of sum] (controller) {$C(s)$};
            \node [block, right=2 of controller] (plant) {$G(s)$};
            \node [output, right=of plant] (output) {};
            \draw [draw,->] (input) -- node {$U(s)$} (sum);
            \draw [->] (sum) -- node {} (controller);
            \draw [->] (controller) -- node {} (plant);
            \draw [->] (plant) -- node [name=y] {$Y(s)$}(output);
            \draw [->] (y) -- ++ (0,-2) -| node [pos=0.99] {$-$} (sum);
            \end{tikzpicture}

            \begin{tikzpicture}[auto, node distance=1cm,>=latex']
            \node [input, name=input] {$U(s)$};
            \node [block, right=of input] (controller) {$C(s)$};
            \node [block, right=of controller] (plant) {$G(s)$};
            \node [output, right=of plant] (output) {};
            \draw [->] (input) -- node {$U(s)$} (controller);
            \draw [->] (controller) -- (plant);
            \draw [->] (plant) -- node [name = y] {$Y(s)$} (output);
            \end{tikzpicture} 
        \end{center}
        \caption{TikzPicture}\label{fig}
    \end{figure}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .