Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to write a tex code that output a table like below:

enter image description here

I wrote the following code:

    \newcounter{NumberReqF}
    \newcommand{\ReqF}{\stepcounter{NumberReqF}\theNumberReqF ~- }
    \newcounter{NumberReqNF}[NumberReqF]
    \newcommand{\ReqNF}{\stepcounter{NumberReqNF}\theNumberReqF .\theNumberReqNF ~- }

        \setcounter{NumberReqF}{0}
        \setcounter{NumberReqNF}{0}
        \noindent \begin{table}[h!]
            \begin{tabular}{|p{0.40\columnwidth}|p{0.15\columnwidth}|p{0.15\columnwidth}|c|c|}
                \hline 
                \multicolumn{3}{|p{0.70\columnwidth}|}{\ReqF Requisito Funcional} & \multicolumn{2}{p{0.30\columnwidth}|}{Oculto ()}\tabularnewline
                \hline 
                \multicolumn{5}{|p{\columnwidth}|}{Aqui vai a descrição do requisito funcional, falando como ele funciona e tal mais algo. Pra testa o espaço vo coloca mais esse text pra que veja como a tabela se comporta}\tabularnewline
                \hline 
                \multicolumn{5}{|p{\columnwidth}|}{\centering Requisitos Não-Funcionais}\tabularnewline
                \hline 
                Nome & Restrição & Categoria & Desejável & \multicolumn{1}{c|}{Permanente}\tabularnewline
                \hline 
                \ReqNF nome do resquisito não-funcional &  &  &  & \multicolumn{1}{c|}{}\tabularnewline
                \hline 
                \ReqNF nome do resquisito não-funcional &  &  &  & \multicolumn{1}{c|}{}\tabularnewline
                \hline
            \end{tabular}
        \end{table}

it outputs:

enter image description here

But the code is so complex How could I improve it? Making it easy to read, write new rows. I intend to add many table like it. I was thinking about create a new command also but I have no idea how.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

First some general notes:

Try to avoid doing this [h!] even with the ! it restricts the places where latex can place the float.

Don't put \noindent before the \begin{table} it needs to go (if anywhere) before \begin{tabular}

Your table was overfull and generated warnings \columnwidth Overfull \hbox (47.99474pt too wide) because it had full width entries which were then surrounded by rules and inter-column space, so making it wider than full width.

Several entries I suspect can be one line so use \multicolumn{1}{c|} rather than p columns

the last column is c already but you had several entries \multicolumn{1}{c|} resetting it to c.

In the following I have used the tabularx package to do some of the width calcuations, and the calc package to make taking account of the array rules easier.

Maybe something like this:

\documentclass{article}
\usepackage[latin1]{inputenc}
 \newcounter{NumberReqF}
    \newcommand{\ReqF}{\stepcounter{NumberReqF}\theNumberReqF ~- }
    \newcounter{NumberReqNF}[NumberReqF]
    \newcommand{\ReqNF}{\stepcounter{NumberReqNF}\theNumberReqF .\theNumberReqNF ~- }

        \setcounter{NumberReqF}{0}
        \setcounter{NumberReqNF}{0}

\usepackage{tabularx,calc}
\newcolumntype{Y}[1]{>{\setlength\hsize{#1\hsize}%
                       \raggedright\arraybackslash}X}
\newcolumntype{F}{|p{\columnwidth-2\tabcolsep-2\arrayrulewidth}|}
\setlength\extrarowheight{2pt}

\begin{document}

\begin{table}
\noindent\begin{tabularx}{\columnwidth}{|Y{0.5}|Y{0.25}|Y{0.25}|c|c|}
                \hline 
                \multicolumn{3}{|l|}{\ReqF Requisito Funcional} & \multicolumn{2}{l|}{Oculto ()}\tabularnewline
                \hline 
                \multicolumn{5}{F}{Aqui vai a descrição do requisito funcional, falando como ele funciona e tal mais algo. Pra testa o espaço vo coloca mais esse text pra que veja como a tabela se comporta}\tabularnewline
                \hline 
                \multicolumn{5}{|c|}{Requisitos Não-Funcionais}\tabularnewline
                \hline 
                Nome & Restrição & Categoria & Desejável & Permanente\tabularnewline
                \hline 
                \ReqNF nome do resquisito não-funcional &  &  &  & \tabularnewline
                \hline 
                \ReqNF nome do resquisito não-funcional &  &  &  &\tabularnewline
                \hline
            \end{tabularx}
        \end{table}


\end{document}
share|improve this answer
    
Thank you for the tips :D –  Rafael Mar 26 '12 at 20:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.