1

I have two problems related to creating a table in LaTeX. My first problem is that I can't limit the width of my table to stop it from going out of margin. This is my code

\begin{center}
\begin{tabular}{@{}ll>{$}r<{$}@{}} \toprule
\multicolumn{2}{c}{FOFDM parameters}\\\cmidrule(r){1-2}
Parameter& Value &\textrm{Detail}\\\midrule
FOFDM\textunderscore NumberOfSubcarriers   & $24$             & Number\ of\ subcarriers\\
FOFDM\textunderscore NumberOfSymbolsInTime & $14$             & Number\ FOFDM\ symbols\ in\ time\\
FOFDM\textunderscore SubcarrierSpacing     & $15\times 10^3$  & Subcarrier\ spacing (Hz)\\
FOFDM\textunderscore CyclicPrefixLength    & $0$   & Length\ of\ the\ cyclic\ prefix\ (s)\\
FOFDM\textunderscore FilterLengthTX        & $0.2\times \frac{1}{FOFDM\textunderscore SubcarrierSpacing}$ &Length\ at\ the\ transmitter\ filter\ (s)\\ 
FOFDM\textunderscore FilterLengthRX        & $0.2\times \frac{1}{FOFDM\textunderscore SubcarrierSpacing}$ &Length\ at\ the\ receiver\ filter\ (s)\\ 
%\caption{Configuration of the simulation}
%\label{FOFDMConfig}
\hline
\end{tabular}
\end{center}
\hfill

The result is shown below enter image description here

My second problem is that the \caption{} and \label{} don't seem to work and when compiling I have this error:

! LaTeX Error: \caption outside float.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \caption

and thank you for your help

  • 3
    Welcome to TeX.SX. Your code does not show a caption. Please see an introduction and read about float environments, in your case the table environment. Also have a look at the tables section, where you can learn about p columns. They have a fixed width. – Johannes_B Jun 18 at 4:58
  • 1
    Also make sure you double check the column specifier you use. Why is the third column in math mode although it apparently only contains text? – leandriis Jun 18 at 5:16
  • Also, are you sure, that the description column is needed as your parameter names already are quite descriptive e and mostly self-explanatory. – leandriis Jun 18 at 5:19
  • (1) you should know what is a p column, the environment tabular* (with the *) and the packages tabularx and tabulary (2) the \caption of the table usually should be inside a table environment (table is a float, tabular is not) and the` \label` should be inside the caption argument or just after \caption{} and before \end{table} – Fran Jun 18 at 5:51
  • load package capt-of and then use \captionof{table}{....} – Red-Cloud Jun 18 at 7:08
2

In the context of a numbered table with a caption, the command \caption{} is designed to be used inside a table float environment. The label is to reference that caption, so it should be inside the caption argument of just after it, but anyway also inside the table environment and before any other caption.

There are some packages to use captions without a float: caption and capt-of but usually the most convenient to numbered tables and figures is use floats.

With respect the width of the table, The fist to understand is that r,c, and l columns cannot break text, so the width of each column is mainly the length of the longest text of the column. To allow line breaks you can use columns as p{5cm} or p{5em}, or better, with relative lengths (e.g., p{0.2\linewidth}). Alternatively, you can use also the m and b columns using the package array.

Fix the width of the whole table to the text width is not trivial using fixed width columns as you must take into account of the width of column separations (\tabcolsep) making column and maybe (hopefully not) the width of vertical rules. This can be simplified a lot using a tabular*, tabularx or tabulary environments, where you can simply set the width of the whole table. There are a lot examples in this site using the three environments. What is better depend mainly of the type of table, but worth remember that any of these solutions can fit better some tables, not make miracles, so a careful redesign of the tables is often advisable, and when this is not enough, use a smaller font size, or a landscape page, etc. An example using tabulary:

mwe

\documentclass[11pt]{article}
\usepackage{booktabs,array,tabulary}
\begin{document}
\begin{table}
\caption{Configuration of the simulation}
\label{FOFDMConfig}
\small\extrarowheight1ex
\begin{tabulary}{\linewidth}{@{}lcL@{}}\toprule
FOFDM\textunderscore Parameter& Value &\textrm{Detail}\\\midrule
NumberOfSubcarriers   & $24$             & Number\ of\ subcarriers\\
NumberOfSymbolsInTime & $14$             & Number\ FOFDM\ symbols\ in\ time\\
SubcarrierSpacing     & $15\times 10^3$  & Subcarrier\ spacing (Hz)\\
CyclicPrefixLength    & $0$   & Length\ of\ the\ cyclic\ prefix\ (s)\\
FilterLengthTX        & $0.2\times \frac{1}{FOFDM\textunderscore SubcarrierSpacing}$ &Length at the transmitter filter (s)\\ 
FilterLengthRX        & $0.2\times \frac{1}{FOFDM\textunderscore SubcarrierSpacing}$ &Length at the receiver filter (s)\\\bottomrule  
\end{tabulary}
\end{table}
\end{document}
  • Thanks, upvoted :) – CarLaTeX Jun 18 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.