1

This post is subsequent to Table is cut off using Stargazer. I have another problem of a cut off table. Except this time it does seem to be something to do with table width.

I have attempted to flesh out the code where previously I was using simple fragments producible by various packages in R Studio. The main point here is I've been trying to make a table fit the space better because it currently goes off page - it's inefficient party because it won't seem to go left.

I tried using 'flush left' because of what I saw in this clearly similar question here making a table fit on a page by moving it left which doesn't seem to have done anything. Unfortunately you will find I have butchered the code a little. I fully intend to learn to use it self-sufficiently but right now am doing it on the fly.

Cut off table

\documentclass{article}
\usepackage[english]{babel}
\usepackage{booktabs,tabularx,caption,ragged2e}
\captionsetup{skip=0.333\baselineskip}
\newcolumntype{L}{>{\hsize=7.5\hsize}X}
\newlength\mylength
\settowidth\mylength{Multicultu} % width of 2nd col.
\begin{document}
\begin{table}[!htbp]
\setlength\tabcolsep{2pt} % default: 6pt
\caption{}  \label{} 
\begin{flushleft}
\begin{tabularx}{\textwidth}{@{} l p{\mylength} LLLLL @{}}  
\toprule 
& Test & Trust & Demographics & Immigration & Economic Model & Issue     Satisfaction & Demographic No Country \\ 
\hline
1 & R2 & 0.016 & 0.2 & 0.086 & 0.007 & 0.021 & 0.027 \\ 
2 & Predicted & 83.20\% & 83.3\%\% & 83.40\% & 82.7\%\% & 83.20\% & 84.50\% \\ 
  3 & AUC Index & 0.585 & 0.79 & 0.701 & 0.559 & 0.603 & 0.61 \\ 
  4 & Sum of squared errors & 4861.786003 & 4773.002716 & 1847.897222 & 1249.544564 & 5009.179836 & 5310.168732 \\ 
  5 & Expected value$|$H0 & 4862.80413 & 4777.131906 & 1835.302972 & 1249.164639 & 5003.713449 & 5311.013662 \\ 
  6 & SD & 0.545436987 & 3.006760697 & 1.739686944 & 0.10557875 & 0.673923831 & 0.953354286 \\ 
  7 & Z & -1.866627646 & -1.373301832 & 7.239377177 & 3.598496041 & 8.111283371 & -0.886270167 \\ 
  8 & P & 0.061953604 & 0.169658533 & 4.51E-13 & 0.000320063 & 5.01E-16 & 0.375471961 \\ 
\bottomrule
\end{tabularx} 
\end{flushleft}
\end{table}
\end{document}
4
  • 1
    \newcolumntype{L}{>{\hsize=7.5\hsize}X} what???????????? Commented May 9, 2017 at 17:33
  • 1
    paragraph indent is zero in a table so the only effect of flushleft is to add additional vertical space. Commented May 9, 2017 at 17:36
  • 1
    the L definition makes every column 7.5 times as wide as tabularx calculated that the column needs to be, I'm wondering what is the intended behaviour? Commented May 9, 2017 at 17:39
  • your comprehensive answer on your question tex.stackexchange.com/questions/332902/… gives almost all what should OP consider in his table design, however from his MWE can be concluded that he has some basic problems (see David Carlisle comments and provided answers) with table settings which might be worth to leave question open :)
    – Zarko
    Commented May 9, 2017 at 18:52

4 Answers 4

2

The posted code produces

! Extra alignment tab has been changed to \cr.

as it has 7 declared columns but 8 columns of data.

Adding an extra L to fix that then you get the warning

Package tabularx Warning: X Columns too narrow (table too wide)
(tabularx)                 on input line 26.

because

\newcolumntype{L}{>{\hsize=7.5\hsize}X}

forces at each iteration every column to be seven and a half times wider than the width calculated, so tabularx has no chance of ever converging to the requested table width.

Then delete the ! from

\begin{table}[!htbp]

which should only be used in exceptional circumstances.

then I added dcolumn to allow decimal aligned columns (you could instead use siunitx)

Then define a command for the headings,

then it sort of fits but it's still far too tight to be readable, you could use \tiny instead of \footnotesize but do you need to give so many decimal places?

enter image description here

\documentclass{article}
\usepackage[english]{babel}
\usepackage{booktabs,tabularx,caption,ragged2e}
\captionsetup{skip=0.333\baselineskip}

\usepackage{dcolumn}
\newcommand\hd[1]{\multicolumn{1}{c}{\begin{tabular}{@{}c@{}}#1\end{tabular}}}
\begin{document}
\begin{table}[htbp]
\centering
\footnotesize
\setlength\tabcolsep{1pt} % default: 6pt
\caption{}  \label{} 

\begin{tabular}{@{}rp{2cm} *{6}{D..{1.9}}@{}}  
\toprule 
&
\hd{Test} &
\hd{Trust}&
\hd{Demo-\\graphics} &
\hd{Immi-\\gration}&
\hd{Economic\\Model}&
\hd{Issue\\Satisfaction}&
\hd{Demo-\\graphic\\No\\Country}\\ 
\hline
1 & R2 & 0.016 & 0.2 & 0.086 & 0.007 & 0.021 & 0.027 \\ 
2 & Predicted & 83.20\% & 83.3\%\% & 83.40\% & 82.7\%\% & 83.20\% & 84.50\% \\ 
  3 & AUC Index & 0.585 & 0.79 & 0.701 & 0.559 & 0.603 & 0.61 \\ 
  4 & Sum of\newline squared errors & 4861.786003 & 4773.002716 & 1847.897222 & 1249.544564 & 5009.179836 & 5310.168732 \\ 
  5 & Expected value$|$H0 & 4862.80413 & 4777.131906 & 1835.302972 & 1249.164639 & 5003.713449 & 5311.013662 \\ 
  6 & SD & 0.545436987 & 3.006760697 & 1.739686944 & 0.10557875 & 0.673923831 & 0.953354286 \\ 
  7 & Z & -1.866627646 & -1.373301832 & 7.239377177 & 3.598496041 & 8.111283371 & -0.886270167 \\ 
  8 & P & 0.061953604 & 0.169658533 & 4.51E-13 & 0.000320063 & 5.01E-16 & 0.375471961 \\ 
\bottomrule
\end{tabular} 

\end{table}


\end{document}
\documentclass{article}
\usepackage[english]{babel}
\usepackage{booktabs,tabularx,caption,ragged2e}
\captionsetup{skip=0.333\baselineskip}

\usepackage{dcolumn}
\newcommand\hd[1]{\multicolumn{1}{c}{\begin{tabular}{@{}c@{}}#1\end{tabular}}}
\begin{document}
\begin{table}[htbp]
\centering
\footnotesize
\setlength\tabcolsep{1pt} % default: 6pt
\caption{}  \label{} 

\begin{tabular}{@{}rp{2cm} *{6}{D..{1.9}}@{}}  
\toprule 
&
\hd{Test} &
\hd{Trust}&
\hd{Demo-\\graphics} &
\hd{Immi-\\gration}&
\hd{Economic\\Model}&
\hd{Issue\\Satisfaction}&
\hd{Demo-\\graphic\\No\\Country}\\ 
\hline
1 & R2 & 0.016 & 0.2 & 0.086 & 0.007 & 0.021 & 0.027 \\ 
2 & Predicted & 83.20\% & 83.3\%\% & 83.40\% & 82.7\%\% & 83.20\% & 84.50\% \\ 
  3 & AUC Index & 0.585 & 0.79 & 0.701 & 0.559 & 0.603 & 0.61 \\ 
  4 & Sum of\newline squared errors & 4861.786003 & 4773.002716 & 1847.897222 & 1249.544564 & 5009.179836 & 5310.168732 \\ 
  5 & Expected value$|$H0 & 4862.80413 & 4777.131906 & 1835.302972 & 1249.164639 & 5003.713449 & 5311.013662 \\ 
  6 & SD & 0.545436987 & 3.006760697 & 1.739686944 & 0.10557875 & 0.673923831 & 0.953354286 \\ 
  7 & Z & -1.866627646 & -1.373301832 & 7.239377177 & 3.598496041 & 8.111283371 & -0.886270167 \\ 
  8 & P & 0.061953604 & 0.169658533 & 4.51E-13 & 0.000320063 & 5.01E-16 & 0.375471961 \\ 
\bottomrule
\end{tabular} 

\end{table}
\end{document}

Actually, you need a format of D..{2.9} to allow for the minus sign, but as noted above 9 decimal places seems excessive for a table.

\documentclass{article}
\usepackage[english]{babel}
\usepackage{booktabs,tabularx,caption,ragged2e}
\captionsetup{skip=0.333\baselineskip}

\usepackage{dcolumn}
\newcommand\hd[1]{\multicolumn{1}{c}{\begin{tabular}{@{}c@{}}#1\end{tabular}}}
\begin{document}
\begin{table}[htbp]
\centering
\footnotesize
\setlength\tabcolsep{1pt} % default: 6pt
\caption{}  \label{} 

\begin{tabular}{@{}r>{\raggedright}p{1.4cm} *{6}{D..{2.9}}@{}}  
\toprule 
&
\hd{Test} &
\hd{Trust}&
\hd{Demo-\\graphics} &
\hd{Immi-\\gration}&
\hd{Economic\\Model}&
\hd{Issue\\Satisfaction}&
\hd{Demo-\\graphic\\No\\Country}\\ 
\hline
1 & R2 & 0.016 & 0.2 & 0.086 & 0.007 & 0.021 & 0.027 \\ 
2 & Predicted & 83.20\% & 83.3\%\% & 83.40\% & 82.7\%\% & 83.20\% & 84.50\% \\ 
  3 & AUC\\ Index & 0.585 & 0.79 & 0.701 & 0.559 & 0.603 & 0.61 \\ 
  4 & Sum of\\ squared errors & 4861.786003 & 4773.002716 & 1847.897222 & 1249.544564 & 5009.179836 & 5310.168732 \\ 
  5 & Expec-\\ted value$|$H0 & 4862.80413 & 4777.131906 & 1835.302972 & 1249.164639 & 5003.713449 & 5311.013662 \\ 
  6 & SD & 0.545436987 & 3.006760697 & 1.739686944 & 0.10557875 & 0.673923831 & 0.953354286 \\ 
  7 & Z & -1.866627646 & -1.373301832 & 7.239377177 & 3.598496041 & 8.111283371 & -0.886270167 \\ 
  8 & P & 0.061953604 & 0.169658533 & 4.51E-13 & 0.000320063 & 5.01E-16 & 0.375471961 \\ 
\bottomrule
\end{tabular} 

\end{table}


\end{document}
2
  • +1 for encouraging the OP to align the numbers on the decimal markers. In my answer, I make the suggestion, but I also suggest the OP round the numbers -- I simply can see no justification for reporting 8 and 9 digits after the decimal marker.
    – Mico
    Commented May 9, 2017 at 20:08
  • yes as I comment in the text 9dp is almost certainly excessive for a table Commented May 9, 2017 at 20:19
2

I test your table with following changes:

  • font size: \small
  • table environment tabularx
  • use S columns' type for numbers
  • reduce \tabcolsep to zero
  • consider David Carlisle and Mico comments (in their answers)

The result is:

enter image description here

\documentclass{article}
\usepackage[showframe,
            left=1cm,right=1cm]{geometry}
\usepackage[english]{babel}
\usepackage{booktabs, makecell, tabularx}
    \renewcommand\theadfont{\small}
\usepackage{caption}
\usepackage{ragged2e}

\usepackage{siunitx}
\captionsetup{skip=0.333\baselineskip}
\newcolumntype{L}{>{\raggedright}X}

\begin{document}
    \begin{table}%[!htbp]
    \small
\setlength\tabcolsep{0pt} % default: 6pt
    \caption{}  
\label{tab:my problematic table}
 \begin{tabularx}{\linewidth}{@{}   l @{\ } 
                                    L @{\quad}
                           *{6}{S[table-format=4.6,
                                  table-figures-exponent=1,
                                  table-align-text-post=false,
                                  table-align-exponent=false]}
                             @{} }
    \toprule
    & Test & Trust & {Demographics} & {Immigration} 
        & {\thead{Economic\\ Model}} & {\thead{Issue\\ Satisfaction}} 
            & {\thead{Demographic\\ No Country}} \\
    \midrule
 1 & R2         & 0.016         & 0.2           & 0.086         & 0.007         & 0.021         & 0.027       \\
 2 & Predicted  & 83.20\%       & 83.3\%\%      & 83.40\%       & 82.7\%\%      & 83.20\%       & 84.50\%     \\
 3 & AUC Index  & 0.585         & 0.79          & 0.701         & 0.559         & 0.603         & 0.61        \\
 4 & Sum of squared errors 
                & 4861.786003   & 4773.002716   & 1847.897222   & 1249.544564   & 5009.179836   & 5310.168732 \\
 5 & Expected value$|$H0 
                & 4862.80413    & 4777.131906   & 1835.302972   & 1249.164639   & 5003.713449   & 5311.013662 \\
 6 & SD         & 0.545436987   & 3.006760697   & 1.739686944   & 0.10557875    & 0.673923831   & 0.953354286 \\
 7 & Z          & -1.866627646  & -1.373301832  & 7.239377177   & 3.598496041   & 8.111283371   & -0.886270167\\
 8 & P          & 0.061953604   & 0.169658533   & 4.51e-13      & 0.000320063   & 5.01e-16      & 0.375471961 \\
 \bottomrule
 \end{tabularx}
    \end{table}
 \end{document}
1
    \documentclass{article}
    \usepackage[left=1cm,right=1cm]{geometry}
    \usepackage[english]{babel}
    \usepackage{booktabs,tabularx,caption,ragged2e,longtable}
    \captionsetup{skip=0.333\baselineskip}
    \newcolumntype{L}{>{\hsize=7.5\hsize}X}
    \newlength\mylength
    \settowidth\mylength{Multicultu} % width of 2nd col.
    \begin{document}
    \begin{table}[!htbp]
    \setlength\tabcolsep{2pt} % default: 6pt
    \caption{}  \label{} 
     \begin{flushleft}
     \begin{longtable}[H]{clcccccc}
      \toprule 
      & Test & Trust & Demographics & Immigration & Economic Model & Issue Satisfaction & Demographic No Country \\ 
     \midrule
     1 & R2 & 0.016 & 0.2 & 0.086 & 0.007 & 0.021 & 0.027 \\ 
     2 & Predicted & 83.20\% & 83.3\%\% & 83.40\% & 82.7\%\% & 83.20\% & 84.50\% \\ 
     3 & AUC Index & 0.585 & 0.79 & 0.701 & 0.559 & 0.603 & 0.61 \\ 
     4 & Sum of squared errors & 4861.786003 & 4773.002716 & 1847.897222 & 1249.544564 & 5009.179836 & 5310.168732 \\ 
      5 & Expected value$|$H0 & 4862.80413 & 4777.131906 & 1835.302972 & 1249.164639 & 5003.713449 & 5311.013662 \\ 
      6 & SD & 0.545436987 & 3.006760697 & 1.739686944 & 0.10557875 & 0.673923831 & 0.953354286 \\ 
      7 & Z & -1.866627646 & -1.373301832 & 7.239377177 & 3.598496041 & 8.111283371 & -0.886270167 \\ 
      8 & P & 0.061953604 & 0.169658533 & 4.51E-13 & 0.000320063 & 5.01E-16 & 0.375471961 \\ 
     \bottomrule
     \end{longtable} 
     \end{flushleft}
     \end{table}
     \end{document}

enter image description here

4
  • longtable does not have an [H] option and should never be inside flushleft or table environments. Commented May 9, 2017 at 17:33
  • thanking you for correcting me , longtable has only c, r and l option. @DavidCarlisle
    – Biki Teron
    Commented May 9, 2017 at 17:43
  • 1
    I know, I wrote it. Commented May 9, 2017 at 17:44
  • you could edit the answer to fix the errors also you changed the page size which is usually not an option to make a table fit into a document. Commented May 9, 2017 at 18:06
1

Your table is experiencing a number of serious issues.

  • What, pray tell, are you doing showing 8 or 9 digits after the decimal marker? Three digits should be more than enough. Either perform the rounding manually or load the siunitx package and let the package's S column type perform the rounding for you.

  • And what is >{\hsize=7.5\hsize}X even supposed to mean? I can see no reason for not making the six (not five) data columns equally wide.

  • You have several instances of \%\% -- it looks very untidy.

  • Using a flushleft environment is not needed. Don't use it.

In the following table, note that the main column type of the six data columns is S, to align the numbers on their respective decimal markers and to round the numbers, as discussed above. The six header cells, though, are wrapped in \mC directives to assure that the overall width of the tabularx environment is \textwidth. Observe how the text in some (but not all) of the text in the headers occupies two lines.

enter image description here

You must log in to answer this question.

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