4

I am new to latex and I am getting an error. Please check if I have missed something.

\noindent
\begin{table}[ht]
\caption{} % title of Table
 \centering % used for centering table
 \begin{tabular}{c c c c} % centered columns (4 columns)
 \hline\hline %inserts double horizontal lines
  Frequency & $V_{0} $(LPF) & Gain(in dB)LPF & $V_{0}$(HPF)& Gain(indB)\\ [0.5ex] % inserts table
 %heading
 \hline % inserts single horizontal line
 100 & 1.57&3.91&16.90m&-35.44 \\ % inserting body of the table
  300&  1.58&  3.97&155.39m&-16.17\\
  500& 1.59&  4.02&442.93m&-7.0\\
  700& 1.53& 3.69&769.11&-2.28\\
  900& 1.39&2.86&1.00& 0\\ [1ex] % [1ex] adds vertical space
  1k & 1.32&2.41&1.1443&1.17\\
  1.1k&1.26&2.007&1.188&1.4\\
   1.2k&1.06&0.506&1.297&2.21\\
  1.5k&865.03m&-1.25&1.438&3.15\\
  2k&509.50m&-5.85&1.542&3.76\\
  4k&141.04m&-17.01&1.49&3.46\\
   6k&62.82m&-24.038&1.56&3.86\\

   \hline %inserts single line
    \end{tabular}
     \label{table:nonlin} % is used to refer this table in the text
     \end{table}

Error which i am getting is :

! Extra alignment tab has been changed to \cr.

2
  • 3
    You've only declared four columns but you are using five!
    – Joseph Wright
    Commented Sep 20, 2016 at 15:56
  • also you need to remove \noindent from before the \begin{table} Commented Sep 20, 2016 at 16:27

2 Answers 2

6

In addition to providing for 5 rather than just 4 columns in the tabular environment, you should also strive to provide a better layout. For instance, negative numbers should be associated with a typographic minus symbol rather than a text-mode "dash" symbol, and (whenever possible) care should be taken to align numbers in a column on their decimal markers. Separately, since there are 12 rows in total, the table looks more appealing if you provide a bit of vertical whitespace after rows 4 and 8, rather than just after row 5. Finally, the table's intelligibility (or at least its readability) would probably gain from a reorganization of the header material.

These ideas are implemented in the following code.

enter image description here

\documentclass{article}
\usepackage{caption,booktabs,siunitx}
\begin{document}

\begin{table}[ht]
\caption{}
\label{table:nonlin}
\centering 
\begin{tabular}{@{} c c S[table-format=-2.3] 
                      c S[table-format=-2.2] @{}} 
 \toprule
 Frequency & \multicolumn{2}{c}{LPF} & \multicolumn{2}{c@{}}{HPF} \\
 \cmidrule(lr){2-3} \cmidrule(l){4-5}
 & $V_{0}$ & {Gain} & $V_{0}$ & {Gain}\\
 & & {(in dB)} & & {(in dB)} \\
 \midrule
  100& 1.57   & 3.91 &\phantom{0}16.90m  &-35.44 \\
  300& 1.58   & 3.97 &155.39m            &-16.17\\
  500& 1.59   & 4.02 &442.93m            & -7.00\\
  700& 1.53   & 3.69 &769.11m            & -2.28\\
 \addlinespace 
  900& 1.39   & 2.86 &1.00\phantom{00}   & 0\\ 
    1k&1.32   & 2.41 &1.1443             &1.17\\
  1.1k&1.26   & 2.007&1.188\phantom{0}   &1.40\\
  1.2k&1.06   & 0.506&1.297\phantom{0}   &2.21\\
 \addlinespace 
  1.5k&865.03m&-1.25 &1.438\phantom{0}   &3.15\\
    2k&509.50m&-5.85 &1.542\phantom{0}   &3.76\\
    4k&141.04m&-17.01&1.49\phantom{00}   &3.46\\
    6k&\phantom{0}62.82m&-24.038&1.56\phantom{00}&3.86\\
 \bottomrule
\end{tabular}
\end{table}

\end{document} 
3

You were just missing a column specifier in the \begin{tabular} statement...

\documentclass{article}
\begin{document}
%\noindent
\begin{table}[ht]
\caption{} % title of Table
\centering % used for centering table
\begin{tabular}{c c c c c} % centered columns (5 columns)
\hline\hline %inserts double horizontal lines
Frequency & $V_{0} $(LPF) & Gain(in dB)LPF & $V_{0}$(HPF) & Gain(indB)\\ [0.5ex]       % inserts table
%heading
\hline % inserts single horizontal line
100 & 1.57&3.91&16.90m&-35.44 \\ % inserting body of the table
300&  1.58&  3.97&155.39m&-16.17\\
500& 1.59&  4.02&442.93m&-7.0\\
700& 1.53& 3.69&769.11&-2.28\\
900& 1.39&2.86&1.00& 0\\ [1ex] % [1ex] adds vertical space
1k & 1.32&2.41&1.1443&1.17\\ 
1.1k&1.26&2.007&1.188&1.4\\
1.2k&1.06&0.506&1.297&2.21\\
1.5k&865.03m&-1.25&1.438&3.15\\
2k&509.50m&-5.85&1.542&3.76\\
4k&141.04m&-17.01&1.49&3.46\\
6k&62.82m&-24.038&1.56&3.86\\

   \hline %inserts single line
    \end{tabular}
     \label{table:nonlin} % is used to refer this table in the text
     \end{table}
\end{document}     
1
  • Welcome to TeX.SE! In addition to fixing the immediate error(s) that halt the compilation, it's also a good idea to delete or comment out instructions in the OP's code that are redundant or meaningless, such as the \noindent directive immediately ahead of \begin{table}, and to make sure that material in comments is correct. (As I'm writing this comment, I just noticed that David Carlisle has edited your posting to comment out the \noindent directive and to update the comment about the number of c columns.) If nothing else, such fixes help make the code more readable, don't they?
    – Mico
    Commented Sep 20, 2016 at 17:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .