Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to

  • get the same width of columns labeled 1-10 (all except the first one ~ Name of X)

  • be able to adjust the position of "name of Y" (have it centered or on the left. Right now, it's affecting the width of the second column)

  • have decimal-aligned numbers

  • (decrease table's size by x percent? To view its miniature which is set by %?)

enter image description here

\documentclass{article}

\usepackage{booktabs}   % this package promotes good tabular style
\usepackage{caption}    % for customising caption style
\usepackage{siunitx}    % for decimal alignment

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
incididunt ut labore.

\begin{table}[!ht]
\setlength{\tabcolsep}{4pt} %length between columns; default = 6
\footnotesize
\centering
\captionsetup{singlelinecheck = on, justification = centering, labelfont = bf}
        \caption{Aaaaaaaaaaaaaaaaa}
        \begin{tabular}{c*{10}{c}}
            \toprule
            & {Name of Y} \\
            \cmidrule(lr){2-11}
           {Name of X} & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\ 
            \midrule
2000    & 123 & 45617 & 1415 & 1111 & 11111 & 55555 & 55555 & 66666 & 777.7 & 88888 \\
2000    & 123 & 45617 & 1415 & 11 & 11111 & 55555 & 55555 & 66666 & 7777.7 & 88888 \\
            \bottomrule
        \end{tabular}

\end{table}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
incididunt ut labore.

\end{document}
share|improve this question

1 Answer 1

up vote 6 down vote accepted

The position of "Name of Y" can be changed using a \multicolumn. For the alignment, you can use the S column type provided by siunitx (the package offers many additional possibilities). To have columns of equal width you could use the tabularx package; to make it cooperate with siunitx, some additional work is required by adding

\begingroup
\catcode`\_=11
\catcode`\:=11
\gdef\tabularxcolumn#1{%
    >{\__siunitx_table_collect_begin:Nn S{} }%
    p{#1}
    <{\__siunitx_table_print:}%
}
\endgroup

which is nothing more than an update (using the new syntax of siunitx) to Martin Scharrer's answer to How to use siunitx and tabularx together?. In your case, however, the table seems to be really wide, so you could additionally rotate it using sidewaystable from the rotating package (You force the reader to change the reading direction, but the table values are much more clearer).

A complete example:

\documentclass{article}
\usepackage{booktabs}   % this package promotes good tabular style
\usepackage{caption}    % for customising caption style
\usepackage{siunitx}    % for decimal alignment
\usepackage{tabularx}    % for columns of equal width
\usepackage{rotating}    % for rotating objects

% make tabularx and siunitx cooperate
\begingroup
\catcode`\_=11
\catcode`\:=11
\gdef\tabularxcolumn#1{%
    >{\__siunitx_table_collect_begin:Nn S{} }%
    p{#1}
    <{\__siunitx_table_print:}%
}
\endgroup


\begin{document}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
incididunt ut labore.

\begin{sidewaystable}
\centering
\captionsetup{singlelinecheck = on, justification = centering, labelfont = bf}
        \caption{Aaaaaaaaaaaaaaaaa}
        \begin{tabularx}{\linewidth}{c*{10}{X}}
            \toprule
            & \multicolumn{10}{c}{Name of Y} \\
            \cmidrule(lr){2-11}
           {Name of X} & {1} & {2} & {3} & {4} & {5} & {6} & {7} & {8} & {9} & {10} \\ 
            \midrule
2000    & 1.23 & 45.617 & 14.15 & 11.11 & 11.111 & 555.55 & 555.55 & 66.666 & 777.7 & 8888.8 \\
2000    & 12.3 & 456.17 & 1.415 & 11 & 111.11 & 55.555 & 5555.5 & 66.666 & 7777.7 & 888.88 \\
            \bottomrule
        \end{tabularx}
\end{sidewaystable}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
incididunt ut labore.

\end{document}

enter image description here

Some other options would be to use \resizebox that allows you to scale the table:

\resizebox{<width>}{<height>}{<content>}

the ! modifier leaves the natural dimension unaltered. (If the table is too wide, perhaps a portrait display would be better than scaling it):

\documentclass{article}

\usepackage{booktabs}   % this package promotes good tabular style
\usepackage{caption}    % for customising caption style
\usepackage{siunitx}    % for decimal alignment

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
incididunt ut labore.

\begin{table}[!ht]
\footnotesize
\centering
\captionsetup{singlelinecheck = on, justification = centering, labelfont = bf}
        \caption{Aaaaaaaaaaaaaaaaa}
        \resizebox{\textwidth}{!}{\begin{tabular}{c*{10}{S}}
            \toprule
            & \multicolumn{10}{c}{Name of Y} \\
            \cmidrule(lr){2-11}
           {Name of X} & {1} & {2} & {3} & {4} & {5} & {6} & {7} & {8} & {9} & {10} \\ 
            \midrule
2000    & 1.23 & 45.617 & 14.15 & 11.11 & 11.111 & 555.55 & 555.55 & 66.666 & 777.7 & 88.888 \\
2000    & 12.3 & 456.17 & 1.415 & 11 & 111.11 & 55.555 & 5555.5 & 66.666 & 7777.7 & 888.88 \\
            \bottomrule
        \end{tabular}}

\end{table}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
incididunt ut labore.

\end{document}

enter image description here

There's also \scalebox{<x-factor>}[<y-factor>]{contents}, but using this you need to by trial-error determine the appropriate factor(s).

Another option reducing \tabcolsep and still using \resizebox:

\documentclass{article}

\usepackage{booktabs}   % this package promotes good tabular style
\usepackage{caption}    % for customising caption style
\usepackage{siunitx}    % for decimal alignment

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
incididunt ut labore.

\begin{table}[!ht]
\setlength{\tabcolsep}{3pt} %length between columns; default = 6
\footnotesize
\centering
\captionsetup{singlelinecheck = on, justification = centering, labelfont = bf}
        \caption{Aaaaaaaaaaaaaaaaa}
        \resizebox{\textwidth}{!}{\begin{tabular}{c*{10}{S}}
            \toprule
            & \multicolumn{10}{c}{Name of Y} \\
            \cmidrule(lr){2-11}
           {Name of X} & {1} & {2} & {3} & {4} & {5} & {6} & {7} & {8} & {9} & {10} \\ 
            \midrule
2000    & 1.23 & 45.617 & 14.15 & 11.11 & 11.111 & 555.55 & 555.55 & 66.666 & 777.7 & 88.888 \\
2000    & 12.3 & 456.17 & 1.415 & 11 & 111.11 & 55.555 & 5555.5 & 66.666 & 7777.7 & 888.88 \\
            \bottomrule
        \end{tabular}}

\end{table}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
incididunt ut labore.

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.