增加列宽

增加列宽

梅威瑟:

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{parskip}
\usepackage{graphicx}
\usepackage[top=0.65 in,bottom=0.65 in,left=0.65 in,right=0.65in]{geometry}
\renewcommand{\baselinestretch}{1.20}

\begin{document}
    \begin{center}
    %\setlength\extrarowheight{5pt}
    \begin{tabular}[t]{|c|c|c|c|c|c|c|c|c|c|c|}
        \hline
        Question                & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10            \\\hline
        Answer                  &   &   &   &   &   &   &   &   &   &              \\\hline
        \end{tabular}
\end{center}
\end{document} 

问题:如何增加表格中列的宽度?

答案1

明确设置长度或使用tabularx

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{parskip}
\usepackage{graphicx}
\usepackage[top=0.65 in,bottom=0.65 in,left=0.65 in,right=0.65in]{geometry}
\renewcommand{\baselinestretch}{1.20}

\usepackage{array}
\usepackage{tabularx}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\usepackage{booktabs}

\begin{document}

Set a length explicitly:

\begin{center}
    \begin{tabular}[t]{|c|*{10}{C{.4in}|}}
        \hline
        Question                & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10            \\\hline
        Answer                  &   &   &   &   &   &   &   &   &   &              \\\hline
        \end{tabular}
\end{center}

Or use \texttt{tabularx}:

\begin{center}
    \begin{tabularx}{\textwidth}{|c|*{10}{Y|}}
        \hline
        Question                & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10            \\\hline
        Answer                  &   &   &   &   &   &   &   &   &   &              \\\hline
    \end{tabularx}
\end{center}

This is just to show the canonical way to typeset tables with \texttt{booktabs}, as suggested by Peter Grill:

\begin{center}
    \begin{tabularx}{\textwidth}{c*{10}{Y}}
        \toprule
        Question                & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10            \\
        \midrule
        Answer                  &   &   &   &   &   &   &   &   &   &              \\
        \bottomrule
    \end{tabularx}
\end{center}
\end{document}

在此处输入图片描述

编辑:设置列高的一种方法是使用 和\setcellgapes, 其他方法请参见此处:\makegapedcellsmakecell表格中的列和行填充

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{parskip}
\usepackage{graphicx}
\usepackage[top=0.65 in,bottom=0.65 in,left=0.65 in,right=0.65in]{geometry}
\renewcommand{\baselinestretch}{1.20}

\usepackage{array}
\usepackage{tabularx}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\usepackage{booktabs}
\usepackage{makecell}
\setcellgapes{.1in}

\begin{document}

Set a length explicitly:

\begin{center}
\makegapedcells
    \begin{tabular}[t]{|c|*{10}{C{.4in}|}}
        \hline
        Question                & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10            \\\hline
        Answer                  &   &   &   &   &   &   &   &   &   &              \\\hline
        \end{tabular}
\end{center}

Or use \texttt{tabularx}:

\begin{center}
\makegapedcells
    \begin{tabularx}{\textwidth}{|c|*{10}{Y|}}
        \hline
        Question                & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10            \\\hline
        Answer                  &   &   &   &   &   &   &   &   &   &              \\\hline
    \end{tabularx}
\end{center}

This is just to show the canonical way to typeset tables with \texttt{booktabs}, as suggested by Peter Grill:

\begin{center}
    \makegapedcells
    \begin{tabularx}{\textwidth}{c*{10}{Y}}
        \toprule
        Question                & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10            \\
        \midrule
        Answer                  &   &   &   &   &   &   &   &   &   &              \\
        \bottomrule
    \end{tabularx}
\end{center}
\end{document}

在此处输入图片描述

答案2

您可以通过增加来使列宽\tabcolsep。以下是使用 前后的表格版本\setlength{\tabcolsep}{10pt}

在此处输入图片描述

另外,我建议您查看软件包booktabs和相关文档。这是一个最小示例,因为您的表实际上没有任何数据:

在此处输入图片描述

笔记:

  • 我删除了{center}应该使用的环境\centering。请参阅我应该对图形和表格使用 center 还是 centering ?

    正如 CarLaTeX 提到的,使用问题中给出的 MWE,可以使用环境{center}(因为它不使用环境table)。但是,大多数人会使用tablearound tabular,所以认为应该指出这一点。

代码:

\documentclass{article} 

\renewcommand{\baselinestretch}{1.20}

\begin{document}
\begin{tabular}[t]{|c|c|c|c|c|c|c|c|c|c|c|} 
\hline
 Question & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\\hline 
Answer & & & & & & & & & & \\\hline 
\end{tabular}  

\begingroup
\setlength{\tabcolsep}{10pt}%
\begin{tabular}[t]{|c|c|c|c|c|c|c|c|c|c|c|} 
\hline
 Question & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\\hline 
Answer & & & & & & & & & & \\\hline 
\end{tabular}  
\endgroup
\end{document}

代码:booktabs

\documentclass{article} 
\usepackage{booktabs}

\begin{document}
\begin{tabular}[t]{lcccccccccc} 
\toprule
Question & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\
%\cmidrule(lr){1-11}% <-- Not very useful here.
Answer & & & & & & & & & & \\
\bottomrule 
\end{tabular}  
\end{document}

相关内容