Drawing Charts (Part 1) - Basics

Drawing Charts (Part 1): Basics #

Author: Er Hua

Table is a two-dimensional form of information representation in LaTeX.

Basic Table Drawing #

  • Use the tabular environment for general table arrangement.
  • Use the array environment for arranging content with mathematical symbols.
\begin{tabular}[alignment (optional, can be t or b)]{column format (lcr or other forms)}
content & content & ... & content \\
...
\end{tabular}
\begin{array}[alignment]{column format}
content & content & ... & content \\
...
\end{array}

Here, \\ denotes a line break, and & is used to separate different cells.

Both tabular and array represent normal boxes, so they can be mixed with other text or formulas. We can place them in a floating object to avoid this.

Here is an example of a normal table:

\documentclass[a4paper]{article}
\usepackage{ctex}

\begin{document}
\begin{tabular}{|c|ccc|p{3cm}|}
\hline
empty & eat & drink & play & fun \\
\hline
Zhang San & fish & wine & guitar & make money \\
Li Si & meat & water & code & make money \\
Wang Ma Zi & seafood & drink & badminton & make money \\
\hline
\end{tabular}
\end{document}

Here is an example of a determinant:

\documentclass[]{article}
\usepackage{ctex}
\begin{document}

$\left (
\begin{tabular}{lcc|r}
    & eat & drink & play \\
Zhang San & fish & wine & guitar \\
Li Si & meat & water & code \\
Wang Ma Zi & seafood & drink & badminton \\
\end{tabular}
\right ) $
\end{document}


Methods to Change the Spacing Between Rows and Columns

Column spacing: Half of the minimum distance is controlled by the variables \tabcolsep and \arraycolsep.

Row spacing: Controlled by the macro \arraystretch.

\documentclass [border={30mm 3mm 30mm 3mm}]{standalone}
\usepackage{ctex}
\begin{document}
%---------------
%\arraystretch is a macro, and its default value is 1. By modifying it as follows, you can change the spacing multiple.
\renewcommand\arraystretch{2}
\setlength\tabcolsep{10mm}
%\tabcolsep is a variable, and you assign a specific value to it.
%---------------
$\left (
\begin{tabular}{lcc|r}
    & eat & drink & play \\
Zhang San & fish & wine & guitar \\
Li Si & meat & water & code \\
Wang Ma Zi & seafood & drink & badminton \\
\end{tabular}
\right ) $
\end{document}

NOTICE:

\arraystretch is a macro, so use \renewcommand to set it.

\tabcolsep is a variable, so use \setlength to set it.