LaTeX table custom row height + custom column width + large table adaptive page width

1. Custom row height

        Default line height effect

        Custom line height effect: it looks more beautiful and generous

        Implementation method: Insert the command \renewcommand\arraystretch{1.5} between \begin{table} and \begin{tabular} in the LaTeX table , where the value of 1.5 can be customized, the larger the value, the higher the table.

        The LaTeX code for the above custom line height effect is as follows

\documentclass{article}

\begin{document}

\begin{table}
\centering
\caption{A Table Demo}
\label{tab_demo}
\renewcommand\arraystretch{1.5}
\begin{tabular}{ccccccc}
\hline
Animal & Weight & Color & Weight & Color & Weight & Color \\
\hline
Dog  & 20.1 & White  & 18.0 & Gray  & 30.5 & Black \\
Cat  & 10.2 & Yellow & 11.2 & Black & 11.5 & White \\
Fox  & 15.5 & Gold   & 15.6 & Gold  & 16.5 & Gold  \\
Duck & 2.4  & White  & 3.0  & White & 4.0  & White \\
\hline
\end{tabular}
\end{table}

\end{document}

2. Custom column width

        Default column width effect

        Custom column width effect: wider

        Implementation method (need to import the graphicx package: \usepackage{graphicx} ): Insert the command \tabcolsep=0.35cm between \begin{table} and \begin{tabular} in the LaTeX table , where 0.35cm is a custom width. The larger the value, the longer the table.

        The LaTeX code for the above custom column width effect is as follows

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\begin{table}
\centering
\caption{A Table Demo}
\label{tab_demo}
\tabcolsep=0.35cm
\begin{tabular}{ccccccc}
\hline
Animal & Weight & Color & Weight & Color & Weight & Color \\
\hline
Dog  & 20.1 & White  & 18.0 & Gray  & 30.5 & Black \\
Cat  & 10.2 & Yellow & 11.2 & Black & 11.5 & White \\
Fox  & 15.5 & Gold   & 15.6 & Gold  & 16.5 & Gold  \\
Duck & 2.4  & White  & 3.0  & White & 4.0  & White \\
\hline
\end{tabular}
\end{table}

\end{document}

3. Adaptive page width for large tables

        The default effect of large tables: too big, not centered, giving people a feeling of crossing the border, ugly

        Large table adaptive page width effect: centered display, table width = page width, looks more beautiful and pleasing to the eye

        Implementation method (the graphicx package needs to be imported: \usepackage{graphicx} ): Use the \resizebox{1.0\linewidth}{!} command to surround the content of the tabular , where 1.0 means to set the width of the table to the page width ( linewidth ); if it is If it is 0.8, the width of the table will be set to 80% of the page width; similarly, the smaller the value, the smaller the table width; of course, you can also set a number larger than 1.0, but that is not beautiful enough, because It will also give people the feeling that the form is out of bounds.

        The above LaTeX code to realize the adaptive page width effect of large tables is as follows

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\begin{table}
\centering
\caption{A Table Demo}
\label{tab_demo}
\resizebox{1.0\linewidth}{!}{
\begin{tabular}{ccccccccccc}
\hline
Animal & Weight & Color & Weight & Color & Weight & Color & Weight & Color & Weight & Color\\
\hline
Dog  & 20.1 & White  & 18.0 & Gray  & 30.5 & Black & 30.5 & Black& 30.5 & Black\\
Cat  & 10.2 & Yellow & 11.2 & Black & 11.5 & White & 11.5 & White& 11.5 & White\\
Fox  & 15.5 & Gold   & 15.6 & Gold  & 16.5 & Gold  & 16.5 & Gold & 16.5 & Gold\\
Duck & 2.4  & White  & 3.0  & White & 4.0  & White & 4.0  & White& 4.0  & White\\
\hline
\end{tabular}
}
\end{table}

\end{document}

Guess you like

Origin blog.csdn.net/qq_36158230/article/details/129351744