8

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 have explained 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 code is something 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}
0

2 Answers 2

13
\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.

4
  • Thank you, that is the perfect solution, thank you very much!!
    – bra_racing
    Jan 17, 2013 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, 2013 at 15:52
  • @bra_racing Difficult to say without seeing some code
    – egreg
    Jan 17, 2013 at 15:59
  • Ok, i'm sorry. Now I'm going to edit the post and put my code
    – bra_racing
    Jan 17, 2013 at 16:01
1

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.

2
  • 1
    @egreg I love your solution, very intuitive indeed. I noted the three l's.
    – azetina
    Jan 17, 2013 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, 2013 at 16:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .