1

I have always had this problem when using LaTeX, but I have no idea how to make tables properly fit the table. It would be nice to do it automatically.

I have the following code:

\begin{tabular}{llllll}
\hline
\textbf{Study name}                                                                                                             & \textbf{Cohort dimension} & \textbf{Time before AF onset} & \textbf{ECG features}                                                                                                                                                                                       & \textbf{Used metric}                                    & \textbf{Model (accuracy)}                                                                           \\ \hline
Study on P-wave feature Time Course as Early Prediction of Paroxysmal AF                                                        & 24 patients               & 2h                            & \begin{tabular}[c]{@{}l@{}}- P-wave durations\\ - PR interval\\ - Heart rate\end{tabular}                                                                                                                   & Linear regression slope of the variability              & Linear discriminant (90.79\%)                                                                       \\
Morphological Variability of the P-wave for Premature Envision of Paroxysmal AF Events                                          & 46 patients + 53 controls & 2h                            & - P-wave area, energy, conduction velocity, dispersion, arc-length                                                                                                                                          & Linear regression slope of the variability              & Decision tree (86.33\%)                                                                             \\
Gaussian modelling of the P-wave morphology time course applied to anticipate paroxysmal atrial fibrillation                    & 46 patients + 53 controls & 2h                            & \begin{tabular}[c]{@{}l@{}}- Gaussian fit parameters\\ - Error between fitted Gaussian and P-wave\end{tabular}                                                                                              & Linear regression slope of the variability              & Stepwise discriminant analysis (86.69\%)                                                            \\
ECG-based Prediction of Atrial Fibrillation Development Following CABG                                                          & 14 patients + 36 controls & 48h                           & \begin{tabular}[c]{@{}l@{}}- P-wave durations\\ - PQ interval\\ - Heart rate\\ - PQ segment, and P, Q, R, and S amplitudes\\ - Wavelet energies and entropy\end{tabular}                                    & Cumulative rank with statistically significant features & \begin{tabular}[c]{@{}l@{}}Decision tree {[}applied over the time-course{]}\\ (85.3\%)\end{tabular} \\
Multiparameter Prediction Model for AF after CABG                                                                               & 11 patients + 29 controls & 48h                           & \begin{tabular}[c]{@{}l@{}}- P-wave duration, slopes, amplitude, area and energies\\ - P-wave wavelet entropy\\ - PQ and PR intervals\\ - Heart rate\end{tabular}                                           & ECG features                                            & Decision tree (85\%)                                                                                \\
Prediction of Paroxysmal AF Onset in Postoperative Patients using Neuro-Fuzzy Modelling                                         & 37 patients + 53 controls & 30m                           & \begin{tabular}[c]{@{}l@{}}-Number of premature atrial complexes\\ - HRV: mean, SDRR, rMSSD, total power, LF/HF, entropy\\ - P-wave duration, amplitude, shape, inflection point, energy ratio\end{tabular} & ECG features                                            & \begin{tabular}[c]{@{}l@{}}Neuro-fuzzy\\ (70\%)\end{tabular}                                        \\
Alteration of the P-wave non-linear dynamics near the onset of paroxysmal atrial fibrillation                                   & 46 patients               & 2h                            & \begin{tabular}[c]{@{}l@{}}- P-wave durations\\ - P-wave area, arc-length\end{tabular}                                                                                                                      & Central tendency measurement                            & Decision tree (90\%)                                                                                \\
Role of the P-wave high frequency energy and duration as nonivasive cardiovascular predictors of paroxysmal atrial fibrillation & 46 patients + 53 controls & 2h                            & - P-wave frequency energies                                                                                                                                                                                 & Linear regression slope of the variability              & Stepwise discriminant analysis (80\%)                                                               \\ \hline
\end{tabular}

But just the 1st column occupies the entire page.

Is there any way to make the table automatically decide which column size to give the columns to make it fit? (and then adjust font size, I guess).

Best wishes, Diogo

  • you have specified l columns (single line with no linebreaking) replace l by p{2cm} or whatever width you want for paragraph columns – David Carlisle Sep 10 '18 at 18:53
  • op tables has more issues than braking text in cell into more lines. since op is novice i would like to show him how to design his table. therefore i suggest to reopen his question – Zarko Sep 10 '18 at 20:12
2

your table has more problems than simple breaking text in cells into more line:

  • your table is huge and without special efforts is not possible to fit on one page
  • probably you should consider to rotate table in landscape orientation, if this is allowed
  • your page layout is unknown, so i decide to define own and also to stick with portraid oriented table.
  • in comparison to your table code i made the following changes:

    • use smaller font (\footnotesize)
    • use \enumitem for lists in the fourth column
    • use the \thead macro from the makcell package for column headers (and with this made some columns narrower)
    • deliberately determine ratios between column widths
    • instead of \hline i use rules provided by package booktabs
    • for more vertical space between rows is used \addlinespa from the booktabs package

      \documentclass{article}
      \usepackage[margin=20mm]{geometry}
      \usepackage{ragged2e}
      \usepackage{booktabs, makecell, tabularx}
      \renewcommand\theadfont{\small\bfseries}
      \renewcommand\theadgape{}
      \newcolumntype{L}{>{\RaggedRight}X}
      \usepackage{siunitx}
      \usepackage{enumitem}
      
      \begin{document}
          \begin{table}[htb]
      \footnotesize
      \setlist[itemize]{nosep,
                        leftmargin=*,
                        before=\vspace{-0.6\baselineskip},
                        after=\vspace{-\baselineskip}
      }
      \setlength\tabcolsep{3pt}
      \begin{tabularx}{\linewidth}{@{}
                  >{\hsize=1.6\hsize}L
                  >{\hsize=0.8\hsize}L
                                     c L
                  >{\hsize=0.8\hsize}L
                  >{\hsize=0.8\hsize}L
                   @{}}
          \toprule
      \thead[bl]{Study name}
          &   \thead[lb]{Cohort\\ dimension}
              &   \thead[lb]{Time before\\ AF onset}
                  &   \thead[bl]{ECG\\ features}
                      &   \thead[lb]{Used metric}
                          &   \thead[lb]{Model\\ (accuracy)}            \\
          \midrule
      Study on P-wave feature Time Course as Early Prediction of Paroxysmal AF
          &   24 patients
              &   2h
                  &   \begin{itemize}
                  \item   P-wave durations\
                  \item   PR interval
                  \item   Heart rate
                      \end{itemize}                                                                                                                   &   Linear regression slope of the variability
                          &   Linear discriminant (\SI{90.79}{\%})                \\
          \addlinespace
      Morphological Variability of the P-wave for Premature Envision of Paroxysmal AF Events
          &   46 patients + 53 controls
              &   2h
                  &   \begin{itemize}
                  \item   P-wave area, energy, conduction velocity, dispersion, arc-length
                      \end{itemize}
                      &   Linear regression slope of the variability
                          &   Decision tree (\si{86.33}{\%})                      \\
          \addlinespace
      Gaussian modelling of the P-wave morphology time course applied to anticipate paroxysmal atrial fibrillation
              &   46 patients + 53 controls
                  &   2h
                      &   \begin{itemize}
                  \item   Gaussian fit parameters
                  \item   Error between fitted Gaussian and P-wave
                          \end{itemize}
                          &   Linear regression slope of the variability
                              &   Stepwise discriminant analysis (\SI{86.69}{\%}) \\
          \addlinespace
      ECG-based Prediction of Atrial Fibrillation Development Following CABG
          &    14 patients + 36 controls
              &   48h
                  &   \begin{itemize}
                  \item   P-wave durations
                  \item   PQ interval
                  \item   Heart rate
                  \item   PQ segment, and P, Q, R, and S amplitudes
                  \item   Wavelet energies and entropy
                      \end{itemize}
                      &   Cumulative rank with statistically significant features
                          &   Decision tree [applied over the time-course] (\SI{85.3}{\%}) \\
          \addlinespace
      Multiparameter Prediction Model for AF after CABG
          &   11 patients + 29 controls
              &   48h
                  &   \begin{itemize}
                  \item   P-wave duration, slopes, amplitude, area and energies
                  \item   P-wave wavelet entropy
                  \item   PQ and PR intervals
                  \item   Heart rate
                      \end{itemize}
                      &   ECG features
                          & Decision tree (\SI{85}{\%})                                   \\
          \addlinespace
      Prediction of Paroxysmal AF Onset in Postoperative Patients using Neuro-Fuzzy Modelling
          &   37 patients + 53 controls
              &   30m
                  &   \begin{itemize}
                  \item   Number of premature atrial complexes
                  \item   HRV: mean, SDRR, rMSSD, total power, LF/HF, entropy
                  \item   P-wave duration, amplitude, shape, inflection point, energy ratio
                      \end{itemize}
                      &   ECG features
                          & Neuro-fuzzy (\SI{70}{\%})                                     \\
          \addlinespace
      Alteration of the P-wave non-linear dynamics near the onset of paroxysmal atrial fibrillation
          &   46 patients
              &   2h
                  &   \begin{itemize}
                  \item   P-wave durations
                  \item   P-wave area, arc-length
                      \end{itemize}
                      &   Central tendency measurement
                          &   Decision tree (\SI{90}{\%})                                 \\
          \addlinespace
      Role of the P-wave high frequency energy and duration as nonivasive cardiovascular predictors of paroxysmal atrial fibrillation
          &   46 patients + 53 controls
              &   2h
                  &   \begin{itemize}
                      \item   P-wave frequency energies
                          \end{itemize}
                          &   Linear regression slope of the variability
                              &   Stepwise discriminant analysis (\SI{80}{\%})                \\
              \bottomrule
          \end{tabularx}
          \end{table}
      \end{document}
      

enter image description here

  • Hello Zarko, many thanks for your help. I am using a template, so I think I only have to comment the following line: \usepackage[margin=20mm]{geometry}. I would like to understand how you specificty the column size? – Take2 Sep 10 '18 at 22:28
  • @DiogoTec, the best way for understanding is read tabularx documentation. shortly. using X columns tabularx divide table width (belong to X columns` on equal parts. this division you can change with \hsize=x\hsize where x is factor of increasing (if x>1) or decreasing (y<1) by tabularx calculated width. those factors i determined experimentally. – Zarko Sep 10 '18 at 23:00
  • I now understand :) thank you May I do an extra question? How can I center the table contents both vertically and horizontally? – Take2 Sep 10 '18 at 23:32
  • @DiogoTec: (i) don't center cell contents, (ii) i don't recommend to center cell contents, (iii) eventually make exception for column headers (by omitting thead options: instead \thead[lb]{...} use \thead{...}. if you still persist to have (ugly table) with all cells contents centered, than add in preamble \renewcommand\tabularxcolumn[1]{m{#1}} and \newcolumntype{C}{>{\Centering}X}, and than instead L useC column specifier, i.e.: \begin{tabularx}{\linewidth}{@{} >{\hsize=1.6\hsize}L >{\hsize=0.8\hsize}L c L >{\hsize=0.8\hsize}L >{\hsize=0.8\hsize}C @{}} – Zarko Sep 11 '18 at 6:55
  • Okay okay. I will follow your suggestion! I would like to adjust the size of the 3rd column, where you specificed c L, but when I change it to something like >{\hsize=1.6\hsize}L instead, it gives me error. Any idea? – Take2 Sep 11 '18 at 10:08

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.