双列环境中表格未居中

双列环境中表格未居中

我正在编写一个双表格式的实验室。我试图添加一个比 \textwidth 更宽的表,并希望它均匀地溢出到两个边距。我必须做什么?到目前为止我有这个:

\centering
    \begin{tabular}{|| c | c || c | c || c | c || c | c ||}
    \hline
        \multicolumn{2}{||c||}{Trial 1} & \multicolumn{2}{c||}{Trial 2} & \multicolumn{2}{c||}{Trial 3} & \multicolumn{2}{c||}{Trial 4}\\
    \hline
        Distance (m) &     Force (N)    & Distance (m) &    Force (N)   &  Distance (m)  &   Force (N)  & Distance (m)  &  Force (N)   \\
    \hline
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
    \hline
    \end{tabular}
\caption{Force and Distance Data for Trials I-IV}
\label{tab:1}
\end{table*}```

答案1

您没有指明使用的是哪种文档类别、哪种字体或哪种主字体大小。我们也不知道文档的文本块有多宽。您提供的唯一“元信息”是您使用了两列布局和环境table*

如果您呈现的表格材料无法容纳在文本块的宽度内,请考虑将单位指示(米和牛顿)放在“距离”和“力”下方的单独行上。

如果您希望表格占据文本块的整个宽度,我建议您使用环境,tabular*因为不需要在单元格内自动换行。

无论如何,我会努力通过省略所有垂直线并使用少量但间距适当的水平线来为表格提供开放和吸引人的“外观”。

在此处输入图片描述

\documentclass[twocolumn]{article} % or some other suitable document class
\usepackage{booktabs} % for well-spaced horizontal lines
\newcommand\mc[1]{\multicolumn{2}{c}{#1}} % handy shortcut macro

\begin{document}
\begin{table*}
\centering
\begin{tabular}{@{} *{8}{c} @{}} % 8 centered columns
\toprule
\mc{Trial 1} & \mc{Trial 2} & \mc{Trial 3} & \mc{Trial 4}\\
\cmidrule(r){1-2} \cmidrule(lr){3-4} \cmidrule(lr){5-6} \cmidrule(l){7-8} 
Distance & Force & Distance & Force & Distance & Force & Distance & Force \\  
(m) & (N) & (m) & (N) & (m) & (N) & (m) & (N) \\
\midrule
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\ \addlinespace
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
\bottomrule
\end{tabular}

\bigskip
\setlength\tabcolsep{0pt} % let LaTeX determine intercolumn whitespace
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} *{8}{c} }
\toprule
\mc{Trial 1} & \mc{Trial 2} & \mc{Trial 3} & \mc{Trial 4}\\
\cmidrule{1-2} \cmidrule{3-4} \cmidrule{5-6} \cmidrule{7-8} 
Distance & Force & Distance & Force & Distance & Force & Distance & Force \\  
(m) & (N) & (m) & (N) & (m) & (N) & (m) & (N) \\
\midrule
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\ \addlinespace
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
\bottomrule
\end{tabular*}

\caption{Force and Distance Data for Trials I--IV}
\label{tab:1}
\end{table*}
\end{document}

答案2

  • 由于缺乏有关文档布局的信息,表格的实际内容示例几乎无法为您提供帮助。您应该将不完整的表格代码片段扩展为包含表格的完整小文档,我们可以按原样进行编译。
  • 作为起点,它可能服务于以下 MWE (最小工作示例):
\documentclass[twocolumn]{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{makecell}
\usepackage{xparse}
\NewExpandableDocumentCommand\mcc{O{c||}m}
    {\multicolumn{2}{#1}{#2}}

\begin{document}
\begin{table*}
  \centering
    \begin{tabular}{|| c | c || c | c || c | c || c | c ||}
    \hline
\mcc[||c||]{Trial 1} 
        &   \mcc{Trial 2} 
                &   \mcc{Trial 3}   
                        &   \mcc{Trial 4}   \\
    \hline
\makecell{Distance\\ (m)} 
    &   \makecell{Force\\ (N)}    
        &   \makecell{Distance\\ (m)} 
            &   \makecell{Force\\ (N)}  
                &  \makecell{Distance\\ (m)}  
                    &   \makecell{Force\\ (N)}  
                        &   \makecell{Distance\\ (m)}
                             &      \makecell{Force\\ (N)}      \\
    \hline
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
    \hline
    \end{tabular}
\caption{Force and Distance Data for Trials I-IV}
\label{tab:1}
    \end{table*}
\end{document}

在此处输入图片描述

(红线表示文字边框)

编辑: 另一种可能性是使用tabularx

\documentclass[twocolumn]{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{makecell, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage{xparse}
\NewExpandableDocumentCommand\mcc{O{c||}m}
    {\multicolumn{2}{#1}{#2}}

\begin{document}
\begin{table*}
  \centering
    \begin{tabularx}{\linewidth}{|| C | C || C | C || C | C || C | C ||}
    \hline
\mcc[||c||]{Trial 1} 
        &   \mcc{Trial 2} 
                &   \mcc{Trial 3}   
                        &   \mcc{Trial 4}   \\
    \hline
{Distance (m)} 
    &   {Force\newline (N)}    
        &   {Distance (m)} 
            &   {Force\newline (N)}  
                &  {Distance (m)}  
                    &   {Force\newline (N)}  
                        &   {Distance (m)}
                             &  {Force\newline (N)}      \\
    \hline
    1   &   2   &   3   &   4   &   5   &   6   &   7   &   8   \\
    1   &   2   &   3   &   4   &   5   &   6   &   7   &   8   \\
    \hline
    \end{tabularx}
\caption{Force and Distance Data for Trials I-IV}
\label{tab:1}
    \end{table*}
\end{document}

在此处输入图片描述

注意:在两种情况下,表格都将出现在下一页的顶部,并从那里插入到文档文本中。

答案3

您会发现,完整的 MWE 可以让我们更轻松地为您提供帮助。不过,在这种情况下,问题很容易诊断:您的tabular比 更宽,\textwidth因此默认情况下它会进入右边距。处理此问题的常见提示是我的桌子放不下;我有什么办法吗?

答案4

如果您确实需要表格那么宽,那么请使用可用于临时延长或缩小的chngpage包和环境。adjustwidth\textwidth

% widetableprob.tex  SE 564251
\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage{chngpage}

\begin{document}
\lipsum

\begin{table*}
\begin{adjustwidth}{-1cm}{-1cm}
\centering
    \begin{tabular}{|| c | c || c | c || c | c || c | c ||}
    \hline
        \multicolumn{2}{||c||}{Trial 1} & \multicolumn{2}{c||}{Trial 2} & \multicolumn{2}{c||}{Trial 3} & \multicolumn{2}{c||}{Trial 4}\\
    \hline
        Distance (m) &     Force (N)    & Distance (m) &    Force (N)   &  Distance (m)  &   Force (N)  & Distance (m)  &  Force (N)   \\
    \hline
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
        1            &         2        &      3       &       4        &        5       &       6      &       7       &         8    \\
    \hline
    \end{tabular}
\caption{Force and Distance Data for Trials I-IV}
\label{tab:1}
\end{adjustwidth}
\end{table*}

\lipsum
\end{document}

相关内容