[Tex/LaTex] LaTeX Table Generator

scalingtables

I'm new in Latex and I should deal with huge number of tables in different ways and limited time, for that I used LaTeX Table Generator website to make the process easier.

Could you guys tell me what I can add to the code which generated by the website without changing in the code formula to generate the tables with unified size and unified font size.

code examples:

\usepackage{graphicx}
\begin{table}[h]
\resizebox{\textwidth}{!}{%
\begin{tabular}{|l|l|r|}
\hline
\multicolumn{3}{|c|}{Item}        \\ \hline
Animal & Description & Price (\$) \\ \hline
Gnat   & per gram    & 13.65      \\ \hline
       & very long text       & 0.01       \\ \hline
\end{tabular}
}
\end{table}

Example 2

\usepackage{multirow}
\usepackage{graphicx}
\begin{table}[h]
\resizebox{\textwidth}{!}{%
\begin{tabular}{|l|l|r|}
\hline
\multicolumn{1}{|c|}{Animal} & Description & Price (\$) \\ \hline
\multirow{2}{*}{Gnat}        & per gram    & 13.65      \\ \cline{2-3} 
                             & each        & 0.01       \\ \hline
Gnu                          & stuffed     & 92.50      \\ \hline
\end{tabular}
}
\end{table}

Thank you.

Best Answer

I'm not sure which table generator you're using, but always having the \resizeboxes is a really bad idea. As you've noticed, you get inconsistent font sizes and distorted rules. You might want to check if there is an option to turn this off in whichever software/web app/etc. you're using for this.

The immediate fix is to comment out the \resizebox line and its corresponding closing brace, like this:

\begin{table}[h]
%\resizebox{\textwidth}{!}{%
\begin{tabular}{|l|l|r|}
\hline
\multicolumn{3}{|c|}{Item}        \\ \hline
Animal & Description & Price (\$) \\ \hline
Gnat   & per gram    & 13.65      \\ \hline
       & very long text       & 0.01       \\ \hline
\end{tabular}
%}
\end{table}

This will get rid of the drastic resizing.

If the table ends up being too wide for the text, you can insert \small or any other font size command inside the tabular environment. This will allow more controlled adjustment of the font size, so it's at least consistent with other font sizes in your document.

In the full code, I also show some capabilities of the excellent booktabs package for better layout of tables. Some table code generators support booktabs natively (excel2latex and probably others) or you can add the markup manually.

\documentclass{article}
\usepackage{booktabs,multirow}
\setcounter{totalnumber}{4} % just so they all fit on the page

\begin{document}
Example 1:
\begin{table}[h]
%\resizebox{\textwidth}{!}{%
\begin{tabular}{|l|l|r|}
\hline
\multicolumn{3}{|c|}{Item}        \\ \hline
Animal & Description & Price (\$) \\ \hline
Gnat   & per gram    & 13.65      \\ \hline
       & very long text       & 0.01       \\ \hline
\end{tabular}
%}
\end{table}

Example 2 (also illustrating \verb+\centering+):
\begin{table}[h]
\centering
%\resizebox{\textwidth}{!}{%
\begin{tabular}{|l|l|r|}
\hline
\multicolumn{1}{|c|}{Animal} & Description & Price (\$) \\ \hline
\multirow{2}{*}{Gnat}        & per gram    & 13.65      \\ \cline{2-3} 
                             & each        & 0.01       \\ \hline
Gnu                          & stuffed     & 92.50      \\ \hline
\end{tabular}
%}
\end{table}

After \verb+booktabs+-ification (optional):
\begin{table}[h]
  \centering
  \begin{tabular}{llr}
    \toprule
    \multicolumn{3}{c}{Item}             \\ \cmidrule(lr){1-3}
    Animal & Description    & Price (\$) \\ \midrule
    Gnat   & per gram       & 13.65      \\
           & very long text & 0.01       \\ \bottomrule
  \end{tabular}
\end{table}

\begin{table}[h]
  \centering
  \begin{tabular}{llr}
    \toprule
    Animal                & Description & Price (\$) \\ \midrule
    \multirow{2}{*}{Gnat} & per gram    & 13.65      \\
                          & each        & 0.01       \\ \addlinespace
    Gnu                   & stuffed     & 92.50      \\ \bottomrule
  \end{tabular}
\end{table}

\end{document}

enter image description here

Related Question