I want my two tables to look like in the example below, except I would like to get rid of the first row(s) (1 to 8
). Both tables should have the same width and all fields should span the given number of columns, e.g. Version
should be 1/8th of the total table. Without the first row, the width of all fields seems to be random, e.g. Options
to Paddings
is roughly 2:6 and not 6:2.
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{figure}
\centering
\begin{tabular}{|p{0.0925\textwidth}|p{0.0925\textwidth}|p{0.0925\textwidth}|p{0.0925\textwidth}|p{0.0925\textwidth}|p{0.0925\textwidth}|p{0.0925\textwidth}|p{0.0925\textwidth}|}
\hline
\centering{1} & \centering{2} & \centering{3} & \centering{4} & \centering{5} & \centering{6} & \centering{7} & \centering{8}\tabularnewline
\hline
Version & \multicolumn{2}{c|}{Traffic Class} & \multicolumn{5}{c|}{Flow Label}\tabularnewline
\hline
\multicolumn{4}{|c|}{Payload Length} & \multicolumn{2}{c|}{Next Header} & \multicolumn{2}{c|}{Hop Limit} \tabularnewline
\hline
\multicolumn{8}{|c|}{\multirow{4}{*}{Source Address}}\tabularnewline
\multicolumn{8}{|c|}{}\tabularnewline
\multicolumn{8}{|c|}{}\tabularnewline
\multicolumn{8}{|c|}{}\tabularnewline
\hline
\multicolumn{8}{|c|}{\multirow{4}{*}{Destination Address}}\tabularnewline
\multicolumn{8}{|c|}{}\tabularnewline
\multicolumn{8}{|c|}{}\tabularnewline
\multicolumn{8}{|c|}{}\tabularnewline
\hline
\end{tabular}
\caption{IPv6: Header Format}
\label{fig:ipv6_header}
\end{figure}
\begin{figure}
\centering{}
\begin{tabular}{|p{0.0925\textwidth}|p{0.0925\textwidth}|p{0.0925\textwidth}|p{0.0925\textwidth}|p{0.0925\textwidth}|p{0.0925\textwidth}|p{0.0925\textwidth}|p{0.0925\textwidth}|}
\hline
\centering{1} & \centering{2} & \centering{3} & \centering{4} & \centering{5} & \centering{6} & \centering{7} & \centering{8}\tabularnewline
\hline
Version & \centering{}IHL & \multicolumn{2}{c|}{Type of Service} & \multicolumn{4}{c|}{Total Length}\tabularnewline
\hline
\multicolumn{4}{|c|}{Identification} & Flags & \multicolumn{3}{c|}{Fragment Offset}\tabularnewline
\hline
\multicolumn{2}{|c|}{Time to Live} & \multicolumn{2}{c|}{Protocol} & \multicolumn{4}{c|}{Header Checksum}\tabularnewline
\hline
\multicolumn{8}{|c|}{Source Address}\tabularnewline
\hline
\multicolumn{8}{|c|}{Destination Address}\tabularnewline
\hline
\multicolumn{6}{|c|}{Options} & \multicolumn{2}{c|}{Padding}\tabularnewline
\hline
\end{tabular}
\caption{IPv4: Header Format}
\label{fig:ipv4_header}
\end{figure}
\end{document}
Update:
I switched to tabularx
and resizebox
so it's easier to control the size of the table. Issue remains though, as soon as I remove the first row(s), the fields don't have the correct width anymore.
\documentclass[draft]{article}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{tabularx}
\begin{document}
\begin{figure}
\centering{}
\resizebox{0.8\textwidth}{!}{%
\begin{tabularx}{\textwidth}{|*{8}{X|}}
\hline
\centering{1} & \centering{2} & \centering{3} & \centering{4} & \centering{5} & \centering{6} & \centering{7} & \centering{8}\tabularnewline
\hline
\centering{Version} & \centering{IHL} & \multicolumn{2}{c|}{Type of Service} & \multicolumn{4}{c|}{Total Length}\tabularnewline
\hline
\multicolumn{4}{|c|}{Identification} & Flags & \multicolumn{3}{c|}{Fragment Offset}\tabularnewline
\hline
\multicolumn{2}{|c|}{Time to Live} & \multicolumn{2}{c|}{Protocol} & \multicolumn{4}{c|}{Header Checksum}\tabularnewline
\hline
\multicolumn{8}{|c|}{Source Address}\tabularnewline
\hline
\multicolumn{8}{|c|}{Destination Address}\tabularnewline
\hline
\multicolumn{6}{|c|}{Options} & \multicolumn{2}{c|}{Padding}\tabularnewline
\hline
\end{tabularx}}
\caption{IPv4: Header Format}
\label{fig:ipv4_header}
\end{figure}
\begin{figure}
\centering{}
\resizebox{0.8\textwidth}{!}{%
\begin{tabularx}{\textwidth}{|*{8}{X|}}
\hline
\centering{1} & \centering{2} & \centering{3} & \centering{4} & \centering{5} & \centering{6} & \centering{7} & \centering{8}\tabularnewline
\hline
\centering{Version} & \multicolumn{2}{c|}{Traffic Class} & \multicolumn{5}{c|}{Flow Label}\tabularnewline
\hline
\multicolumn{4}{|c|}{Payload Length} & \multicolumn{2}{c|}{Next Header} & \multicolumn{2}{c|}{Hop Limit} \tabularnewline
\hline
\multicolumn{8}{|c|}{\multirow{4}{*}{Source Address}}\tabularnewline
\multicolumn{8}{|c|}{}\tabularnewline
\multicolumn{8}{|c|}{}\tabularnewline
\multicolumn{8}{|c|}{}\tabularnewline
\hline
\multicolumn{8}{|c|}{\multirow{4}{*}{Destination Address}}\tabularnewline
\multicolumn{8}{|c|}{}\tabularnewline
\multicolumn{8}{|c|}{}\tabularnewline
\multicolumn{8}{|c|}{}\tabularnewline
\hline
\end{tabularx}}
\caption{IPv6: Header Format}
\label{fig:ipv6_header}
\end{figure}
\end{document}
Best Answer
If you look, for example, at your first table, you can notice that the cells in the second column are always under the scope of
\multicolumn
. Thus TeX has no way of using the column specification.You probably want to use the
bytefield
package; the translation is rather easy.In the first diagram I used a
\bitheader
line, comment it out if you don't want it.