3

Below is the code for a chart that I created using LaTeX. I am creating use cases for my program, and there are 117 use cases that I need to create. It would be possible to use the below code, but it will be really tedious to fill in the information for each, between all the code.

My question, is there a better way to have the default layout of my chart the same as below but somehow creating my own tabular function with these specficaitons. So then I can just insert the information and not worry about getting all lost in the code. This is my first big project (300+ pages), with LaTeX, its a really cool documenting program, much better then Microsoft!!

enter image description here

Thanks in advanced!

\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}

2 Answers2

5

I think your problem is colouring even and odd rows as suggested by Chris in the comments. For this, one need not input row colours in every row. xcolor provides the macro \rowcolors{<starting row>}{<OddColor>}{<EvenColor>} Here is a screen shot from xcolor manual (page 4)

enter image description here

Another screen shot from section 2.12 (page 28) gives more details.

enter image description here

Further there is an example in page 35, Figure 10.

Applying all these to your example will be:

\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}

enter image description here

What I changed?

  1. Removed \rowcolor{lightgray} from all rows and added \rowcolors{1}{lightgray}{white}
  2. The first row color is over ruled by retaining \rowcolor{orange!90}\textcolor{white}
  3. Added @{} to the inner table so that they align.
1

Additional to Harish Kumars Answer you can spare some typing work by including the fontseries specification in the column definition.

\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}
Troy
  • 13,741
schmendrich
  • 3,908