如何更改表格行高?

如何更改表格行高?

我的问题是,如何更改表格中行高?

梅威瑟:

\documentclass[12pt, a4paper]{article}
\usepackage[top=0.7 in,bottom=0.7 in,left=0.7 in,right=0.7 in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,shapes}
\usepackage{parskip}
\usepackage{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
%reduce top margin
\addtolength{\headsep}{-0.5cm}
%for line spacing
\usepackage{setspace}

\renewcommand{\baselinestretch}{0.7} 
\begin{document}
\large
\begin{center}
    \begin{tabular}{|Sc|Sc|}
        \hline
        \textbf{Natural number} & \textbf{Cube} \\ \hline
        1 & $1^3 = 1\times 1\times 1 = 1$  \\ \hline
        2 & $2^3 = 2\times 2\times 2 = 8$  \\ \hline
        3 & $3^3 = 3\times 3\times 3 = 27$  \\ \hline
        4 & $4^3 = 4\times 4\times 4 = 64$   \\ \hline
        5 & $5^3 = 5\times 5\times 5 = 125$  \\ \hline
        6 & $6^3 = 6\times 6\times 6 = 216$  \\ \hline
        7 & $7^3 = 7\times 7\times 7 = 343$  \\ \hline
        8 & $8^3 = 8\times 8\times 8 = 512$   \\ \hline
        9 & $9^3 = 9\times 9\times 9 = 729$  \\ \hline
        10 & $10^3 = 10\times 10\times 10 = 1000$  \\ \hline
        \end{tabular}
\end{center}
\end{document}

答案1

只需修改\arraystretch

\documentclass[12pt, a4paper]{article}
\usepackage[top=0.7 in,bottom=0.7 in,left=0.7 in,right=0.7 in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,shapes}
\usepackage{parskip}
\usepackage{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
%reduce top margin
\addtolength{\headsep}{-0.5cm}
%for line spacing
\usepackage{setspace}

\renewcommand{\baselinestretch}{0.7}
\renewcommand{\arraystretch}{1.2} % <--------------
\begin{document}
\large
\begin{center}
    \begin{tabular}{|Sc|Sc|}
        \hline
        \textbf{Natural number} & \textbf{Cube} \\ \hline
        1 & $1^3 = 1\times 1\times 1 = 1$  \\ \hline
        2 & $2^3 = 2\times 2\times 2 = 8$  \\ \hline
        3 & $3^3 = 3\times 3\times 3 = 27$  \\ \hline
        4 & $4^3 = 4\times 4\times 4 = 64$   \\ \hline
        5 & $5^3 = 5\times 5\times 5 = 125$  \\ \hline
        6 & $6^3 = 6\times 6\times 6 = 216$  \\ \hline
        7 & $7^3 = 7\times 7\times 7 = 343$  \\ \hline
        8 & $8^3 = 8\times 8\times 8 = 512$   \\ \hline
        9 & $9^3 = 9\times 9\times 9 = 729$  \\ \hline
        10 & $10^3 = 10\times 10\times 10 = 1000$  \\ \hline
        \end{tabular}
\end{center}
\end{document}

答案2

如果您想增加行高,同时使单元格内容垂直居中,您可以更改 的值cellspacetop/bottomlimit,因为您已经使用了cellspace。或者,您可以加载makecell,为 固定一个值\setcellgapes,然后使用 使其生效\makegapedcells

注意两种方式的区别在于,在以字母为前缀的说明符的列中cellspace设置minimal单元格顶部和底部的垂直填充S(或者C如果你使用siunitx),而makecell 添加固定的垂直填充:

\documentclass[12pt, a4paper]{article}
\usepackage[top=0.7 in,bottom=0.7 in,left=0.7 in,right=0.7 in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{parskip}
\usepackage{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\usepackage{makecell}
%reduce top margin
\addtolength{\headsep}{-0.5cm}
%for line spacing
\usepackage{setspace}
\setstretch{0.7}

\begin{document}

\large
\begin{center}
\setlength\cellspacetoplimit{12pt}
\setlength\cellspacebottomlimit{12pt}
    \begin{tabular}{|Sc|Sc|}
        \hline
        \textbf{Natural number} & \textbf{Cube} \\ \hline
        1 & $1^3 = 1\times 1\times 1 = 1$ \\ \hline
        2 & $2^3 = 2\times 2\times 2 = 8$ \\ \hline
        3 & $3^3 = 3\times 3\times 3 = 27$ \\ \hline
        4 & $4^3 = 4\times 4\times 4 = 64$ \\ \hline
        5 & $5^3 = 5\times 5\times 5 = 125$ \\ \hline
        6 & $6^3 = 6\times 6\times 6 = 216$ \\ \hline
        7 & $7^3 = 7\times 7\times 7 = 343$ \\ \hline
        8 & $8^3 = 8\times 8\times 8 = 512$ \\ \hline
        9 & $9^3 = 9\times 9\times 9 = 729$ \\ \hline
        10 & $10^3 = 10\times 10\times 10 = 1000$ \\ \hline
        \end{tabular}
\end{center}
%%%
\begin{center}
\setcellgapes{12pt}
\makegapedcells
    \begin{tabular}{|c|c|}
        \hline
        \textbf{Natural number} & \textbf{Cube} \\ \hline
        1 & $1^3 = 1\times 1\times 1 = 1$ \\ \hline
        2 & $2^3 = 2\times 2\times 2 = 8$ \\ \hline
        3 & $3^3 = 3\times 3\times 3 = 27$ \\ \hline
        4 & $4^3 = 4\times 4\times 4 = 64$ \\ \hline
        5 & $5^3 = 5\times 5\times 5 = 125$ \\ \hline
        6 & $6^3 = 6\times 6\times 6 = 216$ \\ \hline
        7 & $7^3 = 7\times 7\times 7 = 343$ \\ \hline
        8 & $8^3 = 8\times 8\times 8 = 512$ \\ \hline
        9 & $9^3 = 9\times 9\times 9 = 729$ \\ \hline
        10 & $10^3 = 10\times 10\times 10 = 1000$ \\ \hline
        \end{tabular}
\end{center}

\end{document} 

在此处输入图片描述

相关内容