我想制作三个方框并简单地将它们连接起来。
答案1
下面我提出三种可能性
代码
不含 TikZ 的解决方案:
\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}
有一些颜色(仍然没有 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}
使用链的 TikZ 解决方案:
\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}
一种丰富多彩的方法:
\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}
作为一棵树,具有
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}
答案2
您也可以使用 TikZ 绘制此图。使用 TikZ 绘制大型框图相当简单,比使用 LaTeX 原生结构更简单。
\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}
上述代码给出以下输出:
答案3
一行 TikZ 解决方案:
\documentclass[tikz,border=7mm]{standalone}
\usetikzlibrary{graphs}
\begin{document}
\tikz\graph[nodes=draw, grow right=14mm] { "$g(t)$" -- "System" -- "$y(t)$"};
\end{document}
答案4
和tikz-cd:
% 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}