![在数组中添加垂直线和左括号](https://linux22.com/image/292230/%E5%9C%A8%E6%95%B0%E7%BB%84%E4%B8%AD%E6%B7%BB%E5%8A%A0%E5%9E%82%E7%9B%B4%E7%BA%BF%E5%92%8C%E5%B7%A6%E6%8B%AC%E5%8F%B7.png)
我想像图片一样显示我的内容。我已考虑使用数组。请告诉我是否有更好的选择。
\textbf {accesslog : } \textcolor{red}{ Array }
\begin{tabular}{ | l c r }
date: & string & Data - da ocorrência. \\
ObjectId: & Usuário - & que executou. \\
action: & String - & Ação Executada. \\ \\
date: & string & Data - da ocorrência. \\
ObjectId: & Usuário - & que executou. \\
action: & String - & Ação Executada
\end{tabular}
目前它看起来像这样:https://www.sharelatex.com/project/53915feaeef2f99941486f56?r=380e068e&rs=ps&rm=d
内容看起来应该是这样的:
还有其他可能的方式来显示这样的内容吗?
答案1
如果我看清楚了图片,可能你不需要任何表格。
\documentclass{article}
\usepackage{color}
\def\red#1{{\color{red}#1}}
\begin{document}
$$
\left(\vcenter{
\hbox{$\left\{\
\vcenter{\parindent=0pt
\hbox{\textbf{date}: \red{string} Data -- da ocorrncia.}
\hbox{\textbf{ObjectId}: \red{Usuário} -- que executou.}
\hbox{\textbf{action}: \red{String} -- Aço Executada.}
}\right.$}
\bigskip
\hbox{$\left\{\
\vcenter{\parindent=0pt
\hbox{\textbf{date}: \red{string} Data -- da ocorrncia.}
\hbox{\textbf{ObjectId}: \red{Usuário} -- que executou.}
\hbox{\textbf{action}: \red{String} -- Aço Executada.}
}\right.$}
}\right.
$$
\end{document}
答案2
这是一个使用blkarray
包的 LaTeX 解决方案。由于您似乎声明了编程变量及其类型,因此我定义了一个\variable
命令,该命令将变量名称及其类型作为单个参数,用冒号分隔,以使语法尽可能接近自然书写。它会根据需要输入所有内容(变量名称以粗体显示,类型以红色显示),如果您忘记了类型,它只会输入变量名称。它需要包xparse
。
如果您更喜欢传统的语法,序言包含另一个\variable
带有 2 个参数的(注释的)定义。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\setlength\parindent{0pt}
\usepackage[x11names]{xcolor}
\usepackage{array}
\usepackage{mathtools}
\usepackage{blkarray}
\usepackage{xparse}
%\newcommand*\variable[2]{\textbf{#1} : \textcolor{red}{#2}}
\NewDocumentCommand{\variable}{>{\SplitArgument{1}{:}}m}
{\varargsaux#1}
\NewDocumentCommand{\varargsaux}{mm}
{\IfNoValueTF{#2}{\textbf{#1}}{\textbf{#1}{ : }\textcolor{red}{#2}}}
\def\thickvrule{\vrule width 0.9pt}
\begin{document}
\begin{tabular}{ >{\sffamily}c}
\begin{blockarray}{rcl}%
\begin{block}{>{\mbox{}}r!{\thickvrule}c@{\enspace}\{l}
\variable{accesslog : Array}
& & \variable{date : string} -- Data da ocorrência. \\
& & \variable{ObjectId : Usuário} -- que executou. \\
& & \variable{action : String} -- Ação Executada.\\
\end{block}
\begin{block}{>{\mbox{}}r!{\thickvrule}c@{\enspace}\{l}
& & \variable{date : string} -- Data da ocorrência. \\
& & \variable{ObjectId : Usuário} -- que executou. \\
& & \variable{action : String} -- Ação Executada.\\
\end{block}
\end{blockarray}
\end{tabular}
\end{document}