我的代码在 net 和 SO help 的帮助下运行。但现在我想使用宏来简化它。我不懂宏,但人们说它使代码更简化。
有人能指导我如何制作这个宏吗?如何使用它定义?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\setlength\parindent{0pt}
\usepackage{xcolor}
\usepackage{setspace}
\begin{document}
\colorbox{black}{\makebox[\dimexpr\linewidth-2\fboxsep]{\color{white}\textbf {User schema}}}
\[
\text{Users} \left\{ \begin{tabular}{@{}p{.8\linewidth}@{}}
\textbf{ID}: \textcolor{red}{ObjectId} -- Id do registro \\
\textbf{Name}: \textcolor{red}{String} -- Name co usuario \\
\textbf{date}: \textcolor{red}{Date} -- Date de Cadastro \\
\textbf{ren\_date}: \textcolor{red}{Date} -- Data de \\
\textbf{email}: \parbox[t]{.9\linewidth}{\raggedright\textcolor{red}{String} -- Lorem ipsum dolorsitamet, consecteturadipisicingelit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minimveniam, exercitationullamcolaborisnisi ut
aliquipexeacommodoconsequat. Duisautereprehenderit in voluptatevelit esse cillumdolore eu fugiatnullapariatur. Occaecatcupidatat
non proident, sunt in culpa quiofficiadeseruntmollit.\strut} \\
\textbf{accesslog}: \textcolor{red}{Array} \begin{tabular}[t]{@{\ }|l@{}}
\strut \\[-\normalbaselineskip]
$\left\{\begin{tabular}{p{.7\linewidth}}
\textbf{date}: \textcolor{red}{string} Data -- da ocorrncia. \\
\textbf{user}: \textcolor{red}{ObjectId} -- que executou. \\
\textbf{action}: \textcolor{red}{String} -- Aço Executada. \\
\end{tabular}\right.\kern-\nulldelimiterspace$ \\
$\left\{\begin{tabular}{p{.7\linewidth}}
\textbf{date}: \textcolor{red}{string} Data -- da ocorrncia. \\
\textbf{user}: \textcolor{red}{ObjectId} -- que executou. \\
\textbf{action}: \textcolor{red}{String} -- Aço Executada. \\
\end{tabular}\right.\kern-\nulldelimiterspace$
\end{tabular}
\\
\textcolor{blue} {\hyperlink{page.2}{\textbf {group\_id : }}} \textcolor{red}{ ObjectId } - Id do grupo.
\end{tabular}\right.\kern-\nulldelimiterspace
\]
答案1
您可以在宏定义和新环境中隐藏重复的复杂代码。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{xcolor}
\usepackage{setspace}
\usepackage{hyperref}
\setlength\parindent{0pt}
\newenvironment{bracedtabular}
{$\left\{\begin{tabular}}
{\end{tabular}\right.\kern-\nulldelimiterspace$}
\newenvironment{lineditems}
{\begin{tabular}[t]{@{}|l@{}}\\[-\normalbaselineskip]}
{\end{tabular}\vspace{3pt}}
\newcommand{\group}[2][.]{\textcolor{#1}{\bfseries#2}}
\newcommand{\key}[1]{\textcolor{red}{#1}}
\newcommand{\longitem}[2][.9\linewidth]{\parbox[t]{#1}{\raggedright#2\unskip\strut}}
\newcommand{\header}[1]{%
\colorbox{black}{%
\makebox[\dimexpr\linewidth-2\fboxsep]{\color{white}\bfseries#1}%
}%
}
\begin{document}
\begin{center}
\header{User schema}
\medskip
\text{Users}
\begin{bracedtabular}{@{}p{.8\linewidth}@{}}
\group{ID}:
\key{ObjectId} -- Id do registro \\
\group{Name}:
\key{String} -- Name co usuario \\
\group{date}:
\key{Date} -- Date de Cadastro \\
\group{ren\_date}:
\key{Date} -- Data de \\
\group{email}:
\longitem{
\key{String} -- Lorem ipsum dolorsitamet, consecteturadipisicingelit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minimveniam, exercitationullamcolaborisnisi ut aliquipexeacommodoconsequat.
Duisautereprehenderit in voluptatevelit esse cillumdolore eu fugiatnullapariatur.
Occaecatcupidatat non proident, sunt in culpa quiofficiadeseruntmollit.
} \\
\group{accesslog}:
\key{Array}
\begin{lineditems}
\begin{bracedtabular}{@{}p{.7\linewidth}}
\group{date}:
\key{string} Data -- da ocorrncia. \\
\group{user}:
\key{ObjectId} -- que executou. \\
\group{action}:
\key{String} -- Aço Executada. \\
\end{bracedtabular} \\
\begin{bracedtabular}{@{}p{.7\linewidth}}
\group{date}:
\key{string} Data -- da ocorrncia. \\
\group{user}:
\key{ObjectId} -- que executou. \\
\group{action}:
\key{String} -- Aço Executada. \\
\end{bracedtabular} \\
\end{lineditems}
\group[blue]{\hyperlink{page.2}{group\_id:}}
\key{ObjectId} - Id do grupo.
\end{bracedtabular}
\end{center}
\end{document}