0

I have a problem when using multicolumn{}{}{} which causes the last column multicolumn takes to take more space than it needs.

This looks odd and in my case causes my table to span more than the width of the actual page.

It looks like this:

enter image description here

As you can see in the table above: "Trial 3" takes up more space than it needs which causes the last column to be out of the page's margin.

Code:

  \begin{table}
    \begin{tabular}{|c|c|c|c|c|c|c|}
      \hline
      \multirow{2}{*}{$\theta^\circ$} & \multirow{2}{*}{$\pm\delta\theta^\circ$}& \multicolumn{3}{c|}{Horizontal Displacement (m$\pm$0.1m)} & \multirow{2}{*}{Mean (m)} & \multirow{2}{*}{Mean Uncertainty ($\pm\delta$m)}\\\cline{3-5}
      & & Trial 1 & Trial 2 & Trial 3 & &\\
      \hline\hline
      25 & 0.41 & 6.3 & 12.0 & 13.7 & 10.7 & 2.9\\
      \hline
      30 & 0.38 & 15.1 & 9.2 & 14.1 & 12.8 & 2.4\\
      \hline
      35 & 0.37 & 14.3 & 17.6 & 8.4 & 13.4 & 3.4\\
      \hline
      40 & 0.37 & 13.4 & 12.4 & 12.1 & 12.6 & 0.5\\
      \hline
      45 & 0.38 & 13.6 & 12.9 & 14.1 & 13.5 & 0.4\\
      \hline
      50 & 0.40 & 17.8 & 15.4 & 19.9 & 17.7 & 1.5\\
      \hline
      55 & 0.43 & 16.9 & 13.7 & 19.6 & 16.7 & 2.0\\
      \hline
      60 & 0.47 & 14.9 & 19.2 & 17.9 & 17.3 & 1.6\\
      \hline
      65 & 0.55 & 13.6 & 16.5 & 14.1 & 14.7 & 1.2\\
      \hline
    \end{tabular}
    \caption{Data table}
    \label{DataTable}
  \end{table}
2
  • 1
    you can not use tabularx with no X columns, use a standard tabular here never use \noindent before a table environment (it will not affect indentation just cause spurious vertical space in the output. Commented Nov 4, 2021 at 20:07
  • Thanks @DavidCarlisle that fixed the line that suddenly stops so it doesn't look odd anymore. However, my table is still at going past the margin because the "Trial 3" column is given more space than it needs. Do you know of any way to fix this? I've edited my answer to include the new look of the table and the updated code.
    – refresh
    Commented Nov 4, 2021 at 20:22

1 Answer 1

2

You just need to make sure that the heading is not wider than the columns it spans either making the columns wider or the heading narrow. I show an example below although it would look better without all the horizontal and vertical rules.

enter image description here

\documentclass{article}
\usepackage{dcolumn}
\begin{document}

\begin{table}
\centering
\setlength\extrarowheight{2pt}
    \begin{tabular}{|c|D..{1.2}|D..{2.1}|D..{2.1}|D..{2.1}|D..{2.1}|D..{1.1}|}
      \hline
      \multicolumn{1}{|c|}{$\theta^\circ$} &
 \multicolumn{1}{c|}{$\pm\delta\theta^\circ$}& 
\multicolumn{3}{c|}{\begin{tabular}{@{}c@{}}Horizontal Displacement\\ (m$\pm$0.1m)\end{tabular}} &
 \multicolumn{1}{c|}{\begin{tabular}{@{}c@{}}Mean\\ (m)\end{tabular}} & 
 \multicolumn{1}{c|}{\begin{tabular}{@{}c@{}}Mean Uncertainty\\ ($\pm\delta$m)\end{tabular}}\\
\cline{3-5}
      & &  \multicolumn{1}{c|}{Trial 1} &  \multicolumn{1}{c|}{Trial 2} &  \multicolumn{1}{c|}{Trial 3} & &\\
      \hline\hline
      25 & 0.41 & 6.3 & 12.0 & 13.7 & 10.7 & 2.9\\
      \hline
      30 & 0.38 & 15.1 & 9.2 & 14.1 & 12.8 & 2.4\\
      \hline
      35 & 0.37 & 14.3 & 17.6 & 8.4 & 13.4 & 3.4\\
      \hline
      40 & 0.37 & 13.4 & 12.4 & 12.1 & 12.6 & 0.5\\
      \hline
      45 & 0.38 & 13.6 & 12.9 & 14.1 & 13.5 & 0.4\\
      \hline
      50 & 0.40 & 17.8 & 15.4 & 19.9 & 17.7 & 1.5\\
      \hline
      55 & 0.43 & 16.9 & 13.7 & 19.6 & 16.7 & 2.0\\
      \hline
      60 & 0.47 & 14.9 & 19.2 & 17.9 & 17.3 & 1.6\\
      \hline
      65 & 0.55 & 13.6 & 16.5 & 14.1 & 14.7 & 1.2\\
      \hline
    \end{tabular}
    \caption{Data table}
    \label{DataTable}
  \end{table}
\end{document}
3
  • I don't understand what you mean by horizontal and vertical rules? Do you mean the \hlines and the |s?
    – refresh
    Commented Nov 4, 2021 at 20:48
  • @Hady yes try reading the booktabs package documentation which has a simple rule for vertical rules: never use them:-) texdoc.org/serve/booktabs/0 Commented Nov 4, 2021 at 21:03
  • Ok, thanks for the help! Have a great day!
    – refresh
    Commented Nov 4, 2021 at 21:17

You must log in to answer this question.

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