我想像图片一样显示我的内容。我已考虑使用数组。请告诉我是否有更好的选择。
\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}