1

I'm trying to create a table with 5 columns, but it seems to be harder than I expected. I'm new to LaTex and I went through several attempts and I can't get any of them to work.

\begin{table}[ht]
\centering
\caption{0\% variation}
\begin{tabular}[t]{lcc}
\hline
Parameter & Actual Value & Difference & Range & Parameter Found \\
\hline
\alpha & 0.191 & 0 & (0.191,0.191) & 0.191\\
\beta & 0.05 & 0 & (0.05,0.05) & 0.05\\
\gamma & 0.0294 & 0 & (0.0294,0.0294) & 0.0294\\
\hline
\end{tabular}
\end{table}

enter image description here

Currently the table has 3 columns for some reason and I can't get it to stretch to the page size (which I think is the issue)

4
  • 2
    You have only 3 columns add more c. {lcccc}
    – Roland
    Commented Jun 27, 2021 at 23:56
  • Gosh that was an easy fix. Thanks a lot!
    – Penguin
    Commented Jun 28, 2021 at 0:10
  • 5
    I’m voting to close this question because solved in comments.
    – Roland
    Commented Jun 28, 2021 at 5:54
  • Yep, with you on that
    – Penguin
    Commented Jun 28, 2021 at 14:12

1 Answer 1

4

In order to make your code compilable, and as has been suggested in the comments before, use 5 column specifiers instead of just 3. Also, commands such as \alpha and \beta can not be used outside of math mode, so use $\alpha$ and $\beta$ instead.

With these changes, you end up with a compilable code and a table that is slightly wider than the textwidth of a regular article class. If you want to make sure the table fits perfectly into the textwidth, you may want to give the combination of tabular* with @{\xtracolsep{\fill}} a try. In the following MWE, I also added a third alternative layout based on horizontal lines from booktabs, the \thead command from makecell and S type columns from siunitx that allow alignment of numbers with respect to their decimal separators:

enter image description here

\documentclass{article}

\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{makecell}

\begin{document}

\begin{table}[ht]
\centering
\caption{0\% variation}
\begin{tabular}[t]{lcccc}
\hline
Parameter & Actual Value & Difference & Range & Parameter Found \\
\hline
$\alpha$ & 0.191 & 0 & (0.191,0.191) & 0.191\\
$\beta$ & 0.05 & 0 & (0.05,0.05) & 0.05\\
$\gamma$ & 0.0294 & 0 & (0.0294,0.0294) & 0.0294\\
\hline
\end{tabular}
\end{table}

\begin{table}[ht]
\caption{0\% variation}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}lcccc}
\hline
Parameter & Actual Value & Difference & Range & Parameter Found \\
\hline
$\alpha$ & 0.191 & 0 & (0.191,0.191) & 0.191\\
$\beta$ & 0.05 & 0 & (0.05,0.05) & 0.05\\
$\gamma$ & 0.0294 & 0 & (0.0294,0.0294) & 0.0294\\
\hline
\end{tabular*}
\end{table}


\begin{table}[ht]
\centering
\caption{0\% variation}
\begin{tabular}{lS[table-format=1.4]cccS[table-format=1.4]}
\toprule
\thead{Parameter} & {\thead{Actual\\ Value}} & \thead{Difference} & \thead{Range} & {\thead{Parameter\\ Found}} \\
\midrule
$\alpha$ & 0.191 & 0 & (0.191,0.191) & 0.191\\
$\beta$ & 0.05 & 0 & (0.05,0.05) & 0.05\\
$\gamma$ & 0.0294 & 0 & (0.0294,0.0294) & 0.0294\\
\bottomrule
\end{tabular}
\end{table}

\end{document}

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