1

I am new to LaTeX. I am trying to make a table in LaTeX but I cannot figure it out by myself. Any help would be much appreciated!

Here is the ideal appearance I made in word.

The ideal appearance of my table

Some details about this table:

  1. I merged some cells together. To achieve this, I am using multirow.

  2. This table is too wide for a page, therefore I am using landscape to rotate it 90 degree.

  3. The text in some cells are too long, and thus I need to wrap the text.

I got into trouble when I try to wrap the text.

Here is my current code (also this .cls file is required: https://www.dropbox.com/s/v89a7qxrkhvb3kg/McMasterThesis.cls?dl=0):

\documentclass[
12pt, 
twoside, 
english, 
singlespacing, 
]{McMasterThesis}
\usepackage[utf8]{inputenc} 
\usepackage{multirow}
\usepackage{lscape}

\begin{document}
\begin{landscape}
\begin{table}[]
\caption{Pairwise Pearson correlation coefficients among EEG indexes}
\label{tab:my-table}
\begin{tabular}{|ll|ll|ll|ll|ll|}
%\begin{tabular}{|p{1cm}l|p{2cm}p{2cm}|p{2cm}p{2cm}|p{2cm}p{2cm}|p{2cm}p{2cm}|}
\hline
                                                                  &   & Delta phase deviation             &              & Beta power modulation quadratic coefficient &             & Beta power modulation vertex time point &              & Delta-beta dPACz                 &    \\ \cline{3-10} 
                                                                  &   & \multicolumn{1}{p{2cm}|}{L}            & R            & \multicolumn{1}{p{2cm}|}{L}                      & R           & \multicolumn{1}{p{2cm}|}{L}                  & R            & \multicolumn{1}{p{2cm}|}{L}           & R  \\ \hline
\multicolumn{1}{|p{2cm}|}{Delta phase deviation}                       & L & \multicolumn{1}{p{2cm}|}{--}           & --           & \multicolumn{1}{p{2cm}|}{--}                     & --          & \multicolumn{1}{p{2cm}|}{--}                 & --           & \multicolumn{1}{p{2cm}|}{--}          & -- \\ \cline{2-10} 
\multicolumn{1}{|p{2cm}|}{}                                            & R & \multicolumn{1}{p{2cm}|}{.149 ± .044}  & --           & \multicolumn{1}{p{2cm}|}{--}                     & --          & \multicolumn{1}{p{2cm}|}{--}                 & --           & \multicolumn{1}{p{2cm}|}{--}          & -- \\ \hline
\multicolumn{1}{|p{2cm}|}{Beta power modulation quadratic coefficient} & L & \multicolumn{1}{p{2cm}|}{-.010 ± .014} & -.016 ± .013 & \multicolumn{1}{p{2cm}|}{--}                     & --          & \multicolumn{1}{p{2cm}|}{--}                 & --           & \multicolumn{1}{p{2cm}|}{--}          & -- \\ \cline{2-10} 
\multicolumn{1}{|p{2cm}|}{}                                            & R & \multicolumn{1}{p{2cm}|}{-.008 ± .012} & .009 ± .015  & \multicolumn{1}{p{2cm}|}{.103 ± .020}            & --          & \multicolumn{1}{p{2cm}|}{--}                 & --           & \multicolumn{1}{p{2cm}|}{--}          & -- \\ \hline
\multicolumn{1}{|p{2cm}|}{Beta power modulation vertex time point}     & L & \multicolumn{1}{p{2cm}|}{-.014 ± .015} & -.028 ± .017 & \multicolumn{1}{p{2cm}|}{.030 ± .040}            & .027 ± .015 & \multicolumn{1}{p{2cm}|}{--}                 & --           & \multicolumn{1}{p{2cm}|}{--}          & -- \\ \cline{2-10} 
\multicolumn{1}{|p{2cm}|}{}                                            & R & \multicolumn{1}{p{2cm}|}{-.009 ± .015} & -.028 ± .023 & \multicolumn{1}{p{2cm}|}{-.011 ± .022}           & .024 ± .023 & \multicolumn{1}{p{2cm}|}{.050 ± .020}        & --           & \multicolumn{1}{p{2cm}|}{--}          & -- \\ \hline
\multicolumn{1}{|p{2cm}|}{Delta-beta dPACz}                            & L & \multicolumn{1}{p{2cm}|}{-.071 ± .018} & -.005 ± .018 & \multicolumn{1}{p{2cm}|}{.148 ± .017}            & .014 ± .016 & \multicolumn{1}{p{2cm}|}{-.008 ± .016}       & -.028 ± .011 & \multicolumn{1}{p{2cm}|}{--}          & -- \\ \cline{2-10} 
\multicolumn{1}{|p{2cm}|}{}                                            & R & \multicolumn{1}{p{2cm}|}{-.039 ± .016} & -.028 ± .016 & \multicolumn{1}{p{2cm}|}{.031 ± .015}            & .181 ± .021 & \multicolumn{1}{p{2cm}|}{.019 ± .019}        & .016 ± .026  & \multicolumn{1}{p{2cm}|}{.026 ± .021} & -- \\ \hline
\end{tabular}
\end{table}
\end{landscape}
\end{document}

This is my current result

enter image description here

It appears that the texts are overlapped, and only the texts in the bottom row were wrapped.

Can anyone shed some light on this? Thank you all!

  • welcome to tex.se! you should define first column as p{2cm} and remove all \multicolumn in the first column. for further help please extend your table code fragment to complete small document with your table. which contain all your definitions and necessary packages that it can be compiled. – Zarko May 15 at 22:14
0

Your table is unusual composed. Why you use almost for each cell construct \multicolumn{1}{p{2cm}}{...}? You can define column width in table specifications as p{2cm} and than remove all those \multicolumns ...

Main problems are widths of the column headers. They need to be broken in more lines or redesigned as shown in figure below.

After clean up your code and redesign column headers, i optain the following result:

enter image description here

(to my taste the lower one is nicer).

To complete my table code I need more information about your document, as used document class, fonts and page layout. The best way for providing this information is extend your table code fragments to complete small document (called MWE: Minimal Working Example), as I asked you in comment. When you will provide those information, I will be able to finish my MWE and add it here.

As you can see from above image, your table is still very wide, i.e. probably wider than your page height. It can be significantly shrinking, if you will use alternative standardized writing of uncertainty: -.039(16) instead of -.039 ± .016.

edit: Thank you for providing MWE. Mine MWE for above tables is:

\documentclass{book}% original is McMasterThesis 
                    % extracted are essential information for this table
\RequirePackage{geometry}
\geometry{
    paper=letterpaper, % Default paper size, change to "letterpaper" for US Letter (you'll need to adjust margins after)
%   inner=1.5in, % The inner margin (beside binding)
    inner=3.8cm,
%   outer=1in, % The outer margin (opposite binding)
    outer=3.8cm,
%   top=.6in, % Top margin
    top=3.8cm,
%   bottom=.8in, % bottom margin
    bottom=2.5cm,
    headheight=20pt, % Header height
    headsep=.25in, % Header separation
    includehead,
    includefoot
}

\usepackage[small,sc]{caption} % Required for customising the captions
\setlength{\captionmargin}{50pt}

\usepackage{newtxtext,newtxmath}% my selection

\usepackage{booktabs, makecell, multirow}
\setcellgapes{2pt}              % new
\newcommand\mcc[1]{\multicolumn{2}{c|}{#1}}
\usepackage{siunitx}
\usepackage{pdflscape}

\begin{document}
\begin{landscape}
%%%% TOP TABLE
\begin{table}
\caption{Pairwise Pearson correlation coefficients among EEG indexes}
\label{tab:my-table}
    \centering
    \small
    \makegapedcells
    \setlength\tabcolsep{4pt}
    \sisetup{separate-uncertainty=true,
             table-column-width=6.6em}
\begin{tabular}{|p{31mm}|c| *{4}{S[table-format=-1.3(1)] S[table-format=-1.3(1)]|}}
\hline
    &   &   &   &   \multicolumn{4}{c|}{Beta power modulation}
                                &   &                               \\ \cline{5-8}
    &   &   \mcc{Delta phase deviation}
                &   \mcc{quadratic coefficient}
                        &   \mcc{vertex time point}
                                &   \mcc{Delta-beta dPACz}          \\ \cline{3-10}
    &   &   {L}
            &   {R}
                &   {L}
                    &   {R}
                        &   {L}
                            &   {R}
                                &   {L}
                                    &   {R}                         \\ \hline
\multirow{2}{=}{Delta phase deviation}
    & L & {--} & {--} & {--} & {--} & {--} & {--} & {--} & {--}     \\ \cline{2-10}
    & R & .149(44)
               & {--} & {--} & {--} & {--} & {--} & {--} & {--}     \\ \hline
\multirow{2}{=}{Beta power modulation quadratic coefficient}
    & L & -.010(14)
               & -.016(13)
                      & {--} & {--} & {--} & {--} & {--} & {--}     \\ \cline{2-10}
    & R & -.008(12)
               & .009(15)
                      & .103(20)
                             & {--} & {--} & {--} & {--} & {--}     \\ \hline
\multirow{2}{=}{Beta power modulation vertex time point}
    & L & -.014(15)
               & -.028(17)
                     & .030(40)
                             & .027(15)
                                    & {--} & {--} & {--} & {--}     \\ \cline{2-10}
    & R & -.009(15)
               & -.028(23)
                     & -.011(22)
                             & .024(23)
                                    & .050(20)
                                           & {--} & {--} & {--}     \\ \hline
\multirow{2}{=}{Delta-beta dPACz}
    & L & -.071(18)
               & -.005(18)
                     & .148(17)
                             & .014(16)
                                    & -.008(16)
                                           & -.028(11)
                                                  & {--} & {--}     \\ \cline{2-10}
    & R & -.039(16)
               & -.028(16)
                     & .031(15)
                             & .181(21)
                                    & .019(19)
                                           & .016(26)
                                                  & .026(21)
                                                         & {--}     \\ \hline
\end{tabular}
\end{table}



%%%% BOTTOM TABLE
\renewcommand\mcc[1]{\multicolumn{2}{c}{#1}}
\begin{table}
\caption{Pairwise Pearson correlation coefficients among EEG indexes}
\label{tab:my-table}
    \centering

    \small
    \setlength\tabcolsep{4pt}
    \sisetup{separate-uncertainty=true,
             table-column-width=6.6em}
\begin{tabular}{@{}p{30mm} c *{4}{S[table-format=-1.3(1)] S[table-format=-1.3(1)]}@{}}
    \toprule
    &   &   &   &   \multicolumn{4}{c}{Beta power modulation}
                                &   &                               \\
    \cmidrule(lr){5-8}
    &   &   \mcc{Delta phase deviation}
                &   \mcc{quadratic coefficient}
                        &   \mcc{vertex time point}
                                &   \mcc{Delta-beta dPACz}          \\
    \cmidrule(lr){3-4}
    \cmidrule(lr){5-6}
    \cmidrule(lr){7-8}
    \cmidrule(lr){9-10}
    &   &   {L}
            &   {R}
                &   {L}
                    &   {R}
                        &   {L}
                            &   {R}
                                &   {L}
                                    &   {R}                         \\
    \midrule
\multirow{2}{=}{Delta phase deviation}
    & L & {--} & {--} & {--} & {--} & {--} & {--} & {--} & {--}     \\
    & R & .149(44)
               & {--} & {--} & {--} & {--} & {--} & {--} & {--}     \\
    \addlinespace
\multirow{2}{=}{Beta power modulation quadratic coefficient}
    & L & -.010(14)
               & -.016(13)
                      & {--} & {--} & {--} & {--} & {--} & {--}     \\
    & R & -.008(12)
               & .009(15)
                      & .103(20)
                             & {--} & {--} & {--} & {--} & {--}     \\
    \addlinespace
\multirow{2}{=}{Beta power modulation vertex time point}
    & L & -.014(15)
               & -.028(17)
                     & .030(40)
                             & .027(15)
                                    & {--} & {--} & {--} & {--}     \\
    & R & -.009(15)
               & -.028(23)
                     & -.011(22)
                             & .024(23)
                                    & .050(20)
                                           & {--} & {--} & {--}     \\
    \addlinespace
\multirow{2}{=}{Delta-beta dPACz}
    & L & -.071(18)
               & -.005(18)
                     & .148(17)
                             & .014(16)
                                    & -.008(16)
                                           & -.028(11)
                                                  & {--} & {--}     \\
    & R & -.039(16)
               & -.028(16)
                     & .031(15)
                             & .181(21)
                                    & .019(19)
                                           & .016(26)
                                                  & .026(21)
                                                         & {--}     \\
    \bottomrule
\end{tabular}
\end{table}
\end{landscape}
\end{document}

As you can see, in your table I use S column type defined in siunitx package (which is loaded by your document class) in all columns the first two, and its syntax for short writing of uncertainty. With this changes your table is compilable with xelatex as well with pdflatex.

Using \small font size your table still gives wider table that is text height. Consequently it spill out on the right side (top of the page). If this can be allowed, than I would remove page number by adding \thispagestyle{empty} immediately after begin{landscape}. If this is not allowed, than width of table can be further reduced by the following changes in above code:

  • use of \footnotesize
  • set table-column-width=6.2em
  • set \setlength\tabcolsep{3pt}
  • reduce the first column width to p{28mm} (for the first table) and/or p{27mm} (for second table)

I hope, that this is useful starting point for your adoption above code to your needs.

  • Thanks for your help! I have updated the code to be MWE – curl sloth May 16 at 1:51
  • @AndrewChang, now I have all information. I extract from your document style information relevant to your question. See edited answer. – Zarko May 16 at 2:23
  • thank you very much for your help :) – curl sloth May 16 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.