Table Drawing ( II ) Advanced

Table Drawing ( II ): Advanced #

Author: Erhua

Keywords: cell merge and split, fixed-width table

In the previous section, we discussed the most basic part of drawing tables, and this section talks about cell merging and splitting and widening tables.

Merging and splitting cells #

Sometimes we will encounter the situation where we want to merge several cells into one cell, using the following method

  • for different cells in the same row use the command \multicolumn {combine the number of cells} {left-justified, centered, right-justified, etc. options} {cell content}
  • For same column different cells merge use the macro package \multirow{number of rows}*{content}, note that, *must be in
\documentclass [border={30mm 3mm 30mm 3pt}]{standalone}
\\usepackage{multirow}
\usepackage{ctex}
\begin{document}
\begin{tabular}{|l|c|c|r|}
\hline
\multirow{2}*{name}&\multicolumn{3}{|c|}{items}\\\
\cline{2-4}
    &eat&drink&play\\\\
\hline
Zhang San&fish&wine&guitar\\\
Li Si&meat&water&code\\\
Wang Ma Zi&seafood&drink&badminton\\\
\hline

\end{tabular}
\end{document}

Key points.

The key points of this figure are the following.

  • \multicolumn{3}{|c|}{project} in {|c|} with a vertical line to have, when the default is not written, there is no line within the table.
  • \cline{2-4} used to merge different rows of cells after the delineation of incomplete or interrupted dividing lines.

the top and leftmost rows of the table can be controlled separately with a special macro package: \makecell macro package

free line breaks in, makecell{ } with \\

The slash splitting of the table header is done using another macro package: \diagbox macro package

  • \diagbox{left}{right}
  • \diagbox{left}{center}{right}
\documentclass [border={30mm 3pt 30mm 3pt}]{standalone}
\\usepackage{multirow}
\usepackage{diagbox}
\usepackage{ctex}
\begin{document}
\begin{tabular}{|l|c|c|r|}
\hline
\diagbox{name}{item} & eat&drink&play\\
\hline
Zhang San&fish&wine&guitar\\\
Li Si&meat&water&code\\\
Wang Ma Zi&seafood&drink&badminton\\\
\hline
\end{tabular}
\end{document}

The solution can be found here http://latex.lierhua.top/docs/%E4%B9%A0%E9%A2%98%E7%AD%94%E6%A1%88/

Research Thesis Trilinear Table #

A general college thesis usually requires the table to be set up as a three-line table. The lines at the top and bottom of the three-line table are thicker and the middle is thinner, and the ratio of thickness is specified by each institution.

The three-line table requires the use of the booktabs macro package.

\toprule: top line, with an optional parameter to change the thickness of the top line, toprule[line width]
\midrule: midrule
\bottomrule: bottomrule
\cmidrule: partial midrule
\documentclass [border={30mm 3pt 30mm 3pt}]{standalone}
\\usepackage{diagbox}
\usepackage{booktabs}
\usepackage{ctex}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\textwidth}{c|X|X|X|X|X|X|X}
\toprule [1mm]
% Use the default width when not adding [1mm
\diagbox{item}{date}&Monday&Tuesday&Wednesday&Thursday&Friday&Saturday&Weekday,\
\midrule
Table tennis&1&2&4&1&7&3&6\\
Badminton&6&0&8&1&2&5&8\
\bottomrule [1mm]
\end{tabularx}
\end{document}

\documentclass [border={30mm 3pt 30mm 3pt}]{standalone}
\\usepackage{diagbox}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{ctex}
\usepackage{tabularx}
\begin{document}
\begin{tabular}{c|ccccccc}
\toprule
\multirow{2}*{\diagbox{item}{date}}&\multicolumn{1}{c}{male}&\multicolumn{2}{c}{female}\\
\cmidrule{2-2}\cmidrule{3-4}
    & Li Si & Zhang San & Wang Ma Zi \\
\midrule
Table tennis&1&2&4\\\\
Badminton&6&0&8\\\
\bottomrule
\end{tabular}
\end{document}

Use of fixed-width tables #

LaTeX’s tabular* environment can produce fixed-width tables, and we commonly use the tabularx environment provided by tabularx to achieve the same effect as the tabular* environment, which provides a column formatting descriptor called X (in the same place as clr).

The macro package environment is as follows.

\usepackage{tabularx}
\begin{tabularx}{width}[vertically aligned]{column format specifier ( c,l,r,X,p{width} )}
%\begin{tabularx}{\textwidth}[vertically aligned]{|c|l|r|X|p{10pt}|}
\end{tabularx}
\documentclass [border={30mm 3pt 30mm 3pt}]{standalone}
\usepackage{diagbox}
\usepackage{ctex}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\textwidth}{c|X|X|X|X|X|X|X}
\hline
\diagbox{item}{date}&Monday&Tuesday&Wednesday&Thursday&Friday&Saturday&Weekday\\
\hline
Table tennis&1&2&4&set&a&validation&auto&line&7&3&6\\
Badminton&6&0&8&1&2&5&8\
\hline
\end{tabularx}
\end{document}

Use of long tables #

As we have said before, a table is actually a box, so a table that does not exceed one page will actually be less suitable for typesetting if he does not put it in a floating body environment. However, long tables are very long, even more than one page, so LaTeX has a macro package for dealing with long tables: the longtable macro package. The use of long tables is described in the longtable macro package.

tips #

CTAN forum provides a small plug-in for creating tables: excel2latex, you can check it out at the following address https://www.ctan.org/tex-archive/support/excel2latex/