下面是我使用 LaTeX 创建的图表的代码。我正在为我的程序创建用例,我需要创建 117 个用例。可以使用下面的代码,但在所有代码之间填写每个用例的信息会非常繁琐。
我的问题是,有没有更好的方法可以让我的图表的默认布局与下面相同,但以某种方式使用这些规范创建我自己的表格函数。这样我就可以插入信息,而不必担心在代码中迷失一切。这是我的第一个大项目(300 多页),使用 LaTeX,它是一个非常酷的文档程序,比微软好多了!!
先谢谢了!
\begin{tabular}[!ht]{l p{10cm}}
\rowcolor{orange!90}\textcolor{white}{\textbf{Identifier/Name}} & \textcolor{white}{\textbf{UC1 - Login}} \\
\textbf{Importance} & 5/5\\
\rowcolor{lightgray}\textbf{Difficulty} & 1/5\\
\textbf{Actor(s)} & Generalized User\\
\rowcolor{lightgray}\textbf{Goal} & To allow the user to access the system.\\
\textbf{Preconditions} & The user is at the login page. \\
\rowcolor{lightgray}\textbf{Summary} & Will validate the users name and password and subsequently give them access to the system.\\
\textbf{Steps} &
{\begin{tabular}{p{4cm} | p{4cm}}
1. User provides username and password. & 2. System directs user to main system page. \\
\end{tabular}} \\
\rowcolor{lightgray}\textbf{Postcondition} & \textbf{Success:} User is logged in. \newline \textbf{Failure:} The system reamins at the login state. \\
\end{tabular}
答案1
我认为您的问题是为偶数行和奇数行着色,正如 Chris 在评论中建议的那样。为此,无需在每一行中输入行颜色。xcolor
提供宏这是手册\rowcolors{<starting row>}{<OddColor>}{<EvenColor>}
中的屏幕截图(第 4 页)xcolor
第 2.12 节(第 28 页)的另一个屏幕截图提供了更多详细信息。
第 35 页图 10 中还有一个示例。
将所有这些应用到您的示例中将是:
\documentclass{report}
\usepackage[table]{xcolor}
\definecolor{lightblue}{rgb}{0.93,0.95,1.0}
\begin{document}
\rowcolors{1}{lightgray}{white} %% <--- here
\noindent
\begin{tabular}[!ht]{l <{\raggedright}p{10cm}}
\rowcolor{orange!90}\textcolor{white}{\textbf{Identifier/Name}} & \textcolor{white}{\textbf{UC1 -
Login}} \\
\textbf{Importance} & 5/5\\
\textbf{Difficulty} & 1/5\\
\textbf{Actor(s)} & Generalized User\\
\textbf{Goal} & To allow the user to access the system.\\
\textbf{Preconditions} & The user is at the login page. \\
\textbf{Summary} & Will validate the users name and password and subsequently give them access to the
system.\\
\textbf{Steps} &
{\begin{tabular}{@{}p{4cm} | p{4cm}@{}}
1. User provides username and password. & 2. System directs user to main system page. \\
\end{tabular}} \\
\textbf{Postcondition} & \textbf{Success:} User is logged in. \newline \textbf{Failure:} The system
reamins at the login state. \\
\end{tabular}
\end{document}
我改变了什么?
\rowcolor{lightgray}
从所有行中删除并添加\rowcolors{1}{lightgray}{white}
- 第一行颜色被保留
\rowcolor{orange!90}\textcolor{white}
- 添加
@{}
到内表以便它们对齐。
答案2
除 Harish Kumars 的回答外,您还可以通过在列定义中包含字体系列规范来节省一些打字工作。
\documentclass{report}
\usepackage[table]{xcolor}
\definecolor{lightblue}{rgb}{0.93,0.95,1.0}
\begin{document}
\rowcolors{1}{lightgray}{white} %% <--- here
\noindent
\begin{tabular}[!ht]{>{\bfseries}l <{\raggedright}p{10cm}}
\rowcolor{orange!90}\textcolor{white}{Identifier/Name} & \textcolor{white}{\textbf{UC1 - Login}} \\
Importance & 5/5\\
Difficulty & 1/5\\
Actor(s) & Generalized User\\
Goal & To allow the user to access the system.\\
Preconditions & The user is at the login page. \\
Summary & Will validate the users name and password and subsequently give them access to the
system.\\
Steps &
{\begin{tabular}{@{}p{4cm} | p{4cm}@{}}
1. User provides username and password. & 2. System directs user to main system page. \\
\end{tabular}} \\
Postcondition & \textbf{Success:} User is logged in. \newline \textbf{Failure:} The system reamins at the login state. \\
\end{tabular}
\end{document}