您能否指点一下如何在 latex 中创建下图?这是描述以方框为中心的双方协议的情况。它就像一个 3X4 表,但我在对齐方面遇到了困难。Tikz 是绘制此图的唯一方法吗?
答案1
添加新的浮点或标题类型(本例中为“Scheme”)的简单方法是使用newfloat
属于caption
捆绑包的包。还有一个float
包也提供(for:place really Here!)。可以使用或更简单的包H
来制作框。\fbox{\begin{minipage}{<width>}..\end{minipage}}
adjustbox
tabular
如果您想要与 PDF 相同的格式,则最好使用 来制作实际内容。
\documentclass{article}
\usepackage{float}
\usepackage{newfloat}
\DeclareFloatingEnvironment[
fileext=los,
listname=List of Schemes,
name=Scheme,
placement=H,
within=section,
]{scheme}
\usepackage{adjustbox}
\usepackage{blindtext}
\begin{document}
\section{Test}
\blindtext
\begin{scheme}
\begin{adjustbox}{minipage=.6\linewidth,fbox,center}
\begin{tabular}{rl}
\bfseries Encryption: & .... \\
& .... \\
\bfseries Deccryption: & .... \\
& .... \\
something & .... \\
& .... \\
\end{tabular}
\end{adjustbox}
\caption{Some scheme}
\end{scheme}
\blindtext
\end{document}
或者,使用adjustbox
v0.9 于 2012/05/16 开始(可在 CTAN 和在 Bitbucket.org):
\documentclass{article}
\usepackage{newfloat}
\DeclareFloatingEnvironment[
fileext=los,
listname=List of Schemes,
name=Scheme,
within=section,
]{scheme}
\usepackage{adjustbox}[2012/05/16]
\usepackage{blindtext}
\begin{document}
\listofschemes
\section{Test}
\blindtext
\begin{adjustbox}{tabular={rp{.4\linewidth}},fbox,center,caption={Some scheme},nofloat=scheme}
\bfseries Encryption: & .... \\
& .... \\
\bfseries Deccryption: & .... \\
& .... \\
something & .... \\
& .... \\
\end{adjustbox}
\blindtext
\end{document}
如果您希望方案浮动,请将 更改为nofloat
。当然,如果您更频繁地需要它,您可以为此创建一个新环境。float
\newenvironment{xscheme}{\adjustbox{tabular={rp{.4\linewidth}},fbox,center,caption={Some scheme},nofloat=scheme}\bgroup}{\egroup}
不要调用它,scheme
因为该环境是内部使用的。
答案2
我还对创建协议流程图(也称为梯形图或序列图)感兴趣。我发现这个最接近我想要的:
http://www.texample.net/tikz/examples/sequence-diagram/
但它太复杂了,代码也太丑了。下面是我尝试的一种更简单的形式:
% Agents
\def\Client {Client}
\def\MasterController{Master Controller}
\def\FeatureCtlr {Feature Controller}
% Drawing centred nodes macro.
\newcommand{\nd}{\node(0, 0)}
% Diagram
\begin{tikzpicture}[every node/.style={font=\normalsize,
minimum height=0.5cm,
minimum width=0.5cm}]
% Matrix
\node[matrix, very thin, column sep=1.3cm, row sep=0.5cm](matrix) at (0,0)
{
\nd (\Client) {}; & & \nd (\MasterController) {}; & & \nd (\FeatureCtlr) {}; \\
\nd (\Client 0) {}; & & \nd (\MasterController 0) {}; & & \nd (\FeatureCtlr 0) {}; \\
\nd (\Client 1) {}; & \nd {}; & \nd (\MasterController 1) {}; & & \nd (\FeatureCtlr 1) {}; \\
\nd (\Client 2) {}; & \nd {}; & \nd (\MasterController 2) {}; & & \nd (\FeatureCtlr 2) {}; \\
\nd (\Client 3) {}; & & \nd (\MasterController 3) {}; & \nd {}; & \nd (\FeatureCtlr 3) {}; \\
\nd (\Client 4) {}; & \nd {}; & \nd (\MasterController 4) {}; & & \nd (\FeatureCtlr 4) {}; \\
\nd (\Client 5) {}; & \nd {}; & \nd (\MasterController 5) {}; & & \nd (\FeatureCtlr 5) {}; \\
\nd (\Client 6) {}; & & \nd (\MasterController 6) {}; & \nd {}; & \nd (\FeatureCtlr 6) {}; \\
};
% Agents labels
\fill
(\Client) node[draw,fill=white] {\Client}
(\MasterController) node[draw,fill=white] {\MasterController}
(\FeatureCtlr) node[draw,fill=white] {\FeatureCtlr};
% Vertical lifelines
\draw [dotted]
(\Client) -- (\Client 6)
(\MasterController) -- (\MasterController 6)
(\FeatureCtlr) -- (\FeatureCtlr 6);
% Blocks (Budget constraints)
\filldraw[fill=black!17]
(\Client 0.north west) rectangle (\Client 5.south east)
(\MasterController 0.north west) rectangle (\MasterController 3.south east)
(\FeatureCtlr 1.north west) rectangle (\FeatureCtlr 2.south east)
(\FeatureCtlr 4.north west) rectangle (\FeatureCtlr 5.south east);
% Horizontal flows (inter-process).
\draw [-latex] (\Client 0) -- node [midway,above]{$request$} (\MasterController 0);
\draw [-latex] (\MasterController 1) -- node [midway,above]{$validate$} (\FeatureCtlr 1);
\draw [-latex,dashed] (\FeatureCtlr 2) -- (\MasterController 2);
\draw [-latex,dashed] (\MasterController 3) -- (\Client 3);
\draw [-latex] (\Client 4) -- node [midway,above]{$access$} (\FeatureCtlr 4);
\draw [-latex,dashed] (\FeatureCtlr 5) -- (\Client 5);
\end{tikzpicture}