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 want to draw a table like the attached with LaTeX. I'm using the table and tabular environmnet. My problem is how I can represent the line which goes from the begining to the end of the table at the bottom of the figure. My idea is draw a line with \multicolumn{6}{|c|}{...} but I can't obtain it, because the height is too long.

Any idea? I hope I explain my problem plainly.

enter image description here

If I use the solution that @egreg says I have another problem. I need colour some cells of another tables, so I use the code \usepackage[table]{xcolor} but it does the line shorter. The is somethin like this:

\documentclass{article}
\usepackage{amsmath,array}
\usepackage[table][hiperref]{xcolor} % Need for colour cells
\providecommand{\textsubscript}[1]{$_\textnormal{#1}$}

\begin{document}
\setlength{\extrarowheight}{2pt}
\begin{tabular}{|*6{c|}}
\multicolumn{1}{c}{1 bit}  &
\multicolumn{1}{c}{2 bits} &
\multicolumn{1}{c}{1 bit}  &
\multicolumn{1}{c}{4 bits} &
\multicolumn{1}{c}{4 bits} &
\multicolumn{1}{c}{4 bits} \\
\hline
VALIDEZ & DIVERSIFICACI\'ON &
TAMA\~NO & KDC\textsubscript{AUTH/ENC} &
KDC\textsubscript{KEK} & KDC\textsubscript{MAC} \\
\hline
\multicolumn{6}{@{}c@{}}{\vrule height 2pt depth 2pt \hrulefill \vrule     height 2pt depth 2pt} \\
\multicolumn{6}{c}{2 bytes}
\end{tabular}
\end{document}
share|improve this question
add comment

2 Answers 2

up vote 13 down vote accepted
\documentclass{article}
\usepackage{amsmath,array}
\providecommand{\textsubscript}[1]{$_\textnormal{#1}$}

\begin{document}
\setlength{\extrarowheight}{2pt}
\begin{tabular}{|*6{c|}}
\multicolumn{1}{c}{1 bit}  &
\multicolumn{1}{c}{2 bits} &
\multicolumn{1}{c}{1 bit}  &
\multicolumn{1}{c}{4 bits} &
\multicolumn{1}{c}{4 bits} &
\multicolumn{1}{c}{4 bits} \\
\hline
VALIDEZ & DIVERSIFICACI\'ON &
TAMA\~NO & KDC\textsubscript{AUTH/ENC} &
KDC\textsubscript{KEK} & KDC\textsubscript{MAC} \\
\hline
\multicolumn{6}{@{}c@{}}{\vrule height 2pt depth 2pt \hrulefill \vrule height 2pt depth 2pt} \\
\multicolumn{6}{c}{2 bytes}
\end{tabular}
\end{document}

enter image description here

A more general solution that works also when colortbl is loaded (via \usepackage[table]{xcolor}, in your case)

\documentclass{article}
\usepackage{amsmath,array}
\usepackage[table]{xcolor} % Need for colour cells

\providecommand{\textsubscript}[1]{$_\textnormal{#1}$}

\newcommand{\range}[1]{%
  \multicolumn{#1}{@{}c@{}}{%
    \vrule height 2.2pt depth 1.8pt
    \leaders\hrule\hskip 0pt plus 1filll % note the three l's
    \vrule height 2.2pt depth 1.8pt
  }%
}

\begin{document}
\setlength{\extrarowheight}{2pt}
\begin{tabular}{|*6{c|}}
\multicolumn{1}{c}{1 bit}  &
\multicolumn{1}{c}{2 bits} &
\multicolumn{1}{c}{1 bit}  &
\multicolumn{1}{c}{4 bits} &
\multicolumn{1}{c}{4 bits} &
\multicolumn{1}{c}{4 bits} \\
\hline
VALIDEZ & DIVERSIFICACI\'ON &
TAMA\~NO & KDC\textsubscript{AUTH/ENC} &
KDC\textsubscript{KEK} & KDC\textsubscript{MAC} \\
\hline
\range{6}\\
\multicolumn{6}{c}{2 bytes}
\end{tabular}
\end{document}

You can use \range{<number>} for spanning any number of columns; six, in this case.

share|improve this answer
    
Thank you, that is the perfect solution, thank you very much!! –  bra_racing Jan 17 '13 at 12:41
    
Now I've another problem. In my preamble I've the sentence `\usepackage[table,hyperref]{xcolor}´ for put colours in cells of other tables. It causes that line is shorter than I expect. There are another alternative for change the colours of the cells?? –  bra_racing Jan 17 '13 at 15:52
    
@bra_racing Difficult to say without seeing some code –  egreg Jan 17 '13 at 15:59
    
Ok, i'm sorry. Now I'm going to edit the post and put my code –  bra_racing Jan 17 '13 at 16:01
    
It works perfectly. Thank you very much –  bra_racing Jan 17 '13 at 21:24
add comment

The following provides a simple solution to the second problem and I will delete this answer if @egreg posts a better solution:

\documentclass{article}
\usepackage{amsmath,array}
\usepackage[table,hyperref]{xcolor}% % Need for colour cells

\providecommand{\textsubscript}[1]{$_\textnormal{#1}$}

\def\mytable{%
\setlength{\extrarowheight}{2pt}
\begin{tabular}{|*6{c|}}
\multicolumn{1}{c}{1 bit}  &
\multicolumn{1}{c}{2 bits} &
\multicolumn{1}{c}{1 bit}  &
\multicolumn{1}{c}{4 bits} &
\multicolumn{1}{c}{4 bits} &
\multicolumn{1}{c}{4 bits} \\
\hline
VALIDEZ & DIVERSIFICACI\'ON &
TAMA\~NO & KDC\textsubscript{AUTH/ENC} &
KDC\textsubscript{KEK} & KDC\textsubscript{MAC} \\
\hline
\end{tabular}}

\newlength{\tablewith}
\settowidth{\tablewith}{\mytable}

\begin{document}

\noindent
\setlength{\extrarowheight}{2pt}
\begin{tabular}{|*6{c|}}
\multicolumn{1}{c}{1 bit}  &
\multicolumn{1}{c}{2 bits} &
\multicolumn{1}{c}{1 bit}  &
\multicolumn{1}{c}{4 bits} &
\multicolumn{1}{c}{4 bits} &
\multicolumn{1}{c}{4 bits} \\
\hline
VALIDEZ & DIVERSIFICACI\'ON &
TAMA\~NO & KDC\textsubscript{AUTH/ENC} &
KDC\textsubscript{KEK} & KDC\textsubscript{MAC} \\
\hline
\multicolumn{6}{@{}c@{}}{\vrule height 2pt depth 2pt \rule{\tablewith}{0.4pt}\!\! \vrule height 2pt depth 2pt} \\
\multicolumn{6}{c}{2 bytes}
\end{tabular}
\end{document}

enter image description here

What I did was to get the width of your current table and use that as the rule width.

share|improve this answer
1  
Found a better one, thanks anyway. :) –  egreg Jan 17 '13 at 16:42
1  
@egreg I love your solution, very intuitive indeed. I noted the three l's. –  azetina Jan 17 '13 at 16:47
    
Now I'm in class and I can't test the solution, but I'm sure that it works. At nigth I'll say you the result. Thank you very much, the answers are very helpful –  bra_racing Jan 17 '13 at 16:49
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.