我使用模板在 Latex 中创建用例(模板信息)。它通常看起来是这样的:
使用它的乳胶源如下所示:
\begin{usecase}
\addtitle{test text to show the rowcolor}
\addfield{user:}{test}
\addfield{conditions:}{test}
\addscenario{secnario}{
\item test
}
\addfield{result:}{test}
\end{usecase}
我想更改标题和结果字段的背景颜色。为了实现这一点,我编辑了模板:
% Initial source for the title
\newcommand\addtitle[1]{ \hline \\ [-1.5ex] \multicolumn{2}{p{15cm}}{\textbf{#1}}\\ [1ex] \hline \\ [-1.5ex]}
% Modified to add color to the title
\newcommand\addtitle[1]{ \hline \\ [-1.5ex] \rowcolor{Gray} \multicolumn{2}{p{15cm}}{\textbf{#1}}\\ [1ex] \hline \\ [-1.5ex]}
%
% Initial Source to add a filed
\newcommand\addfield[2]{\textit{#1} \\ [1ex] \hline \\ [-1.3ex] }
% New command for the result, same as addfield but with color
\newcommand\addresult[2]{ \rowcolor{Gray} \textit{#1} \\ [1ex] \hline \\ [-1.3ex] }
这将创建以下输出:
我该如何更改模板才能使整个宽度和高度都有彩色背景?
这是可编译的示例:
\documentclass[12pt,DIV14,BCOR10mm,a4paper,parskip=half-,headsepline,headinclude]{scrreprt}
\usepackage[headsepline,headinclude,automark]{scrpage2}
\usepackage{color, colortbl}
\usepackage{usecases}
\definecolor{Gray}{rgb}{0.8,0.8,0.8}
\begin{document}
\chapter{UseCaseTest}
\the\textwidth
\begin{usecase}
\addtitle{test text to show the rowcolor}
\addfield{user:}{test}
\addfield{conditions:}{test}
\addscenario{scenario}{
\item test
}
\addresult{result:}{test}
\end{usecase}
\end{document}
输出结果如下:
提前致谢
答案1
这可能会帮助你朝着正确的方向努力
平均能量损失
\documentclass{article}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\definecolor{TopRow}{rgb}{0.4,0.7,1}
\definecolor{NormalRow}{rgb}{0.8,0.9,1}
\newcommand\addrow[2]{#1 \\ }
\newcommand\addheading[2]{#1 \\ \hline}
\newcommand\tabularhead{\begin{tabular}{lp{8cm}}\rowcolor{TopRow}
\hline
}
\newcommand\addmulrow[2]{ \begin{minipage}[t][][t]{2.5cm}#1\end{minipage}%
&\begin{minipage}[t][][t]{8cm}
\begin{enumerate} #2 \end{enumerate}
\end{minipage}\\ }
\newenvironment{usecase}{\tabularhead}
{\hline\end{tabular}}
\begin{document}
% Initial Source to add a filed
\newcommand\addfield[2]{\textit{#1} \\ [1ex] \hline \\ [-1.3ex] }
% New command for the result, same as addfield but with color
\newcommand\addresult[2]{\rowcolor{NormalRow}\textit{#1} & #2\\ [1ex] \hline \\
[-1.3ex] }
\begin{usecase}
\addheading{test text to show the rowcolor}{}
\addfield{user:}{test}
\addfield{conditions:}{test}
\addmulrow{scenario}{
\item test
}
\addresult{result:}{test}
\end{usecase}
\end{document}