Graphics, Figures & TablesTable tweaking (wrap text, ...)

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
bulbanos
Posts: 13
Joined: Fri Apr 24, 2009 10:25 pm

Table tweaking (wrap text, ...)

Post by bulbanos »

hey

as you can see in the attached screenshot I want to make a somehow basic table. I'm bound to long table headers so I obviously want them to wrap instead of pushing my table off the page. How can I do that? I tried tabularx which worked fine as long as I didn't use the multicolumn in the headers.
And second, I don't want to have the horizontal rule continuing over my text of the two left headers.
Is there anyone around with a suggestion?

Code: Select all

  \begin{table}[ht!]
   \centering
	 \begin{tabular}{|c|c||c|c|c|c|c|c|}
	 \hline 
	 \multirow{2}{*}{Modulatie} & \multirow{2}{*}{Code Rate} & \multicolumn{2}{c|}{Ogenblikkelijke data rate} & \multicolumn{2}{c|}{Data rate per frame} & \multicolumn{2}{c|}{Data rate in het datadeel van een frame} \\ \hline 
	  & & DL & UL & DL & UL & DL & UL \\ \hline \hline
	 QPSK & 1/2 CTC & 3,500 & 3,500 & 3,456 & & 3,168 & \\ \hline
	 QPSK & 3/4 CTC & 5,250 & 3,500 &5,184 & & 4,752  & \\ \hline
	 16-QAM & 1/2 CTC & 7,000 & 3,500&  6,912& &  6,336 &  \\ \hline
	 16-QAM & 3/4 CTC & 10,500 & 3,500 & 10,368&  &9,504 & \\ \hline	 	 	  
	 64-QAM & 1/2 CTC & 10,500 & 3,500 &10,368&  &9,504 & \\ \hline	 
	 64-QAM & 2/3 CTC & 14,000 & 3,500 &13,824&  &12,672&  \\ \hline	 
	 64-QAM & 3/4 CTC & 15,750 & 3,500 &15,552&  &14,256 &  \\ \hline	 
	 64-QAM & 5/6 CTC & 17,500 & 3,500 &17,280&  &15,840 & \\ \hline	 
	  	 	 
	 \hline
	 \end{tabular}
	 \caption{Verschillende downlink PHY datarates in Mbps}
	 \label{tab:phyrates}	 
 \end{table}
Attachments
table.jpg
table.jpg (41.08 KiB) Viewed 6437 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Table tweaking (wrap text, ...)

Post by localghost »

Spreading the cell contents of the table head over several lines does the trick. For better legibility abandon vertical lines. Consider the following code.

Code: Select all

\documentclass[11pt,a4paper,dutch]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[includeheadfoot,margin=2cm]{geometry}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage{booktabs,dcolumn}
\usepackage{lmodern}

\setlength{\parindent}{0pt}

% New column types for tables (dcolumn)
\newcolumntype{d}{D{,}{,}{-1}}
\newcolumntype{e}{D{,}{,}{-2}}
\newcolumntype{f}{D{,}{,}{-3}}

\begin{document}
  \begin{table}[!ht]
    \centering
    \caption{Verschillende downlink PHY datarates in Mbps}\label{tab:phyrates}
      \begin{tabular}{ccedffff} \toprule
        \multirow{2}{*}{Modulatie} & \multirow{2}{*}{Code Rate} & \multicolumn{2}{c}{Ogenblikkelijke} & \multicolumn{2}{c}{Data rate} & \multicolumn{2}{c}{Data rate in het} \\
      & & \multicolumn{2}{c}{data rate} & \multicolumn{2}{c}{per frame} &  \multicolumn{2}{c}{datadeel van een frame} \\  \cmidrule{3-8}
      & & \multicolumn{1}{c}{DL} & \multicolumn{1}{c}{UL} & \multicolumn{1}{c}{DL} & \multicolumn{1}{c}{UL} & \multicolumn{1}{c}{DL} & \multicolumn{1}{c}{UL} \\ \midrule[1pt]
      QPSK & 1/2 CTC & 3,5 & 3,5 & 3,456 & & 3,168 & \\
      QPSK & 3/4 CTC & 5,25 & 3,5 &5,184 & & 4,752  & \\
      16-QAM & 1/2 CTC & 7 & 3,5 &  6,912 & & 6,336 &  \\
      16-QAM & 3/4 CTC & 10,5 & 3,5 & 10,368 &  & 9,504 & \\
      64-QAM & 1/2 CTC & 10,5 & 3,5 & 10,368 &  & 9,504 & \\
      64-QAM & 2/3 CTC & 14 & 3,5 & 13,824 &  & 12,672&  \\
      64-QAM & 3/4 CTC & 15,75 & 3,5 & 15,552 &  & 14,256 &  \\
      64-QAM & 5/6 CTC & 17,5 & 3,5 & 17,28 &  & 15,84 & \\ \bottomrule
    \end{tabular}
  \end{table}
\end{document}
The table has been tweaked with booktabs and the values have been aligned with dcolumn. Information about the used packages can be found on CTAN.


Best regards
Thorsten¹
bulbanos
Posts: 13
Joined: Fri Apr 24, 2009 10:25 pm

Table tweaking (wrap text, ...)

Post by bulbanos »

What's the difference between the specified column types? The readme states
If this is negative, any number of decimal places can be used in the
column
And I guess a multicolumn of 1 is a trick there...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Table tweaking (wrap text, ...)

Post by localghost »

There's not really a difference. I don't remember where I got that from. More than the first declaration is not necessary. The others are superfluous. Perhaps the suggestion from the dcolumn manual is the best.

Code: Select all

\newcolumntype{d}[1]{D{,}{,}{#1}}
This lets you set up the alignment of a column more individually in the argument for the tabular environment. Your table setup would then look like this.

Code: Select all

\begin{tabular}{ccd{2.2}d{1.1}d{2.3}d{1.1}d{2.3}d{1.1}} \toprule
  % contents
\end{tabular}
The \multicoumn command indeed is a trick because the new columns are typeset in math mode. Another package that lets you align values in table cells is siunitx.
Post Reply