0

I'm very new to overleaf and coding in general - I'm struggling quite a bit with the tables. My problem is I can't figure out how to transform this table (from Word) into LateX.

I know there is some multi-row and multi-columns needed here but there are so many columns i'm overwhelemed enter image description here

Would really appreciate some help - I understand the commands in general (\hline, & etc.. ) but I am really struggling to actually create the table from scratch.

Thanks!

EDIT: Now works! BUT the only thing now is that the table seems too large in width for the page... it might need use of \long table or breaking it in two parts across two pages.. See:enter image description here

The code now is this:

\begin{table}[htbp]
  \centering
\caption{Overview of 'live' schools in contact with DSMF which will be distributing the survey.}\label{live schools}\\ 
    \begin{tabular}{p{5em}ccccccccc}
    \toprule
    \textbf{Level} &       & \multicolumn{1}{p{6.25em}}{\textbf{Type}} &       & \multicolumn{1}{p{5em}}{\textbf{Funding category}} &       & \multicolumn{1}{p{5em}}{\textbf{Gender}} &       & \multicolumn{1}{p{5em}}{\textbf{Country}} &  \\
    \midrule
    \multicolumn{1}{r}{} &       &       &       &       &       &       &       &       &  \\
    Secondary school & 431   & \multicolumn{1}{p{6.25em}}{Comprehensive} & 261   & \multicolumn{1}{p{5em}}{State} & 377   & \multicolumn{1}{p{5em}}{Mixed} & 394   & \multicolumn{1}{p{5em}}{England} & 465 \\
    \midrule
    Sixth Form College & 9     & \multicolumn{1}{p{6.25em}}{Selective} & 112   & \multicolumn{1}{p{5em}}{Independent} & 119   & \multicolumn{1}{p{5em}}{Boys only} & 24    & \multicolumn{1}{p{5em}}{Scotland} & 43 \\
    \midrule
    Further Education & 17    & \multicolumn{1}{p{6.25em}}{Faith} & 79    & \multicolumn{1}{p{5em}}{N/A} & 16    & \multicolumn{1}{p{5em}}{Girls only} & 59    & \multicolumn{1}{p{5em}}{Wales} & 1 \\
    \midrule
    Primary School & 28    & \multicolumn{1}{p{6.25em}}{Grammar} & 26    &       &       & \multicolumn{1}{p{5em}}{Boys with girls in Sixth Form} & 16    & \multicolumn{1}{p{5em}}{Switzerland} & 1 \\
    \midrule
    Pupil referral unit & 9     & \multicolumn{1}{p{6.25em}}{Alternative provision} & 12    &       &       & \multicolumn{1}{p{5em}}{Girls with boys in Sixth Form} & 10    & \multicolumn{1}{p{5em}}{Czech Republic} & 1 \\
    \midrule
    Prep School & 4     & \multicolumn{1}{p{6.25em}}{Free} & 10    &       &       & \multicolumn{1}{p{5em}}{N/A} & 10    & \multicolumn{1}{p{5em}}{Northern Ireland} & 1 \\
    \midrule
    Special school & 6     & \multicolumn{1}{p{6.25em}}{Non-selective} & 8     &       &       &       &       &       &  \\
    \midrule
    International school & 3     & \multicolumn{1}{p{6.25em}}{Free-Faith} & 4     &       &       &       &       &       &  \\
    \midrule
    University & 3     & \multicolumn{1}{p{6.25em}}{Other} & 2     &       &       &       &       &       &  \\
    \midrule
    Adult Education & 1     & \multicolumn{1}{p{6.25em}}{Missing data} & 10    &       &       &       &       &       &  \\
    \midrule
    Conservatoire & 1     &       &       &       &       &       &       &       &  \\
    \midrule
    \textbf{Total schools} & \multicolumn{9}{c}{\textbf{512}} \\
    \midrule
    \textbf{Total schools} & \multicolumn{9}{c}{\multirow{2}[2]{*}{\textbf{480}}} \\
    \textit{(excl. Universities, Primary and Adult educations schools)} & \multicolumn{9}{c}{} \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%
10
  • Welcome to TeX.SE. Are you (a) proposing to copy and paste the contents of an existing Word table into a .tex document and (b) asking what kind of auxiliary information (such as suitably-placed \hline directives) you would need to provide in order to create, say, a viable tabular environment?
    – Mico
    Aug 6, 2023 at 22:18
  • 3
    You may be interested in the Excel2LaTeX add-on for Microsoft Excel, where you can convert a subrange of an Excel spreadsheet into a LaTeX tabular environment. I've had pretty good results from it before.
    – gz839918
    Aug 7, 2023 at 1:42
  • 5
    I think it would help if you would post your best attempt at the table. "I understand the commands in general" doesn't tell us what you don't understand. The table itself also needs some work. I would actually call it 5 separate tables since (as far as I can see) there's no relation between the rows of the inner tables. So one way to cut down on the overwhelming number of columns would be to have 5 separate tables with 2 columns each.
    – Teepeemm
    Aug 7, 2023 at 2:35
  • @gz839918 thank you so much!! This worked really well but the only thing now is that the table seems too large in width for the page... it might need use of \long table or breaking it in two parts across two pages..
    – patta83
    Aug 7, 2023 at 6:30
  • 1
    The repeated use of \multicolumn{1}{...}{...} is not needed here. Instead, put the relevant column definition directly inside the argument to the table environment, such as \begin{tabular}{ p{5em} p{6.25em} ... }. This way, you can also more easily set the width of your table. Decreasing the font size might also help. Aug 7, 2023 at 6:32

1 Answer 1

5

Here's my proposition to fit your table, although you are still strongly advice to visit the link: My table doesn't fit; what are my options?.

In your case the main reason the table doesn't fit is c-column type, which does not insert breaks if text is too long in cells, whereas p{} column does, including its siblings m{} and b{}. The latter columns are a part of the package array, which is loaded by tabularx.

In such "wordy" tables you may also need to decrease font size, however if you need the size lower than \footnotesize, it is IMO a sign the table may need another thinking through. Another option is to place a table vertically and utilise available space for long texts. For instance, you could load this package rotating and substitute table environment with sidewaystable.

In this example I used tabularx to utilise a more convenient X-column type; search this forum for more info, e.g. this recent post, or read the package documentation.

\documentclass{article}
\usepackage{lmodern,microtype}
\usepackage{tabularx}
\usepackage{booktabs}

\renewcommand{\arraystretch}{1.5}
\newcolumntype{Y}{>{\hsize=1.6\hsize\linewidth=\hsize\raggedright}X}
\newcolumntype{Z}{>{\hsize=0.4\hsize\linewidth=\hsize\raggedleft\arraybackslash}X}
\newcolumntype{M}{>{\hsize=2\hsize\linewidth=\hsize\centering\arraybackslash}X}

\begin{document}
\begin{table}[htbp]
  \caption{Overview of 'live' schools in contact with DSMF which will be distributing the survey.}\label{tab:liveschools}
  \scriptsize
  \centering
  \vspace{3pt}%
  \begin{tabularx}{\linewidth}{@{} *5{Y@{\hspace{0.25\tabcolsep}}Z} @{}}
    \toprule
    \multicolumn{2}{M}{\textbf{Level}}
    & \multicolumn{2}{M}{\textbf{Type}}
    & \multicolumn{2}{M}{\textbf{Funding category}}
    & \multicolumn{2}{M}{\textbf{Gender}}
    & \multicolumn{2}{M}{\textbf{Country}} \\
    \midrule
    Secondary school     & 431 & Comprehensive         & 261 & State       & 377 & Mixed                         & 394 & England          & 465 \\
    Sixth Form College   & 9   & Selective             & 112 & Independent & 119 & Boys only                     & 24  & Scotland         & 43  \\
    Further Education    & 17  & Faith                 & 79  & N/A         & 16  & Girls only                    & 59  & Wales            & 1   \\
    Primary School       & 28  & Grammar               & 26  &             &     & Boys with girls in Sixth Form & 16  & Switzerland      & 1   \\
    Pupil referral unit  & 9   & Alternative provision & 12  &             &     & Girls with boys in Sixth Form & 10  & Czech Republic   & 1   \\
    Prep School          & 4   & Free                  & 10  &             &     & N/A                           & 10  & Northern Ireland & 1   \\
    Special school       & 6   & Non-selective         & 8   &             &     &                               &     &                  &     \\
    International school & 3   & Free-Faith            & 4   &             &     &                               &     &                  &     \\
    University           & 3   & Other                 & 2   &             &     &                               &     &                  &     \\
    Adult Education      & 1   & Missing data          & 10  &             &     &                               &     &                  &     \\
    Conservatoire        & 1   &                       &     &             &     &                               &     &                  &     \\
    \midrule[\heavyrulewidth]
    \multicolumn{2}{@{}l}{\textbf{Total schools}}
    & \multicolumn{8}{l}{\textbf{512}} \\
    \midrule
    \multicolumn{2}{@{}l@{}}{\textbf{Total schools}\textsuperscript{\,1}}
    & \multicolumn{8}{l}{\textbf{480}} \\
    \bottomrule
    \multicolumn{10}{@{}l@{}}{\textsuperscript{1}\,\textit{(excl. Universities, Primary and Adult educations schools)}} \\
  \end{tabularx}
\end{table}
\end{document}

enter image description here

1
  • I love you. I UNDERSTAND NOW
    – patta83
    Aug 7, 2023 at 22:33

You must log in to answer this question.

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