3

I have been looking at a few posts... namely How to force a table into a page width, but still could not get my table to show up properly across the page width.

Can you help me get my tables on both pages to show up centered across the page although beyond margins?

Here is the code that I have so far:

\documentclass[10pt,openany]{book}

\usepackage{calc}
\usepackage[left=1.5cm, right=1.5cm, bindingoffset=1.5cm, headheight=30pt, top={120pt+10mm}]{geometry}
\usepackage{graphicx, rotating, ltablex, dcolumn, booktabs}
\usepackage[english]{babel}
\usepackage[usenames,dvipsnames,svgnames,table,xcdraw]{xcolor}
\usepackage{array}
\usepackage{colortbl}
\usepackage{tabularx}
\usepackage{multicol}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\definecolor{myblueiii}{RGB}{199,234,253}

\begin{document}

\noindent

\begin{table}[htbt]
\centering
\caption{My caption}
\label{my-label}
\rowcolors{2}{myblueiii}{white}
\begin{tabular}{cccccccccc}
\rowcolor{myblueii!50}
\hline
\textbf{Model} & \textbf{NUMUORS} & \textbf{NUMUANDS} & \textbf{TOTOTORS} & \textbf{TOTOPANDS} & \textbf{VG} & \textbf{NLOGIC} & \textbf{LOC} & \textbf{ELOC} & \textbf{} \\ \hline
1 & -0.0516 & 0.0314 & -0.0027 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2119 & 0.0018 & 0.005 & -0.3091 \\
2 & -0.0482 & 0.0336 & -0.0021 & \cellcolor[HTML]{9B9B9B} & -0.0337 & 0.2088 & 0.0019 & \cellcolor[HTML]{9B9B9B} & -0.3255 \\
3 & -0.0517 & 0.0341 & -0.0026 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2118 & 0.0018 & 0.005 & -0.309 \\
4 &  &  &  & \cellcolor[HTML]{9B9B9B} &  &  &  &  &  \\
5 & -0.0516 & 0.0341 & -0.0027 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2119 & 0.0018 & 0.005 & -0.3091 \\
6 & -0.0482 & 0.0336 & -0.0021 & \cellcolor[HTML]{9B9B9B} & -0.0337 & 0.2088 & 0.0019 & \cellcolor[HTML]{9B9B9B} & -0.3255 \\
7 & -0.0517 & 0.0341 & -0.0026 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2118 & 0.0018 & -0.309 & -0.309 \\
8 &  &  &  & \cellcolor[HTML]{9B9B9B} &  &  &  &  &
\end{tabular}
\end{table}

\newpage
\begin{table}[htbt]
\centering
\caption{My caption}
\label{my-label}
\rowcolors{2}{myblueiii}{white}
\begin{tabular}{cccccccccc}
\rowcolor{myblueii!50}
\hline
\textbf{Model} & \textbf{NUMUORS} & \textbf{NUMUANDS} & \textbf{TOTOTORS} & \textbf{TOTOPANDS} & \textbf{VG} & \textbf{NLOGIC} & \textbf{LOC} & \textbf{ELOC} & \textbf{} \\ \hline
1 & -0.0516 & 0.0314 & -0.0027 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2119 & 0.0018 & 0.005 & -0.3091 \\
2 & -0.0482 & 0.0336 & -0.0021 & \cellcolor[HTML]{9B9B9B} & -0.0337 & 0.2088 & 0.0019 & \cellcolor[HTML]{9B9B9B} & -0.3255 \\
3 & -0.0517 & 0.0341 & -0.0026 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2118 & 0.0018 & 0.005 & -0.309 \\
4 &  &  &  & \cellcolor[HTML]{9B9B9B} &  &  &  &  &  \\
5 & -0.0516 & 0.0341 & -0.0027 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2119 & 0.0018 & 0.005 & -0.3091 \\
6 & -0.0482 & 0.0336 & -0.0021 & \cellcolor[HTML]{9B9B9B} & -0.0337 & 0.2088 & 0.0019 & \cellcolor[HTML]{9B9B9B} & -0.3255 \\
7 & -0.0517 & 0.0341 & -0.0026 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2118 & 0.0018 & -0.309 & -0.309 \\
8 &  &  &  & \cellcolor[HTML]{9B9B9B} &  &  &  &  &
\end{tabular}
\end{table}

\end{document} 

First table:

enter image description here

Second table:

enter image description here

2

I think your best option is to display the table in landscape format. Since you're already loading the rotating package, you could make use of the sidewaystable environment.

I would also like to suggest that you align the numbers in columns 2 thru 10 on their decimal markers. That'll make the table much more readable.

Since you're using alternating row colors, there's no point in using \hline as well to set off row boundaries, is there?

enter image description here

\documentclass[10pt,openany]{book}
\usepackage{calc}
\usepackage[hmargin=1.5cm, bindingoffset=1.5cm, 
            headheight=30pt, top={120pt+10mm}]{geometry}
\usepackage{rotating,array,siunitx}
\usepackage[english]{babel}
\usepackage[usenames,dvipsnames,svgnames,table,xcdraw]{xcolor}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\definecolor{myblueiii}{RGB}{199,234,253}

\begin{document}

\begin{sidewaystable}
\setlength\tabcolsep{3pt}      % default: 6pt
\setlength\extrarowheight{1pt} % give the table a more open look
\centering
\caption{My caption}
\label{my-label}
\rowcolors{2}{myblueiii}{white}
\begin{tabular}{c *{5}{S[table-format=-1.4]}
                  *{2}{S[table-format= 1.4]}
                       S[table-format=-1.3]
                       S[table-format=-1.4]}
\rowcolor{myblueii!50}
\textbf{Model} & {\textbf{NUMUORS}} & {\textbf{NUMUANDS}} & {\textbf{TOTOTORS}} &
{\textbf{TOTOPANDS}} & {\textbf{VG}} & {\textbf{NLOGIC}} & {\textbf{LOC}} &
{\textbf{ELOC}} & {\textbf{}} \\
1 & -0.0516 & 0.0314 & -0.0027 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2119 & 0.0018 & 0.005 & -0.3091 \\
2 & -0.0482 & 0.0336 & -0.0021 & \cellcolor[HTML]{9B9B9B} & -0.0337 & 0.2088 & 0.0019 & \cellcolor[HTML]{9B9B9B} & -0.3255 \\
3 & -0.0517 & 0.0341 & -0.0026 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2118 & 0.0018 & 0.005 & -0.309 \\
4 &  &  &  & \cellcolor[HTML]{9B9B9B} & & & & & \\
5 & -0.0516 & 0.0341 & -0.0027 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2119 & 0.0018 & 0.005 & -0.3091 \\
6 & -0.0482 & 0.0336 & -0.0021 & \cellcolor[HTML]{9B9B9B} & -0.0337 & 0.2088 & 0.0019 & \cellcolor[HTML]{9B9B9B} & -0.3255 \\
7 & -0.0517 & 0.0341 & -0.0026 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2118 & 0.0018 & -0.309 & -0.309 \\
8 &  &  &  & \cellcolor[HTML]{9B9B9B} & & & & & \\
\end{tabular}

\end{sidewaystable}

\end{document} 
  • @Micro, thanks for your solution! For the second table that will appear on the next page, how can you rotate the table 180 degrees? Thanks! – Joe Feb 15 '17 at 17:14
  • @Joe - For the second tabular environment to show up in landscape mode on a separate page, just encase it in a sidewaystable environment of its own. (I didn't do this in my answer as the contents of the two tabular environments you posted (though not their screenshots) appeared to be identical.) – Mico Feb 15 '17 at 18:01
2

By reducing font size in column headers to \footnotesize and tabcolsep (spaces between columns) to 3pt, it is possible to fit table into text width:

\documentclass[10pt,openany]{book}
\usepackage{calc}
\usepackage[showframe,
            left=1.5cm, right=1.5cm, 
            bindingoffset=1.5cm, headheight=30pt, 
            top={120pt+10mm}]{geometry}
\usepackage{graphicx, rotating, ltablex, dcolumn, booktabs}
\usepackage[english]{babel}
\usepackage[usenames,dvipsnames,svgnames,table,xcdraw]{xcolor}
\usepackage{array}
\usepackage{tabularx}
\usepackage{multicol}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\definecolor{myblueiii}{RGB}{199,234,253}

\usepackage{siunitx}                            % <-- added
\newcommand\mch[1]{\multicolumn{1}{c}{\footnotesize\textbf{#1}}} % <-- added

\begin{document}
    \begin{table}[htbt]
\centering
\caption{My caption}
    \label{my-label}
\setlength\tabcolsep{3pt}
\rowcolors{2}{myblueiii}{white}
    \begin{tabular}{c *{5}{S[table-format=-1.4]}
                      *{2}{S[table-format= 1.4]}
                           S[table-format=-1.3]
                           S[table-format=-1.4]}
\rowcolor{myblueii!50}
    \hline
\mch{Model} & \mch{NUMUORS} & \mch{NUMUANDS} & \mch{TOTOTORS} & \mch{TOTOPANDS} 
    & \mch{VG} & \mch{NLOGIC} & \mch{LOC} & \mch{ELOC} & \\ 
    \hline
1 & -0.0516 & 0.0314 & -0.0027 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2119 & 0.0018 & 0.005 & -0.3091 \\
2 & -0.0482 & 0.0336 & -0.0021 & \cellcolor[HTML]{9B9B9B} & -0.0337 & 0.2088 & 0.0019 & \cellcolor[HTML]{9B9B9B} & -0.3255 \\
3 & -0.0517 & 0.0341 & -0.0026 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2118 & 0.0018 & 0.005 & -0.309 \\
4 &  &  &  & \cellcolor[HTML]{9B9B9B} &  &  &  &  &  \\
5 & -0.0516 & 0.0341 & -0.0027 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2119 & 0.0018 & 0.005 & -0.3091 \\
6 & -0.0482 & 0.0336 & -0.0021 & \cellcolor[HTML]{9B9B9B} & -0.0337 & 0.2088 & 0.0019 & \cellcolor[HTML]{9B9B9B} & -0.3255 \\
7 & -0.0517 & 0.0341 & -0.0026 & \cellcolor[HTML]{9B9B9B} & -0.0372 & 0.2118 & 0.0018 & -0.309 & -0.309 \\
8 &  &  &  & \cellcolor[HTML]{9B9B9B} &  &  &  &  &  
    \end{tabular}
    \end{table}
\end{document}

enter image description here

  • @Mico, of course. I overlooked this option in OP preamble. Corrected in my answer. – Zarko Feb 15 '17 at 18:05

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.