8

Self-explanatory title. I'm new to LaTeX and this table looks pretty ugly.

enter image description here

\documentclass[letterpaper]{article}
\special{papersize=8.5in,11in}
\usepackage{indentfirst}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsmath}

\usepackage{gensymb}
\usepackage[margin=1in]{geometry}
\setlength{\parskip}{1em}

\begin{document}

\begin{table}
\centering
\begin{tabular}{|c|ccccc|} 
\hline
     &  $0$ & $\frac{\pi}{6}$      & $\frac{\pi}{4}$      & $\frac{\pi}{6}$      
& $\frac{\pi}{2}$  \\ 
\hline
$\sin x$ & $0$  & $\frac{1}{2}$        & $\frac{\sqrt{2}}{2}$ & 
$\frac{\sqrt{3}}{2}$ & $1$  \\
$\cos x$ & $1$  & $\frac{\sqrt{3}}{2}$ & $\frac{\sqrt{2}}{2}$ & $\frac{1}{2}$        & $0$  \\
$\tan x$ & $0$  & $\frac{\sqrt{3}}{3}$ & $1$                  & $\sqrt{3}$           &   \\
\hline
\end{tabular}
\end{table}

\end{document}

Thank you.

5
  • 2
    Welcome to TeX.SE! How about \renewcommand{\arraystretch}{1.57}? I'd also like to encourage you to be a bit more specific, i.e. to tell us what you wish to achieve. Otherwise there is a danger that this question could be closed as "primarly opinion based".
    – user121799
    Sep 26, 2018 at 1:44
  • 1
    The booktabs package (and documentation) has some strongly held opinions about making tables pretty. #1 is no vertical lines. But I do agree with marmot that it's not clear what you want to achieve.
    – Teepeemm
    Sep 26, 2018 at 1:48
  • 2
    It would also be helpful (for us casual readers) to include an image of the "ugly" table.
    – MrWhite
    Sep 26, 2018 at 16:12
  • Typo: the second $\frac{\pi}{6}$ in the heading should be $\frac{\pi}{3}$. So far, all the answers have reproduced this error faithfully!
    – TonyK
    Sep 26, 2018 at 18:44
  • This might be tangential, but looking at the answers I have this great urge to nicely ask for filling the gap in place for tan(pi/2). It almost looks like an erroneous omission.
    – luk32
    Sep 26, 2018 at 23:24

8 Answers 8

12

I'd keep it as simple as possible.

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}

\usepackage{booktabs}
\usepackage{array}
\usepackage{caption} % optional

\begin{document}

\begin{table}

\centering

\caption{Table of trigonometric functions for common angles}

$
\setlength{\arraycolsep}{12pt} % for this particular table
\begin{array}{@{} l *{5}{>{\displaystyle}c} @{}}
\toprule
  &  0 & \frac{\pi}{6}      & \frac{\pi}{4}      & \frac{\pi}{6} & \frac{\pi}{2}  \\ 
\midrule
\sin x
  & 0  & \frac{1}{2}        & \frac{\sqrt{2}}{2} & \frac{\sqrt{3}}{2} & 1  \\
\addlinespace
\cos x
  & 1  & \frac{\sqrt{3}}{2} & \frac{\sqrt{2}}{2} & \frac{1}{2}        & 0  \\
\addlinespace
\tan x
  & 0  & \frac{\sqrt{3}}{3} & 1                  & \sqrt{3}           &   \\
\bottomrule
\end{array}
$

\end{table}

\end{document}

I use array to simplify the input (no $ necessary except around the array). With \addlinespace we can easily separate the lines. With a larger value of \arraycolsep we better separate the columns for ease of reading in this particular case.

enter image description here

7

my primary concern is to simplify your code. other is opinion based ...

  • instead tabular i would use array and than remove all $ in table code
  • for more vertical space i would employ the makecell package, i.e. use its macro \gapedcells:
  • note: mathtools load amsmath, so there is no need to load it again (loading packages more than once is not always innocuous...)

    \documentclass[letterpaper]{article}
    \usepackage[margin=1in]{geometry}
    \usepackage{indentfirst}
    \usepackage{mathtools}
    \usepackage{amssymb}
    %\usepackage{gensymb}   % <--- do you really need?
    \usepackage{makecell}   % <--- new
    
    \setlength{\parskip}{1em}
    
    \begin{document}
    
    \[\setcellgapes{3pt}
      \makegapedcells
    \begin{array}{c|ccccc}
            & 0 & \frac{\pi}{6}      & \frac{\pi}{4}      & \frac{\pi}{6}      & \frac{\pi}{2} \\
        \hline
    \sin x  & 0 & \frac{1}{2}        & \frac{\sqrt{2}}{2} & \frac{\sqrt{3}}{2} & 1      \\
    \cos x  & 1 & \frac{\sqrt{3}}{2} & \frac{\sqrt{2}}{2} & \frac{1}{2}        & 0      \\
    \tan x  & 0 & \frac{\sqrt{3}}{3} & 1                  & \sqrt{3}           & \infty \\
    \end{array}
    \]
    
    \end{document}
    

enter image description here

1
  • 1
    This is by far the best looking table IMHO.
    – TonyK
    Sep 26, 2018 at 18:45
7
\documentclass[border=3pt]{standalone}
\usepackage{booktabs}
\usepackage{array}
\usepackage{amsmath}

\setlength\extrarowheight{2pt}

\def\getNum#1\relax{\gdef\num{#1}$\tfrac{1}{2}\sqrt{#1}$}

\def\getDenum#1\\{\gdef\denum{#1}$\tfrac{1}{2}\sqrt{#1}$&$\sqrt{\tfrac{\num}{\denum}}$\\}

\begin{document}

\begin{tabular}
{
    >{$}c<{^\circ$}
    >{\getNum}c
    >{\getDenum}c
    c
}
\toprule
\multicolumn{1}{c}{$\theta$}&
    \multicolumn{1}{c}{$\sin\theta$}&
        \multicolumn{1}{c}{$\cos\theta$}&
            \multicolumn{1}{c}{$\tan\theta$}\\
\midrule
0&
    0&
        4\\
30&
    1&
        3\\
45&
    2&
        2\\
60&
    3&
        1\\
90&
    4&
        0\\
\bottomrule
\end{tabular}

\end{document}

enter image description here

6

enter image description here

  1. Use \toprule and \bottomrule from booktabs at the beginning and end of your table
  2. Remove rules among columns and rows except the first one
  3. Use tabularx with type X column instead of tabular (it is better since you force columns with similar contents to be of equal size, at least in my opinion)
  4. Stretch your array \renewcommand{\arraystretch}{1.5}
  5. Use 'tab' to indent nested contents (this is to make debugging and revisions easier)

Code

\documentclass[letterpaper]{article}
\special{papersize=8.5in,11in}
\usepackage{indentfirst}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsmath}
\setlength{\parskip}{1em}
\usepackage{gensymb}
\usepackage[margin=1in]{geometry}

\usepackage{ragged2e}
\usepackage{tabularx}
\newcolumntype{C}{ >{ \arraybackslash \Centering } X }
\usepackage{booktabs}

\renewcommand{\arraystretch}{1.5}
\setlength{\parskip}{1em}

\begin{document}

\begin{table}

    \centering

    \begin{tabularx}{0.35\textwidth}{c| *{5}{C}} 
        \toprule
        &  $0$ & $\frac{\pi}{6}$      & $\frac{\pi}{4}$      & $\frac{\pi}{6}$      
        & $\frac{\pi}{2}$
        \\ 
        \hline
        $\sin x$ & $0$  & $\frac{1}{2}$        & $\frac{\sqrt{2}}{2}$ & 
        $\frac{\sqrt{3}}{2}$ & $1$
        \\
        $\cos x$ & $1$  & $\frac{\sqrt{3}}{2}$ & $\frac{\sqrt{2}}{2}$ & $\frac{1}{2}$        & $0$
        \\
        $\tan x$ & $0$  & $\frac{\sqrt{3}}{3}$ & $1$                  & $\sqrt{3}$           &
        \\
        \bottomrule
    \end{tabularx}

\end{table}

\end{document}
5

A workaround in tabu, an extension of tabularx; the most important thing to better presentations for fractions in math is to preserve the size of the numbers for this reason you must use \dfrac instead \frac; in the MWE some colors and rules modifications with tabu.

RESULT: enter image description here

MWE:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
\documentclass[letterpaper]{article}
\special{papersize=8.5in,11in}
\usepackage{indentfirst}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{gensymb}
\usepackage[margin=1in]{geometry}
\setlength{\parskip}{1em}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage{tabu}


\begin{document}

\begin{table}[!h]
\centering
\tabulinesep=5pt
\tabulinestyle{1pt,blue}
\begin{tabu} to 0.5\linewidth {|X[c]|X[c]|[0.75pt]X[c]|[0.75pt]X[c]|[0.75pt]X[c]|[0.75pt]X[c]|}
\rowfont{\leavevmode\color{white}}
\multicolumn{1}{c|}{}
&\cellcolor{blue!30}$0$ 
&\cellcolor{blue!40}$\dfrac{\pi}{6}$
&\cellcolor{blue!50}$\dfrac{\pi}{4}$
&\cellcolor{blue!60}$\dfrac{\pi}{6}$      
&\multicolumn{1}{c|}{\cellcolor{blue!70}$\dfrac{\pi}{2}$}
\\ \tabucline -

%row2
$\sin x$
&$0$
&$\dfrac{1}{2}$
&$\dfrac{\sqrt{2}}{2}$
&$\dfrac{\sqrt{3}}{2}$
&$1$
\\[-0.5pt] \tabucline [0.5pt on 3pt blue] -

%row3
$\cos x$
&$1$
&$\dfrac{\sqrt{3}}{2}$
&$\dfrac{\sqrt{2}}{2}$
&$\dfrac{1}{2}$
&$0$
\\[-0.5pt] \tabucline [0.5pt on 3pt blue] -

%row4
$\tan x$
& $0$
& $\dfrac{\sqrt{3}}{3}$
& $1$
& $\sqrt{3}$ 
&
\\ \tabucline -

\end{tabu}
\end{table}

\end{document}
2

An alternative solution with tblr environment of tabularray package: there is default rowsep=2pt with tblr environment.

\documentclass[letterpaper]{article}

\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}

\usepackage{tabularray}

\begin{document}

\begin{table}
\centering
$\begin{tblr}{|c|ccccc|} 
\hline
         &  0 & \frac{\pi}{6}      & \frac{\pi}{4}      & \frac{\pi}{6}      & \frac{\pi}{2}  \\ 
\hline
  \sin x & 0  & \frac{1}{2}        & \frac{\sqrt{2}}{2} & \frac{\sqrt{3}}{2} & 1  \\
  \cos x & 1  & \frac{\sqrt{3}}{2} & \frac{\sqrt{2}}{2} & \frac{1}{2}        & 0  \\
  \tan x & 0  & \frac{\sqrt{3}}{3} & 1                  & \sqrt{3}           &    \\
\hline
\end{tblr}$
\end{table}

\end{document}

enter image description here

1

In my opinion, cals, the packages bm and cmbright and some light colours, are improvements:

\documentclass[a4paper, 11pt]{article}
\usepackage{bm, cmbright, cals}
\usepackage[dvipsnames]{xcolor} 
\renewcommand{\sfdefault}{cmbr}
%\everymath{\displaystyle}                                  % Nicest without displaystyle?

\begin{document}
\begin{calstable}[c]
\colwidths{{56pt}{33pt}{33pt}{33pt}{33pt}{33pt}} % 6 columns
\makeatletter
\def\cals@framers@width{0.4pt}
\def\cals@framecs@width{0.4pt}
\cals@setpadding{Ag}
\cals@setcellprevdepth{Al}
\def\cals@cs@width{0.2pt}
\def\cals@rs@width{0.2pt}
\def\cals@bgcolor{}

\def\gray{\ifx\cals@bgcolor\empty
    \def\cals@bgcolor{gray!15}
\else \def\cals@bgcolor{} \fi}

\def\green{\ifx\cals@bgcolor\empty
    \def\cals@bgcolor{green!15}
\else \def\cals@bgcolor{} \fi}

\def\blue{\ifx\cals@bgcolor\empty
    \def\cals@bgcolor{blue!15}
\else \def\cals@bgcolor{} \fi}

\def\black{\ifx\cals@bgcolor\empty
    \def\cals@bgcolor{black}
\else \def\cals@bgcolor{} \fi}


% R1
\brow
    \gray\alignC\cell{\vfil \textbf{Radians}}\gray
    \green\alignC\cell{\vfil $0$}
    \alignC\cell{\vfil $\frac{\pi}{6}$}
    \alignC\cell{\vfil $\frac{\pi}{4}$}
    \alignC\cell{\vfil $\frac{\pi}{3}$}
    \alignC\cell{\vfil $\frac{\pi}{2}$}\green
    \ht\cals@current@row=33pt
\erow
% R3
\brow
    \blue\alignC\cell{\vfil \textbf{sin}($\bm{\theta}$)}\blue
    \alignC\cell{\vfil $0$}
    \alignC\cell{\vfil $\frac{1}{2}$}
    \alignC\cell{\vfil $\frac{\sqrt 2}{2}$}
    \alignC\cell{\vfil $\frac{\sqrt 3}{2}$}
    \alignC\cell{\vfil $1$}
    \ht\cals@current@row=33pt
\erow
% R4
\brow
    \blue\alignC\cell{\vfil \textbf{cos}($\bm{\theta}$)}\blue
    \alignC\cell{\vfil $1$}
    \alignC\cell{\vfil $\frac{\sqrt 3}{2}$}
    \alignC\cell{\vfil $\frac{\sqrt 2}{2}$}
    \alignC\cell{\vfil $\frac{1}{2}$}
    \alignC\cell{\vfil $0$}
    \ht\cals@current@row=33pt
\erow
% R5
\brow
    \blue\alignC\cell{\vfil \textbf{tan}($\bm{\theta}$)}\blue
    \alignC\cell{\vfil $0$}
    \alignC\cell{\vfil $\frac{\sqrt 3}{3}$}
    \alignC\cell{\vfil $1$}
    \alignC\cell{\vfil $\sqrt 3$}
    \black\alignC\cell{}\black
    \ht\cals@current@row=33pt
\erow\makeatother
\end{calstable}\par

\end{document}

enter image description here

0

In {NiceTabular} of nicematrix, vous have a key cell-space-limits. Here the output with that key set to 3 pt.

\documentclass[letterpaper]{article}

\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{nicematrix}

\begin{document}

\begin{table}
\centering
$\begin{NiceArray}{|c|ccccc|}[cell-space-limits=3pt]
\hline
         &  0 & \frac{\pi}{6}      & \frac{\pi}{4}      & \frac{\pi}{6}      & \frac{\pi}{2}  \\ 
\hline
  \sin x & 0  & \frac{1}{2}        & \frac{\sqrt{2}}{2} & \frac{\sqrt{3}}{2} & 1  \\
  \cos x & 1  & \frac{\sqrt{3}}{2} & \frac{\sqrt{2}}{2} & \frac{1}{2}        & 0  \\
  \tan x & 0  & \frac{\sqrt{3}}{3} & 1                  & \sqrt{3}           &    \\
\hline
\end{NiceArray}$
\end{table}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

You must log in to answer this question.

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