0

Here is my practise table , I wrote if after watching some youtube videos and reading wikibooks tables tutorial. This is not generating pdf

\documentclass{article}

\usepackage{tabularx}
\usepackage{siunitx}
%\sisetup{
%round-mode = places,
%round-precision = 2, 
%}

\usepackage{booktabs}
\usepackage{array}
\begin{document}
\begin{table}[h!]
\begin{center}
\begin{tabularx}{| @{}X | @{}X | @{}X |}
\hline
\textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3}\\
$\alpha$ & $\beta$ & $\gamma$ \\
\hline
1 & 1110.1 & a \\
2 & 10.1  & b \\
3 & 23.113231 & c \\
\hline
\end{tabularx}
\end{center}
\caption{Your first label}
\label{tab:table1}
\end{table}
Second table
\begin{table} [h!]
\begin{center}
\begin{tabular}{|r | l |}
    \hline
    7C0 & hexadecimal \\
    3700 & octal \\
    \cline{2-2} 11111000000 & binary \\
    \hline
\end{tabular}
\end{center}
\caption{Your second label}
\label{tab:table2}
\end{table}


\begin{tabular}{cc}
    boring cell content & \parbox[t]{5cm}{rather long par\\new par}
\end{tabular}

\begin{tabular}{c c}
    \hline
    \begin{verbatim}
    code
    \end{verbatim}
    & description
    \\ \hline
\end{tabular}
\end{document}

I am getting following errors

line 15: Missing number, treated as zero. \begin{tabularx}{| @{}X | @{}X | @{}X |}
line 15: Illegal unit of measure (pt inserted). \begin{tabularx}{| @{}X | @{}X | @{}X |}
line 24: Package array Error: Illegal pream-token (\hline): `c' used. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Package array Error: Illegal pream-token (\hline): `c' used. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 24: Extra alignment tab has been changed to \cr. \end{tabularx}
line 51: Something's wrong--perhaps a missing \item. \begin{verbatim}
line 51: Something's wrong--perhaps a missing \item. \begin{verbatim}
line 51: Something's wrong--perhaps a missing \item. \begin{verbatim}
line 51: Missing \endgroup inserted. \begin{verbatim}
line 51: Missing \endgroup inserted. \begin{verbatim}
line 51: Missing } inserted. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Missing } inserted. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 51: Missing \cr inserted. \begin{verbatim}
line 51: Misplaced \cr. \begin{verbatim}
line 24: X Columns too narrow (table too wide)(tabularx)
line 24: Overfull \hbox (54.77792pt too wide) in alignment

Since I am trying to learn so I would like to know what is the conceptual mistake I did in this code.

14
  • 5
    You forgot to specify tabularx width: it should be: \begin{tabularx}{<desired width>}{| @{}X | @{}X | @{}X |}
    – Zarko
    Commented May 9, 2020 at 11:48
  • 1
    See also my comment to an earlier question of you: tex.stackexchange.com/questions/542928/…
    – leandriis
    Commented May 9, 2020 at 11:51
  • 1
    Also, do yourself and your reader a favor and remove all occurences or @{} if you want to keep the vertical lines. Inside of a table you usually have a small horizontal white space left and right of the text inside of a cell (Also called \tabcolsep). This white space ensures that the text does not toutch the vertical line or the text in the adjacent columns. With @{} you can remove this small space. If you remove this space, the letters will touch the vertical line, which does not look good.
    – leandriis
    Commented May 9, 2020 at 11:56
  • 1
    @leandriis sorry yes I noticed that later:-) (the ping to you was only an indication of shared pain:-) Commented May 9, 2020 at 12:02
  • 1
    also the table is a table of numerical data with no linebreaking in the cells so would look much better set as a tabular at its natural width, why are you forcing the table to be full width? Commented May 9, 2020 at 12:04

1 Answer 1

3

As mentioned earlier, the error message you get informs you about the missing width of the tabularx:

The correct syntax is \begin{tabularx}{>table width here<}{>column specifiers here<}. Example: \begin{tabularx}{\textwidth}{XXX}.

Since you mentioned in an earlier comment you were inerested in good looking table, I have added some step-by-step examples on how you can improve the layout of this first table. The code contains some hopefully helpful comments to explain the changes and their reasons.

As also already mentioned earlier, the example contains another error: A verbatim environment can only be used in a p (or derived) column type. I have also corrected that.

enter image description here

\documentclass{article}

\usepackage{tabularx}
\usepackage{siunitx}
%\sisetup{
%round-mode = places,
%round-precision = 2, 
%}

\usepackage{booktabs}
\usepackage{array}



\begin{document}
\begin{table}[h!]
\begin{center}
\begin{tabularx}{\textwidth}{| @{}X | @{}X | @{}X |} % added missing width argument \textwidth here
\hline
\textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3}\\
$\alpha$ & $\beta$ & $\gamma$ \\
\hline
1 & 1110.1 & a \\
2 & 10.1  & b \\
3 & 23.113231 & c \\
\hline
\end{tabularx}
\end{center}
\caption{syntax corrected}
\label{tab:table1a}
\end{table}

\begin{table}[h!]
\centering % removed center environment and used centering command instead. The former adds vertical white space that might be undesired
\begin{tabularx}{\textwidth}{| X | X | X |} % Also removed @{} to prevent overlap of the text with the vertical lines
\hline
\textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3}\\
$\alpha$ & $\beta$ & $\gamma$ \\
\hline
1 & 1110.1 & a \\
2 & 10.1  & b \\
3 & 23.113231 & c \\
\hline
\end{tabularx}
\caption{removed overlap with vertical lines}
\label{tab:table1b}
\end{table}

\begin{table}[h!]
\centering 
\begin{tabularx}{\textwidth}{X X X} % Entirely removed vertical lines 
\toprule % replaced \hline with booktabs line
\textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3}\\
$\alpha$ & $\beta$ & $\gamma$ \\
\midrule  % replaced \hline with booktabs line
1 & 1110.1 & a \\
2 & 10.1  & b \\
3 & 23.113231 & c \\
\bottomrule  % replaced \hline with booktabs line
\end{tabularx}
\caption{removed vertical lines and used horizontal lines from booktabs}
\label{tab:table1c}
\end{table}


\begin{table}[h!]
\centering 
\begin{tabular}{ccc} % replaced tabularx with a regular tabular. There is no need to artificially make the table wider
\toprule 
\textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3}\\
$\alpha$ & $\beta$ & $\gamma$ \\
\midrule  
1 & 1110.1 & a \\
2 & 10.1  & b \\
3 & 23.113231 & c \\
\bottomrule  
\end{tabular}
\caption{replaced tabularx with tabular. no need to make the table wider}
\label{tab:table1d}
\end{table}


\begin{table}[h!]
\centering 
\begin{tabular}{cS[table-format=4.6] c} % rreplacesd second column with S type column from siunits to improve alignment of numbers
\toprule 
\textbf{Value 1} & \textbf{Value 2} & \textbf{Value 3}\\
$\alpha$ & {$\beta$} & $\gamma$ \\ % adde {} around {$\beta$} because of non-number in S type column  
\midrule  
1 & 1110.1 & a \\
2 & 10.1  & b \\
3 & 23.113231 & c \\
\bottomrule  
\end{tabular}
\caption{used siunitx for second column}
\label{tab:table1d}
\end{table}

\pagebreak


Second table
\begin{table} [h!]
\centering % see table 2
\begin{tabular}{|r | l |}
    \hline
    7C0 & hexadecimal \\
    3700 & octal \\
    \cline{2-2} 11111000000 & binary \\
    \hline
\end{tabular}
\caption{Your second label}
\label{tab:table2}
\end{table}


\begin{tabular}{cc}
    boring cell content & \parbox[t]{5cm}{rather long par\\new par}
\end{tabular}

\bigskip % just for some vertical space in the output. Do not use in actual document!

\begin{tabular}{cp{5cm}} % use a p type column here
    boring cell content & rather long par new par \\ % no need for parbox in every cell (automatic linebreak here)
        boring cell content & rather \newline long text   par new par % no need for parbox in every cell (manual linebreak)
\end{tabular}

\bigskip % just for some vertical space in the output. Do not use in actual document!

\begin{tabular}{p{3cm} c} % verbatim only works in a p type column. Adjust the width to your needs
    \hline
    \begin{verbatim}
    code
    \end{verbatim}
    & description
    \\ \hline
     \verb|code| % for shorter code, use verb. For more improvement give more information about the nature of the code. More advanced packages are listings and minted. Which to use depends on the requirements and the desired output.
    & description
    \\ \hline
\end{tabular}


\end{document}

You must log in to answer this question.

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