3

I copied this table from excel2latex, I want this table to be centered, aligned and fit into the the page within the margin. My code is:

\documentclass[11pt]{article}
\usepackage{booktabs,siunitx}
\usepackage{graphicx}

\begin{document}    
% Table generated by Excel2LaTeX from sheet 'Sheet1'
\begin{table}
    \centering
    \small
    \scalebox{0.4}{
    \begin{tabular}{llcclccc}
        \textbf{Table 1} &       &       &       &       &       &       &  \\
        \multicolumn{8}{l}{Charitable Donation Tax Credit Rates1, by Province, 1997 and 2009 (\%)} \\
        \midrule
        \midrule
        & \multicolumn{3}{c@{\quad}}{1997} &       & \multicolumn{3}{r@{\quad}}{2009} \\
        \cmidrule{2-4}\cmidrule{6-8}          & \multicolumn{1}{l}{First \$200 of Donations} &       & \multicolumn{1}{l}{Donation in Excess of \$200} &       & \multicolumn{1}{l}{First \$200 of Donations} &       & \multicolumn{1}{l}{Donations in Excess of \$200} \\
        Federal & \multicolumn{1}{c}{17.0} &       & \multicolumn{1}{c}{29.0} &       & \multicolumn{1}{c}{15.0} &       & \multicolumn{1}{c}{29.0} \\
        \midrule
        \multicolumn{1}{c}{Newfoundland and Labrador} & \multicolumn{1}{c}{11.73} &       & \multicolumn{1}{c}{20.01} &       & \multicolumn{1}{c}{7.7} &       & \multicolumn{1}{c}{15.5} \\
        Price Edward Island & \multicolumn{1}{c}{10.12} &       & \multicolumn{1}{c}{17.26} &       & \multicolumn{1}{c}{9.8} &       & \multicolumn{1}{c}{16.7} \\
        Nova Scotia & \multicolumn{1}{c}{9.95} &       & \multicolumn{1}{c}{16.97} &       & \multicolumn{1}{c}{8.79} &       & \multicolumn{1}{c}{17.5} \\
        New Brunswick & \multicolumn{1}{c}{10.71} &       & \multicolumn{1}{c}{18.27} &       & \multicolumn{1}{c}{9.65} &       & \multicolumn{1}{c}{17.95} \\
        Quebec2 & \multicolumn{1}{c}{23.0} &       & \multicolumn{1}{c}{23.0} &       & \multicolumn{1}{c}{20.0} &       & \multicolumn{1}{c}{24.0} \\
        Ontario & \multicolumn{1}{c}{8.16} &       & \multicolumn{1}{c}{13.92} &       & \multicolumn{1}{c}{6.05} &       & \multicolumn{1}{c}{11.16} \\
        Manitoba & \multicolumn{1}{c}{8.5} &       & \multicolumn{1}{c}{14.5} &       & \multicolumn{1}{c}{10.8} &       & \multicolumn{1}{c}{17.4} \\
        Saskatchewan & \multicolumn{1}{c}{9.4} &       & \multicolumn{1}{c}{16.0} &       & \multicolumn{1}{c}{11.0} &       & \multicolumn{1}{c}{15.0} \\
        Alberta & \multicolumn{1}{c}{7.74} &       & \multicolumn{1}{c}{13.20} &       & \multicolumn{1}{c}{10.0} &       & \multicolumn{1}{c}{21.0} \\
        British Columbia & \multicolumn{1}{c}{8.67} &       & \multicolumn{1}{c}{14.79} &       & \multicolumn{1}{c}{5.06} &       & \multicolumn{1}{c}{14.7} \\
        \midrule
        \midrule
        \multicolumn{8}{r}{1The credit rate is statutory rate, which is not subject to surtaxes. Surtaxes increase the value of the credit as they are calculated as a percentage of provincial/territorial income taxes net of the provincial/territorial Charitable Donation Tax Credit.} \\
        \multicolumn{8}{l}{2 The tax credit rate for Quebec residents must be adjusted for the 16.5\% Quebec Abatement.} \\
        \multicolumn{8}{l}{\textit{Source: Canada Revenue Agency; Department of Finance Canada calculations.}} \\
    \end{tabular}%
    \label{tab:addlabel}%
}
\end{table}





\end{document}

enter image description here

8
  • Thanks for making it to latex format! Can you please help me with this problem?
    – user149250
    Nov 27, 2017 at 23:47
  • Welcome to TeX.SE!. Try with [!htpb] after \begin{table}.
    – Cragfelt
    Nov 27, 2017 at 23:59
  • @Cragfelt that will have no effect at all on the tabular layout Nov 28, 2017 at 0:00
  • 1
    @Cragfelt -- regarding the positioning argument (the [!htpb]), this would be the same for either table or figure. the problem is with the size of the table, not the location. Nov 28, 2017 at 2:05
  • 1
    @Cragfelt no, the question is unrelated to the position of the table on the page, it is about the tabular itself, and how big it is. Nov 28, 2017 at 7:41

5 Answers 5

3

the markup generated by excel2latex is just massively over-complicated, all the \multicolumn{1}{c} are doing nothing useful at all. Mostly here I just removed the markup added. It would be simpler to just get a plain text comma separated value output from excel and add the markup required, however

enter image description here

\documentclass[11pt]{article}
\usepackage{booktabs,siunitx}
\usepackage{graphicx}

\begin{document}    
% Table generated by Excel2LaTeX from sheet 'Sheet1'
\begin{table}
    \centering
    \footnotesize
    \setlength\tabcolsep{5pt}
\caption{Charitable Donation Tax Credit Rates1, by Province, 1997 and 2009 (\%)}


    \begin{tabular}{@{}l*{4}{S}@{}}
        \toprule
        & \multicolumn{2}{c}{1997} & \multicolumn{2}{c}{2009} \\
        \cmidrule{2-3}\cmidrule{4-5}          
& \multicolumn{1}{l}{First \$200} & \multicolumn{1}{l}{Excess of \$200} &       
\multicolumn{1}{l}{First \$200} & \multicolumn{1}{l}{Excess of \$200} \\
        Federal & 17.0 & 29.0 & 15.0 & 29.0 \\
        \midrule
     Newfoundland \& Labrador & 11.73 & 20.01 & 7.7 & 15.5 \\
        Price Edward Island & 10.12 & 17.26 & 9.8 & 16.7 \\
        Nova Scotia & 9.95 & 16.97 & 8.79 & 17.5 \\
        New Brunswick & 10.71 & 18.27 & 9.65 & 17.95 \\
        Quebec2 & 23.0 & 23.0 & 20.0 & 24.0 \\
        Ontario & 8.16 & 13.92 & 6.05 & 11.16 \\
        Manitoba & 8.5 & 14.5 & 10.8 & 17.4 \\
        Saskatchewan & 9.4 & 16.0 & 11.0 & 15.0 \\
        Alberta & 7.74 & 13.20 & 10.0 & 21.0 \\
        British Columbia & 8.67 & 14.79 & 5.06 & 14.7 \\
        \bottomrule
    \end{tabular}%
    \label{tab:addlabel}%


    \begin{enumerate}
    \item  The credit rate is statutory rate, which is not subject to surtaxes. Surtaxes increase the value of the credit as they are calculated as a percentage of provincial/territorial income taxes net of the provincial/territorial Charitable Donation Tax Credit.
\item  The tax credit rate for Quebec residents must be adjusted for the 16.5\% Quebec Abatement.
    \end{enumerate}



 \textit{Source: Canada Revenue Agency; Department of Finance Canada calculations.}

\end{table}





\end{document}
3

Another one. This one taking also in account simplify the design of awful headers (maybe is not what you want, but the point is catch the idea that headers with a lot of lines are not pleasing). Indeed, this job is best done at hand, starting with a raw copy & paste for spreadsheet to the LaTeX editor or importing a .csv file that adapting the unnecessarily complicated excel2latex ouput.

mwe

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs,siunitx,tabularx}
\newcolumntype{U}{S[table-format=4.3,round-mode=places, round-precision=2]}
\usepackage{graphicx}
\renewcommand\belowcaptionskip{1ex}
\begin{document}    
% Table generated by hand 1.0 from MWE 
\begin{table}
\caption{Charitable Donation Tax Credit Rates (\%)\protect\footnotemark[1], by Province.} 
\label{tab:addlabel}%
\begin{tabularx}{\linewidth}{@{}XUUUU@{}}
\toprule
& \multicolumn{2}{c}{Donations in 1997} & \multicolumn{2}{c}{Donations in 2009} \\
\cmidrule(rl){2-3}\cmidrule(rl){4-5}
 & \mbox{1st \$200} & 
\mbox{$>\mathdollar200$} &
\mbox{1st \$200} & 
\mbox{$>\mathdollar200$} \\
\midrule
        Federal &  17.0 & 29.0 & 15.0 & 29.0 \\
        Newfoundland and Labrador &  11.73 & 20.01 & 7.7 & 15.5 \\
        Price Edward Island &  10.12 & 17.26 & 9.8 & 16.7 \\
        Nova Scotia &  9.95 & 16.97 & 8.79 & 17.5 \\
        New Brunswick &  10.71 & 18.27 & 9.65 & 17.95 \\
        Quebec\footnotemark[2] &  23.0 & 23.0 & 20.0 & 24.0 \\
        Ontario &  8.16 & 13.92 & 6.05 & 11.16 \\
        Manitoba &  8.5 & 14.5 & 10.8 & 17.4 \\
        Saskatchewan &  9.4 & 16.0 & 11.0 & 15.0 \\
        Alberta &  7.74 & 13.20 & 10.0 & 21.0 \\
        British Columbia &  8.67 & 14.79 & 5.06 & 14.7 \\\bottomrule
\end{tabularx}
\par\footnotesize\parskip1ex
\footnotemark[1] The credit rate is statutory rate, which is not subject to surtaxes. Surtaxes increase the value of the credit as they are calculated as a percentage of provincial/territorial income taxes net of the provincial/territorial Charitable Donation Tax.\par
\footnotemark[2] The tax credit rate for Quebec residents must be adjusted for the 16.5\% Quebec Abatement.\par
\emph{Source: Canada Revenue Agency; Department of Finance Canada calculations.}         
\end{table}
\end{document}
2

with use of threeparttable, tablenotes and tabular* environment::

enter image description here

\documentclass[11pt]{article}
%\usepackage{geometry}
\usepackage[skip=1ex,
            font=small,
            labelfont=bf,
            labelsep=newline,
            singlelinecheck=false
            ]{caption}
\usepackage{booktabs, threeparttable}
\usepackage{siunitx}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
% Table generated by Excel2LaTeX from sheet 'Sheet1'
    \begin{table}[ht]
    \begin{threeparttable}
\caption{Charitable Donation Tax Credit Rates\tnote{1}, by Province, 1997 and 2009 (\%)}
    \label{tab:addlabel}
    \setlength\tabcolsep{0pt}
    \small
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l SSSS}
    \toprule
        & \multicolumn{2}{c}{Donations in 1997}
                        & \multicolumn{2}{c}{Donations in 2009}      \\
    \cmidrule(lr){2-3}
    \cmidrule(lr){4-5}
        &   {First \$200}
                &   {Excess of \$200}
                        &   {First \$200}
                                &   {Excess of \$200}               \\
Federal & 17.0  & 29.0  & 15.0  & 29.0                              \\
    \midrule
Newfoundland and Labrador
        & 11.73 & 20.01 & 7.7   & 15.5                              \\
Price Edward Island
        & 10.12 & 17.26 & 9.8   & 16.7                              \\
Nova Scotia
        & 9.95  & 16.97 & 8.79  & 17.5                              \\
New Brunswick
        & 10.71 & 18.27 & 9.65  & 17.95                             \\
Quebec\tnote{2} 
        & 23.0  & 23.0  & 20.0  & 24.0                              \\
Ontario & 8.16  & 13.92 & 6.05  & 11.16                             \\
Manitoba & 8.5  & 14.5  & 10.8  & 17.4                              \\
Saskatchewan
        & 9.4   & 16.0  & 11.0  & 15.0                              \\
Alberta & 7.74  & 13.20 & 10.0  & 21.0                              \\
British Columbia
        & 8.67  & 14.79 & 5.06  & 14.7                              \\
    \bottomrule
    \end{tabular*}
\begin{tablenotes}\footnotesize
\item[1]    The credit rate is statutory rate, which is not subject to surtaxes. Surtaxes increase the value of the credit as they are calculated as a percentage of provincial/territorial income taxes net of the provincial/territorial Charitable Donation Tax Credit.
\item[2]    The tax credit rate for Quebec residents must be adjusted for the \SI{16.5}{\%} Quebec Abatement.

    \smallskip
\item[]     \textit{Source: Canada Revenue Agency; Department of Finance Canada calculations.}
\end{tablenotes}
\end{threeparttable}
\end{table}
1

Here's a solution that's quite similar to the one by @Zarko (I swear I didn't copy his approaches!). The main differnces are (a) the use of a tabularx environment and (b) the material in the first column is subject to automatic line-breaking and -wrapping.

The number of columns has been reduced from 8 to 5, by eliminating the blank columns. All useless and pointless \multicolumn{1}{c}{...} wrappers have been discarded.

enter image description here

\documentclass[11pt]{article}
\usepackage{booktabs,siunitx,tabularx,ragged2e}
\usepackage[flushleft]{threeparttable}
\newcolumntype{L}{>{\RaggedRight\arraybackslash\hspace{0pt}%
                    \hangafter1\hangindent1em}X}
\newcolumntype{C}{>{\Centering\arraybackslash\hspace{0pt}}X}
\newcommand\mC[1]{\multicolumn{1}{C}{#1}}
\usepackage[skip=0.25\baselineskip,labelfont=bf,labelsep=newline,
            singlelinecheck=false]{caption}
\begin{document}    

\begin{table}
\setlength\tabcolsep{3pt}
\begin{threeparttable}
\caption{Charitable Donation Tax Credit Rates\tnote{1}, 
         by Province, 1997 and 2009 (\%)}  
\label{tab:addlabel}

\begin{tabularx}{\textwidth}{@{} L *{4}{S[table-format=2.2]} @{}}
\toprule
& \multicolumn{2}{c}{1997} 
& \multicolumn{2}{c}{2009} \\
\cmidrule(lr){2-3}\cmidrule(l){4-5}
& \mC{First \$200 of Donations}      
& \mC{Donations in Excess of \$200}      
& \mC{First \$200 of Donations}
& \mC{Donations in Excess of \$200} \\ 
\midrule
Federal & 17.0 & 29.0 & 15.0 & 29.0 \\
\addlinespace
Newfoundland and Labrador & 11.73 & 20.01 & 7.7 & 15.5 \\
Price Edward Island & 10.12 & 17.26 & 9.8 & 16.7  \\
Nova Scotia      &  9.95 & 16.97 &  8.79 & 17.5 \\
New Bruns\-wick    & 10.71 & 18.27 &  9.65 & 17.95 \\
Quebec\tnote{2}  & 23.0  & 23.0  & 20.0  & 24.0 \\
Ontario          &  8.16 & 13.92 &  6.05 & 11.16 \\
Manitoba         &  8.5  & 14.5  & 10.8  & 17.4 \\
Saskatche\-wan   &  9.4  & 16.0  & 11.0  & 15.0 \\
Alberta          &  7.74 & 13.20 & 10.0  & 21.0 \\
British Columbia &  8.67 & 14.79 &  5.06 & 14.7 \\
\bottomrule
\end{tabularx}

\footnotesize
\begin{tablenotes}
\item[1] The credit rate is statutory rate, which is 
not subject to surtaxes. Surtaxes increase the value 
of the credit as they are calculated as a percentage 
of provincial\slash territorial income taxes net of 
the provincial\slash territorial Charitable Donation 
Tax Credit.
\item[2] The tax credit rate for Quebec residents 
must be adjusted for the 16.5\% Quebec Abatement.
\end{tablenotes}

\textit{Source: Canada Revenue Agency; Department 
of Finance Canada calculations.}

\end{threeparttable}
\end{table}

\end{document}
0

Here's a solution with threeparttable, siunitx, colortbl and siunitx. I redesigned it a bit;

\documentclass[11pt]{article}
\usepackage{booktabs,siunitx, makecell, caption}
\usepackage[flushleft]{threeparttable}
\usepackage[table, svgnames]{xcolor}
\usepackage[showframe, a4paper]{geometry}
\usepackage{graphicx}

\begin{document}
% Table generated by Excel2LaTeX from sheet 'Sheet1'
\captionsetup{labelsep = newline, labelfont = bf, font = small, singlelinecheck = off}
\begin{table}
  \centering\setlength{\tabcolsep}{5pt}\setlength{\extrarowheight}{2pt}
\begin{threeparttable}
    \small
\caption{Charitable Donation Tax Credit Rates1, by Province, 1997 and 2009 (\%)}
\rowcolors{4}{WhiteSmoke!70!Lavender}{white}
    \begin{tabular}{@{}l*{3}{Sc}S}%
        \toprule
        \midrule
        & \multicolumn{3}{c@{\quad}}{1997} & & \multicolumn{2}{r@{\quad}}{2009} \\
        \cmidrule(lr){2-4}\cmidrule(lr){6-8} &{ \makecell{First \$\,200\\ of Donations}} & & {\makecell{Donation\\ in Excess\\ of \$\,200}} & & {\makecell{First \$\,200\\ of Donations}} & & {\makecell{Donations\\ in Excess\\ of \$\,200}} \\
\addlinespace
\rowcolor{Gainsboro!60!Lavender} Federal & 17.0 & & 29.0 & & 15.0 & & 29.0 \\
        \addlinespace
        Newfoundland and Labrador & 11.73 & & 20.01 & & 7.7 & & 15.5 \\
        Price Edward Island & 10.12 & & 17.26 & & 9.8 & & 16.7 \\
        Nova Scotia & 9.95 & & 16.97 & & 8.79 & & 17.5 \\
        New Brunswick & 10.71 & & 18.27 & & 9.65 & & 17.95 \\
        Quebec2 & 23.0 & & 23.0 & & 20.0 & & 24.0 \\
        Ontario & 8.16 & & 13.92 & & 6.05 & & 11.16 \\
        Manitoba & 8.5 & & 14.5 & & 10.8 & & 17.4 \\
        Saskatchewan & 9.4 & & 16.0 & & 11.0 & & 15.0 \\
        Alberta & 7.74 & & 13.20 & & 10.0 & & 21.0 \\
        British Columbia & 8.67 & & 14.79 & & 5.06 & & 14.7 \\
        \midrule
        \bottomrule
    \end{tabular}%
    \label{tab:addlabel}%
\begin{tablenotes}
 \item[1.]The credit rate is statutory rate, which is not subject to surtaxes. Surtaxes increase the value of the credit as they are calculated as a percentage of provincial/territorial income taxes net of the provincial/territorial Charitable Donation Tax Credit.
 \item[2.]The credit rate is statutory rate, which is not subject to surtaxes. Surtaxes increase the value of the credit as they are calculated as a percentage of provincial/territorial income taxes net of the provincial/territorial Charitable Donation Tax Credit.\smallskip
\item[]\textit{Source: Canada Revenue Agency; Department of Finance Canada calculations.}
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document} 

enter image description here

0

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.