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 want to make the three square box and simply connect them. enter image description here

share|improve this question

5 Answers 5

Below I present three possibilities

  • Using basic boxes: \parboxes and \fbox (without color) or \fcolorbox (with color) nad \hline.

  • Using tikz and chains.

  • Drawing the diagram as a tree with forest.

The code

  1. A TikZ-free solution:

    \documentclass{article}
    \usepackage{amsmath}
    
    \newcommand\MBox[2][2em]{%
     \fbox{\parbox[c][2em][c]{#1}{\centering#2}%
     }%
    }
    \newcommand*{\MRule}{$\vcenter{\hrule width 1cm}$}
    
    \begin{document}
    
    \MBox{$g(t)$}\MRule\MBox[4em]{System}\MRule\MBox{$y(t)$}
    
    \end{document}
    

    enter image description here

    With some colors (still no TikZ):

    \documentclass{article}
    \usepackage{xcolor}
    \usepackage{amsmath}
    
    \newcommand\MBox[3][2em]{%
     \fcolorbox{black}{#3}{\parbox[c][2em][c]{#1}{\centering#2}%
     }%
    }
    \newcommand*{\MRule}{$\vcenter{\hrule width 1cm}$}
    
    \begin{document}
    
    \MBox{$g(t)$}{red!70!black!30}\MRule\MBox[4em]{System}{cyan!50}\MRule\MBox{$y(t)$}{red!70!black!30}
    
    \end{document}
    

enter image description here

  1. A TikZ solution using chains:

    \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{chains}
    
    \begin{document}
    
    \begin{tikzpicture}[
    mbox/.style={
      draw,
      text width=#1,
      align=center,
      minimum height=3em,
      join
      },
      start chain=going right,
      every join/.style=-
    ]
    \node[mbox=2em,on chain] {$g(t)$};
    \node[mbox=3.5em,on chain] {System};
    \node[mbox=2em,on chain] {$y(t)$};
    \end{tikzpicture}
    
    \end{document}
    

    enter image description here

    A colorful approach:

    \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{chains}
    
    \begin{document}
    
    \begin{tikzpicture}[
    mbox/.style={
      draw,
      text width=#1,
      align=center,
      rounded corners,
      minimum height=3em,
      join,
      line width=0.8pt
      },
      start chain=going right,
      every join/.style=-
    ]
    \node[mbox=2em,on chain,fill=red!70!black!30] {$g(t)$};
    \node[mbox=3.5em,on chain,fill=cyan!50] {System};
    \node[mbox=2em,on chain,fill=red!70!black!30] {$y(t)$};
    \end{tikzpicture}
    
    \end{document}
    

    enter image description here

  2. As a tree, with forest:

    \documentclass{article}
    \usepackage{forest}
    
    \begin{document}
    
    \begin{forest}
    for tree={draw,nodes={align=center},grow=east}
    [$g(t)$,fill=red!60!black!30 [System,fill=cyan!30 [$y(t)$,fill=red!60!black!30 ] ] ]
    \end{forest}
    
    \end{document}
    

    enter image description here

share|improve this answer
    
Addition: The rule can also be placed on the math axis: \newcommand*{\MRule}{$\vcenter{\hrule width 1cm}$} –  Heiko Oberdiek Jun 23 at 16:11
    
@HeikoOberdiek Ah, thanks. I updated the answer. –  Gonzalo Medina Jun 23 at 16:11
    
@GonzaloMedina it is possible to make this diagram fancy and colorful, because I will used it in the beamer –  Micky K Jun 23 at 16:15
    
@MickyK Of course! See my updated answer. –  Gonzalo Medina Jun 23 at 16:18
    
@GonzaloMedina facing error illegal parameter umber in definition of \end{tikzpicture} –  Micky K Jun 23 at 16:23

You can draw this with TikZ as well. Drawing large block diagrams with TikZ is fairly straightforward, moreso than using LaTeX native structures.

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}


\begin{document}
    \begin{tikzpicture}
        \node (g) [draw, minimum width = 2cm, minimum height=1.2 cm] {$g(t)$};
        \node (system) [draw, minimum width = 3cm, minimum height=1.2 cm] at ($ (g) + (5cm, 0)$) {System};
        \node (y) [draw, minimum width = 2cm, minimum height=1.2 cm] at ($ (system) + (5cm, 0)$) {$y(t)$};

        \draw [->] (g.east) -- (system.west);
        \draw [->] (system.east) -- (y.west);
    \end{tikzpicture}
\end{document}

The above code gives the following output:

simple block diagram

share|improve this answer

One line TikZ solution :

\documentclass[tikz,border=7mm]{standalone}
\usetikzlibrary{graphs}
\begin{document}
  \tikz\graph[nodes=draw, grow right=14mm] { "$g(t)$" -- "System" -- "$y(t)$"};
\end{document}

enter image description here

share|improve this answer
    
want to make it fancy in one line solution, because I want to use in beamer –  Micky K Jun 23 at 16:31
    
@MickyK no problem : add nodes={draw,cloud} (but don't forget shapes.symbols library) ;) –  Kpym Jun 23 at 16:36

A MetaPost solution, for whom it may interest:

input boxes
beginfig(1);
  boxjoin(b.w - a.e = (3cm, 0));
  boxit.g(btex $g(t)$ etex);
  boxit.sys(btex System etex);
  boxit.y(btex $y(t)$ etex);
  defaultdx := .75cm;
  defaultdy := .5cm;
  drawboxed(g, sys, y);
  drawarrow g.e -- sys.w; drawarrow sys.e --  y.w;
endfig;
end.

enter image description here

share|improve this answer

With :

% arara: pdflatex

\documentclass{article}
\usepackage{tikz-cd}
\usepackage{mathtools}

\begin{document}
\[
\begin{tikzcd}[%
    ,every arrow/.append style=dash
    ,cells={%
        nodes={%
            ,draw
            ,minimum width = 1.45cm % optional if you want squares
            ,minimum height= 1.45cm % optional if you want squares
            %,rounded corners % if you need it fancy...
            %,fill=blue!50 % if you need it fancy...
            }
        }
    ]
g(t) \rar & \text{System} \rar & y(t)
\end{tikzcd}
\]  
\end{document}

enter image description here

share|improve this answer

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.