Table Error in LaTeX: Troubleshooting Solutions

  • Context: LaTeX 
  • Thread starter Thread starter Rajini
  • Start date Start date
  • Tags Tags
    Error Latex Table
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting a LaTeX table code that generates errors when using square brackets for units. Participants explore various solutions to resolve the issue, focusing on formatting and syntax within LaTeX.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant reports an error when using square brackets for units in a LaTeX table, noting that removing the brackets resolves the issue.
  • Another participant explains that the error arises because LaTeX interprets square brackets at the end of a line as a command for extra spacing, which conflicts with the subsequent line starting with square brackets.
  • A suggestion is made to use [0ex] at the end of the first line to avoid the error.
  • One participant shares their experience of successfully creating tables with units but notes that this is their first attempt with units starting from the first cell, leading to the peculiar error.
  • Multiple solutions are proposed, including using math mode for units or escaping square brackets with curly braces.
  • Participants express intent to try the suggested solutions and share their outcomes.

Areas of Agreement / Disagreement

Participants generally agree on the nature of the error and the proposed solutions, but there is no consensus on which solution is the best or most effective, as multiple options are presented.

Contextual Notes

Some solutions depend on specific LaTeX configurations or document classes, which may not be universally applicable. The discussion does not resolve which method is superior or more widely accepted.

Rajini
Messages
619
Reaction score
4
dear all..
I use the following code to generate a table...to my eyes i think no error..but still i get error..
Code:
\begin{table}[h]
\caption{some fitting.}\label{tab:fit}
\vspace{3mm}
\centering
\begin{tabular}[width=1\linewidth]{llll}
\hline\hline
Wavenumber & FWHM        & Area        & Force constant\\
[cm$^{-1}$]  & [cm$^{-1}$] & [cm$^{-2}$] &   [N~m$^{-1}$]\\
\hline
19 & 1   & 1 & 5.9 \\
230 & 3 & 17 & 57.2 \\
2 & 1    & 23 & 7.8 \\
35 & 15 & 37 & 12.4 \\
314 & 30 & 3 & 121.2 \\
43 & 13.9 & 1  & 4.2 \\
\hline\hline
\end{tabular}
\end{table}
But i can get the table only if i don't use the box brackets [ ] for the unit just below wavelength..when i make box bracket around the unit i always get error..
thanks
 
Physics news on Phys.org
Hi Rajini,

Rajini said:
dear all..
I use the following code to generate a table...to my eyes i think no error..but still i get error..
Code:
\begin{table}[h]
\caption{some fitting.}\label{tab:fit}
\vspace{3mm}
\centering
\begin{tabular}[width=1\linewidth]{llll}
\hline\hline
Wavenumber & FWHM        & Area        & Force constant\\
[cm$^{-1}$]  & [cm$^{-1}$] & [cm$^{-2}$] &   [N~m$^{-1}$]\\
\hline
19 & 1   & 1 & 5.9 \\
230 & 3 & 17 & 57.2 \\
2 & 1    & 23 & 7.8 \\
35 & 15 & 37 & 12.4 \\
314 & 30 & 3 & 121.2 \\
43 & 13.9 & 1  & 4.2 \\
\hline\hline
\end{tabular}
\end{table}
But i can get the table only if i don't use the box brackets [ ] for the unit just below wavelength..when i make box bracket around the unit i always get error..
thanks

Take a look at the output from this table, that has [5ex] at the end of the first line of the table:


Code:
\begin{table}[h]
\centering
\begin{tabular}[width=1\linewidth]{llll}
\hline\hline
19 & 1   & 1 & 5.9 \\[5ex]
230 & 3 & 17 & 57.2 \\
2 & 1    & 23 & 7.8 \\
35 & 15 & 37 & 12.4 \\
314 & 30 & 3 & 121.2 \\
43 & 13.9 & 1  & 4.2 \\
\hline\hline
\end{tabular}
\end{table}

When an expression in square brackets is at the end of a line, it is a way of telling LaTeX that you want extra spacing before the next line. But since your next line begins with square brackets, LaTeX thinks you are trying to do the same thing and gives an error. There are several things you can do, but probably the easiest is just put [0ex] at the end of the first line of your table like this:

Code:
\begin{table}[h]
\caption{some fitting.}\label{tab:fit}
\vspace{3mm}
\centering
\begin{tabular}[width=1\linewidth]{llll}
\hline\hline
Wavenumber & FWHM        & Area        & Force constant\\[0ex]
[cm$^{-1}$]  & [cm$^{-1}$] & [cm$^{-2}$] &   [N~m$^{-1}$]\\
\hline
19 & 1   & 1 & 5.9 \\
230 & 3 & 17 & 57.2 \\
2 & 1    & 23 & 7.8 \\
35 & 15 & 37 & 12.4 \\
314 & 30 & 3 & 121.2 \\
43 & 13.9 & 1  & 4.2 \\
\hline\hline
\end{tabular}
\end{table}
 
Hi thanks for your reply!.
actually i made some tables successfully...but for units i use the same as above..but first cell in unit row will be empty so i was fine with my table...but this is my first time making a table with units start from the first cell of the row..so i got this peculiar error...
anyway i will correct according to your idea..
thanks again
 
Getting special symbols in your generated document can be nasty in LaTeX.

Solution #1: Do it in math mode.
Code:
...
\begin{tabular}[width=1\linewidth]{llll}
\hline\hline
Wavenumber & FWHM        & Area        & Force constant\\
$[\text{cm}^{-1}]$  & $[\text{cm}^{-1}]$ & $[\text{cm}^{-2}]$ & $[\text{N~m}^{-1}]$ \\
\hline
...

Solution #2: Use curly braces to escape the square brackets (backslash square bracket doesn't work):
Code:
...
\begin{tabular}[width=1\linewidth]{llll}
\hline\hline
Wavenumber & FWHM        & Area        & Force constant\\
{[}cm$^{-1}${]}  & {[}cm$^{-1}${]} & {[}cm$^{-2}${]} &   {[}N~m$^{-1}${]}\\
\hline
...
 
Yes DH..
seems like latex provides several options...!
will try them
thanks
 
Hi both of you,
[0ex] is simple to use..
It worked well..
thanks
 

Similar threads

  • · Replies 0 ·
Replies
0
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 7 ·
Replies
7
Views
9K
  • · Replies 2 ·
Replies
2
Views
6K