我怎样才能在 Latex 中创建这种连通且级联的框图?
答案1
您可以在这里指定盒子的宽度(如果太短,将会进行调整以适应)以及盒子之间的间距。
\documentclass{article}
\usepackage{keyval}
\makeatletter
\define@key{cascading}{width}{\cascading@wd=#1}
\define@key{cascading}{sep}{\def\cascading@sep{#1}}
\newdimen\cascading@wd
\newcommand{\cascadingblocks}[2][]{%
\setkeys{cascading}{sep=2ex,#1}%
\leavevmode\vbox{\offinterlineskip
\@for\next:=#2\do{%
\settowidth{\dimen@}{\next}%
\ifdim\dimen@>\cascading@wd
\cascading@wd=\dimen@
\fi
}%
\@for\next:=#2\do{%
\cascading@rule
\hbox{\fbox{\hb@xt@\cascading@wd{\hss\next\hss}}}%
}
}
}
\def\cascading@rule{%
\def\cascading@rule{%
\hb@xt@\dimexpr\cascading@wd+2\fboxsep+2\fboxrule\relax
{\hss\vrule\@height\cascading@sep\hss}%
}%
}
\makeatother
\begin{document}
% natural width, default sep
\cascadingblocks{foo,bar,foobar,foobazzzz}
% 3cm width, 3pt sep
\cascadingblocks[width=3cm,sep=3pt]{foo,bar,foobar,foobazzzz}
% 1cm width (automatically increased), default sep
\cascadingblocks[width=1cm]{foo,bar,foobar,foobazzzz}
\end{document}
答案2
\documentclass{article}
\begin{document}
\lineskip0pt
\framebox[3cm]{\strut Text1}
\makebox[3cm]{\strut\vrule}
\framebox[3cm]{\strut Text2}
\makebox[3cm]{\strut\vrule}
\framebox[3cm]{\strut Text3}
\end{document}
答案3
另一种选择是使用 TikZ 和链:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{tikzpicture}[
start chain=going below,
node distance=3mm,
every node/.style={on chain,join},
every join/.style={-},
block/.style={draw, text width=3cm,align=center}
]
\foreach \i in {1,...,5}
\node[block] {Text \i};
\end{tikzpicture}
\end{document}
答案4
使用 PSTricks。
\documentclass[preview]{standalone}
\usepackage{pst-node,multido}
\def\mybox#1{\psframebox{\makebox[3cm]{#1}}}
\begin{document}
\offinterlineskip
\psmatrix[rowsep=.5]
\mybox{A}\\
\mybox{B}\\
\mybox{C}
\endpsmatrix
\multido{\ia=1+1,\ib=2+1}{3}{\ncline{\ia,1}{\ib,1}}
\end{document}