1

I'm writing a lab in two table format. I'm trying to add a table that's wider than \textwidth, and would like for it to spill onto both margins equally. What do I have to do? So far I have this:

\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*}```

3
  • 1
    Welcome to TeX.SE.
    – Mico
    Sep 26, 2020 at 8:54
  • 1
    Thank you @Mico ! I've been using it as reference for quite some time now, but hadn't had the need to ask anything since it seems like ya'll have figured out everything already! It was nice having someone take the time to answer my specific query, so thank you =)
    – Alex D
    Oct 3, 2020 at 4:40
  • You're most welcome!
    – Mico
    Oct 3, 2020 at 5:48

4 Answers 4

2

You haven't indicated which document class, which fonts, or which main font size are in use. We also don't know how wide the text block of your document is. The only "meta information" you've provided, then, is that you use a two-column layout and a table* environment.

If the tabular material you've presented won't fit inside the width of the text block, consider placing the unit indications (meters and Newton) on a separate line, below "Distance" and "Force".

If you want the table to take up the full width of the text block, I would suggest you employ a tabular* environment since automatic line breaking within cells isn't needed.

At any rate, I would strive to give the table an open and inviting "look" by omitting all vertical lines and using few, but well spaced horizontal lines.

enter image description here

\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}
1
  • I definitely agree insofar as it's more inviting and appealing. Thank you so much for the answer!
    – Alex D
    Oct 3, 2020 at 2:57
1
  • Due to lack of information about your document layout and example of real content of table is almost impossible to help you. You should extend incomplete table code fragment to complete small document with your table, which we can compile as it is.
  • As starting point it may serve the following MWE (Minimal Working Example}:
\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}

enter image description here

(red lines shows text borders)

Edit: Another possibilities is use 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}

enter image description here

Note: In both case table will appear on the top of the next page from where it will be inserted in your document text.

0

You'll find that a complete MWE can make it easier for us to help you. In this instance though, the issue was easy enough to diagnose: Your tabular is wider than the \textwidth so it goes into the right margin by default. The common pointer on tips for dealing with this is My table doesn't fit; what are my options?

2
  • Thank you for taking time to answer my question Don. I understand the problem, thank you. Is there any way to center it in a way such that the table spills onto both margins equally? I've updated my question to reflect this change.
    – Alex D
    Sep 26, 2020 at 3:08
  • @AlexD To get what you want, you could do something like \newcommand{\mycentering}{\centering\leftskip=0pt plus1fil minus1fil \rightskip=\leftskip} and use \mycentering in place of \centering. This will spill into both margins but without limit which could be undesirable. You could change the minus1fil to e.g., minus0.5in to limit it to a specific amount, but in general you probably want to stay inside your margins.
    – Don Hosek
    Sep 26, 2020 at 14:34
0

If you really really need the table to be as wide then use the chngpage package and the adjustwidth environment which can be used to temporarily extend or narrow the \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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .