使用 tabularx 表环境指定列宽

使用 tabularx 表环境指定列宽

我正在用 LaTeX 处理一个复杂的文档,里面有各种类型的表格。我希望第二列更宽,第三列更窄。我尝试了不同的想法来处理这个代码块{c *6{>{}X}}

我正在考虑宽度的类似内容:第一列 25pts,第二列 300pts,最后一列 80pts。这个想法是在表格环境中定义列宽,而不是在文档序言中。我查看了手册tabularx,这里的一些帖子,我想看看表格语法的完整示例,如下所示。

\begin{table}[!htbp] 
\setlength{\tabcolsep}{6pt}
{\tabcolsep=0pt\def\arraystretch{1}
    \caption{caption} \label{tab:some-table}
    \begin{tabularx}{\textwidth}{c *6{>{}X}}\midrule
        & \centering\hspace{-1in} some text & \centering\hspace{-0.75in} some text \tabularnewline\midrule 
        1 \hspace{12pt}  & some very very long text and much much more text & \multirow{5}{\linewidth}{some text}\tabularnewline 
        2 \hspace{12pt}  & some text  & \tabularnewline
        3 \hspace{12pt}  & some text   &  \tabularnewline
        4 \hspace{12pt}  & some text  &   \tabularnewline
        5 \hspace{12pt}  & some text &  \tabularnewline
        \midrule
\end{tabularx}}
\end{table}

答案1

这是您的表格的三个版本。在第一个版本中,我使用了 regulattabular环境,其列宽与您在问题中指定的一样。但是,表格比文本宽度大很多(至少是标准文章类的文本宽度;用红线表示)。因此,我建议使用tabularx一个或两个X类型的列。哪个更好取决于实际表格的内容。我还分别用和替换了两个\midrule命令。为了使列标题相对于相应列水平居中,我使用了包中的命令:\toprule\bottomrule\theadmakecell

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx}

\usepackage{multirow}
\usepackage{booktabs}

\usepackage{makecell}
\renewcommand{\theadfont}{\normalfont}

\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}
\begin{document}

\begin{table}[!htbp] 
    \caption{caption} \label{tab:some-table}
    \begin{tabular}{p{25pt}p{300pt}p{80pt}}
    \toprule
        & \thead{some text} & \thead{some text} \\
    \midrule 
        1  & some very very long text and much much more text & \multirow{5}{*}{some text} \\ 
        2  & some text & \\
        3  & some text & \\
        4  & some text & \\
        5  & some text & \\
        \bottomrule
\end{tabular}
\end{table}

\begin{table}[!htbp] 
    \caption{caption} \label{tab:some-table}
    \begin{tabularx}{\textwidth}{cXX}
    \toprule
        & \thead{some text} & \thead{some text} \\
    \midrule 
        1  & some very very long text and much much more text & \multirow{5}{*}{some text} \\ 
        2  & some text & \\
        3  & some text & \\
        4  & some text & \\
        5  & some text & \\
        \bottomrule
\end{tabularx}
\end{table}

\begin{table}[!htbp] 
    \caption{caption} \label{tab:some-table}
    \begin{tabularx}{\textwidth}{cXl}
    \toprule
        & \thead{some text} & \thead{some text} \\
    \midrule 
        1  & some very very long text and much much more text & \multirow{5}{*}{some text} \\ 
        2  & some text & \\
        3  & some text & \\
        4  & some text & \\
        5  & some text & \\
        \bottomrule
\end{tabularx}
\end{table}
\end{document}

使用文档类更新apa6:我已经使用了\multirow{6}{=}{...}6由于列的内容总共占用 6 行,因此需要垂直居中文本。=确保文本的宽度与对应的列一样宽。

\documentclass[doc,natbib,floatsintext,12pt,noextraspace]{apa6}
\shorttitle{short title}
\usepackage{tabularx}

\usepackage{multirow}
\usepackage{booktabs}

\usepackage{makecell}
\renewcommand{\theadfont}{\normalfont}

\begin{document}


\begin{table}[!htbp] 
    \caption{caption} \label{tab:some-table}
    \begin{tabularx}{\textwidth}{cXX}
    \toprule
        & \thead{some text} & \thead{some text} \\
    \midrule 
        1  & some very very long text and much much more text & \multirow{6}{=}{some text some text some text some text some text some text some text some text some text} \\ 
        2  & some text & \\
        3  & some text & \\
        4  & some text & \\
        5  & some text & \\
        \bottomrule
\end{tabularx}
\end{table}

\end{document}

在此处输入图片描述

相关内容