2

I want that the table fits the page, but by default the table is too wide. I already tried tabularx, but now the rows that use a multirow aren't high enough.

This is my code right now:

\begin{table}[h]
\begin{tabularx}{\textwidth}{|l|l|l|X|}
\hline
Header Field & IPv6 length & \multicolumn{1}{r|}{HC1 length} & Description \\ \hline
Version & 4 bits & \multicolumn{1}{r|}{0 bits} & Assuming IPv6 \\ \hline
Traffic Class & 8 bits & \multicolumn{1}{r|}{\multirow{2}{*}{1 bit}} & \multirow{2}{\hsize}{\parbox{\linewidth}{Traffic Class and Flow Label are compressed to a single bit when their values are both zero}} \\ \cline{1-2}
Flow Label & 20 bits & \multicolumn{1}{r|}{} & \\ \hline
Payload Length & 16 bits & 0 bits & Derived from the 802.15.4 frame or fragmentation header \\ \hline
Next Header & 8 bits & 2 bits & Compressed when packet uses UDP or TCP \\ \hline
Hop Limit & 8 bits & 8 bits & Not Compressed \\ \hline
Source Address & \multirow{2}{*}{128 bits} & \multirow{2}{*}{2 bits} & \multirow{2}{\hsize}{The 64-bit interface identifier (IID) for both source and destination addresses are removed if the destination can derive them from the corresponding link-layer address in the 802.15.4 frame or mesh header.} \\ \cline{1-1}
Destination Address & & & \\ \hline
HC2 encoding & 0 bits & 1 bit & The HC2 bit indicates if the next header is compressed using HC2. \\ \hline
\end{tabularx}
\end{table}

And this is how it looks: ShareLatex result

I use ShareLatex.

How could I fix this?

1 Answers1

4

If the \textwidth is too small, even tabularx can't provide much help.

This proposition shows different techniques of achieving the goal, but there might be better ones, of course.

I did not address the fact, that there are too much lines in the table!

\documentclass{article}

\usepackage[lmargin=1.5cm,rmargin=1.5cm]{geometry}
\usepackage{multirow}


\usepackage{tabularx}%

\begin{document}

\begin{table}[h]
\begin{tabularx}{\textwidth}{|l|l|l|X|}
\hline
Header Field & IPv6 length & \multicolumn{1}{r|}{HC1 length} & Description \\ \hline
Version & 4 bits & \multicolumn{1}{r|}{0 bits} & Assuming IPv6 \\ \hline
Traffic Class & 8 bits & \multicolumn{1}{r|}{\multirow{2}{*}{1 bit}} \tabularnewline\cline{1-2}
Flow Label & 20 bits & & \multirow{-2}{\hsize}{\parbox{\linewidth}{Traffic Class and Flow Label are compressed to a single bit when their values are both zero}} \tabularnewline 
& & & \tabularnewline
& & & \tabularnewline
\hline
Payload Length & 16 bits & 0 bits & Derived from the 802.15.4 frame or fragmentation header \\ \hline
Next Header & 8 bits & 2 bits & Compressed when packet uses UDP or TCP \\ \hline
Hop Limit & 8 bits & 8 bits & Not Compressed \\ \hline

\multirow{2}{*}{Source Address} & \multirow{5}{*}{128 bits} & \multirow{5}{*}{2 bits} & \multirow{5}{\hsize}{The 64-bit interface identifier (IID) for both source and destination addresses are removed if the destination can derive them from the corresponding link-layer address in the 802.15.4 frame or mesh header.}  \tabularnewline
& & & \tabularnewline
\cline{1-1}

\multirow{2}{*}{Destination Address} & & & \tabularnewline
& & & \tabularnewline
& & & \tabularnewline
\hline
HC2 encoding & 0 bits & 1 bit & The HC2 bit indicates if the next header is compressed using HC2. \\ \hline
\end{tabularx}
\end{table}

\end{document}

enter image description here