Graphics, Figures & TablesControl Table Size

Information and discussion about graphics, figures & tables in LaTeX documents.
latexhelp1
Posts: 141
Joined: Sun Jun 12, 2011 6:30 am

Control Table Size

Post by latexhelp1 »

I want my table to occupy more space on the page without increasing the font size (e.g. scalebox). Is there a way to increase the spacing within the table, such as a fixed width or fixed column? I have googled around for suggestions but could not find anything effective.

Currently, it occupies a moderate space just in the top left corner of the table.

Here's an example table I am working with:

\newpage
\vspace{-2cm}
\hspace{6cm}
\begin{center}
\begin{table}
\begin{threeparttable}
\begin{tabular}{lccccccc}
\multicolumn{7}{c}{\textbf{\large{Table 1:}}} \\
\hline \hline
& & \small{{(1)}} & \small{{(2)}} & \small{{(3)}} \\
\midrule
Variable & & 0.011*** & 0.026*** & -0.002*** \\
& & \small{(0.002)} & \small{(0.008)} & \small{(0.0005)} \\
\\
Observations & & 1234 & 123412 & 1234123 \\
$R^2$ & & 0.10 & 0.07 & 0.01 \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\vspace{0.2cm}
\scriptsize{

\item \noindent Notes:
}
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{center}
Last edited by latexhelp1 on Wed Oct 26, 2011 12:15 am, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Control Table Size

Post by localghost »

Please get used to always providing a minimal example that is compilable as provided. Otherwise specific help becomes almost impossible especially when a problem is more complicated. Furthermore such an example document increases your chances for good answers.


Your code is weird. This makes me recommend to do some basic reading. Compare the below example with your code snippet to see what you should not do.

Code: Select all

\documentclass[a4paper,titlepage]{article}
\usepackage[T1]{fontenc}
\usepackage[labelfont=bf,tableposition=top]{caption}
\usepackage{array,booktabs,tabularx,threeparttable}

% This code is taken from the UK TeX FAQ (http://www.tex.ac.uk/cgi-bin/texfaq2html?label=wholerow)
\newcolumntype{_}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{%
  \gdef\currentrowstyle{#1}%
  #1\ignorespaces
}

\begin{document}
  \begin{table}[!ht]
    \caption{Table caption}\label{tab:dummy}
    \centering
    \begin{threeparttable}
      \begin{tabularx}{\textwidth}{_l^X^X^X}\toprule
        \rowstyle{\small}
        & (1) & (2) & (3) \\\midrule
        Variable &  0.011\tnote{***} & 0.026\tnote{***} & -0.002\tnote{***} \\
        \rowstyle{\small}
        & (0.002) & (0.008) & (0.0005) \\\addlinespace
        Observations & 1234 & 123412 & 1234123 \\
        $R^2$ & 0.10 & 0.07 & 0.01 \\ \bottomrule\addlinespace
      \end{tabularx}
      \begin{tablenotes}
        \scriptsize
        \item[***] Notes:
      \end{tablenotes}
    \end{threeparttable}
  \end{table}
\end{document}
The example is enhanced by several useful packages. Please refer to the corresponding manuals to learn what they do. Assumed that a package is already installed on your machine, you have instead access on the command line.

Code: Select all

texdoc tabularx
In case of upcoming problems, feel free to ask further targeted questions.

And by the way, it would be very nice to use the »Code« button when posting code to keep your posts clear and legible.


Thorsten
latexhelp1
Posts: 141
Joined: Sun Jun 12, 2011 6:30 am

Re: Control Table Size

Post by latexhelp1 »

Thank you so much for this code! I will continue to research the differences between these two tables, and have already learned a lot.

One question in the interim. I do not understand what you mean in your comment about textdoc tabularx. Are you suggesting that I download something from the internet?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Control Table Size

Post by localghost »

latexhelp1 wrote:[…] I do not understand what you mean in your comment about textdoc tabularx. Are you suggesting that I download something from the internet?
Actually I pointed out that you can access the manual of a package by opening a command line and typing in the given command. If there was something to download, I would have referred you to a corresponding URL.
latexhelp1
Posts: 141
Joined: Sun Jun 12, 2011 6:30 am

Control Table Size

Post by latexhelp1 »

I'm sorry, but I am not able to do that access the documentation you are trying to help me locate. I use TeXnicCenter if that helps anything. I have been resorting to googling around.
localghost wrote:
latexhelp1 wrote:[…] I do not understand what you mean in your comment about textdoc tabularx. Are you suggesting that I download something from the internet?
Actually I pointed out that you can access the manual of a package by opening a command line and typing in the given command. If there was something to download, I would have referred you to a corresponding URL.


I am very happy with the code you sent me, but I do have some questions that I hope you would not mind me following up with.

First, I have some questions about

Code: Select all

{\textwidth}{_l^X^X^X}
.
What do the

Code: Select all

_
and

Code: Select all

^
do? It looks like you created the _ and the ^? Also, is it possible to both column stretch and center justify the same column. My understanding is the l is left-justify and the X is column stretch with a default of left justifying in the process.

Second, is it possible to center (in other words, align) the items within the column? For example, the row, (1) (2) and (3) is not well aligned with the numbers on which they are atop.
*****************************************************************
On a different note, I am noticing 2 problems with the table that I did not previously have. If I include more than 7 Xs (i.e. the first column l for the variable names, and then the results (1), (2), ..., (7)), the numbers no longer fit nicely in one row and some get bumped into a new row. At the same time, I notice that there is ample amounts of white space on the left and right of the table (at least an inch or two on both sides). Even if I landscape the table, the same problem remains. I have decreased the font to \small but would not like to decrease the font any further. Is there a way to make a wider table work?
Here is an example:

Code: Select all

        \documentclass[a4paper,titlepage]{article}
    \usepackage[T1]{fontenc}
    \usepackage[labelfont=bf,tableposition=top]{caption}
    \usepackage{array,booktabs,tabularx,threeparttable}

    % This code is taken from the UK TeX FAQ (http://www.tex.ac.uk/cgi-bin/texfaq2html?label=wholerow)
    \newcolumntype{_}{>{\global\let\currentrowstyle\relax}}
    \newcolumntype{^}{>{\currentrowstyle}}
    \newcommand{\rowstyle}[1]{%
      \gdef\currentrowstyle{#1}%
      #1\ignorespaces
    }

\begin{document}

\begin{table}[!ht]
\caption{Table caption}\label{tab:dummy}
\centering
\begin{threeparttable}
\begin{tabularx}{\textwidth}{_l^X^X^X^X^X^X^X^X}\toprule
\rowstyle{\small} & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\\midrule
 \rowstyle{\small}  Variable &  0.011\tnote{***} & 0.026\tnote{***} & -0.003\tnote{***}& -0.004\tnote{***} & -0.005\tnote{***} & -0.006\tnote{***} & -0.007\tnote{***} & -0.008\tnote{***}\\ \bottomrule\addlinespace
\end{tabularx}
\begin{tablenotes}
\scriptsize
\item[***] Notes:
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}
Second, I am having trouble using \multicolumn in the middle of the table if I do have a longer table with some of the numbers filled in. The code simply won't compile, but I will attach what I am attempting to do.

My apologies for such a long message. I am deeply grateful for your help!
Last edited by latexhelp1 on Wed Oct 19, 2011 4:38 pm, edited 1 time in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Control Table Size

Post by localghost »

latexhelp1 wrote:I'm sorry, but I am not able to do that access the documentation you are trying to help me locate. I use TeXnicCenter if that helps anything. I have been resorting to googling around. […]
Actually I thought that we are here to help people with LaTeX problems and not teach them to handle their operating system. I'm afraid that I can't help in this regard because as you might have noticed from my signature, I'm not a Wind0ws user. I only remember that you could press "Windows"+R to get a window where you can execute commands. The actual command line (command prompt?) should be found somewhere in the »Start« menu, perhaps under "Tools".
latexhelp1 wrote:[…] I have some questions about

Code: Select all

{\textwidth}{_l^X^X^X}
.
What do the

Code: Select all

_
and

Code: Select all

^
do? It looks like you created the _ and the ^? Also, is it possible to both column stretch and center justify the same column. My understanding is the l is left-justify and the X is column stretch with a default of left justifying in the process. […]

There are two new column types "_" and "^" defined in the preamble with a comment where this solution is taken from [1]. They make possible to use the new defined \rowstyle command. This way you don't always have to use the commands for font sizes.
latexhelp1 wrote:[…] is it possible to center (in other words, align) the items within the column? For example, the row, (1) (2) and (3) is not well aligned with the numbers on which they are atop. […]
Define a new column type, e. g. "C", and replace all "X" columns with it.

Code: Select all

\newcolumntype{C}{>{\centering\arraybackslash}X}
This line goes also into the preamble.
latexhelp1 wrote:[…] On a different note, I am noticing 2 problems with the table that I did not previously have. If I include more than 7 Xs (i.e. the first column l for the variable names, and then the results (1), (2), ..., (7)), the numbers no longer fit nicely in one row and some get bumped into a new row. At the same time, I notice that there is ample amounts of white space on the left and right of the table (at least an inch or two on both sides). Even if I landscape the table, the same problem remains. I have decreased the font to \small but would not like to decrease the font any further. Is there a way to make a wider table work? […]
This is a behaviour that you describe best with a proper minimal example. Please follow the link and obey the instructions.
latexhelp1 wrote:[…] Second, I am having trouble using \multicolumn in the middle of the table if I do have a longer table with some of the numbers filled in. The code simply won't compile, but I will attach what I am attempting to do. […]
This might need a different approach because "X" columns and the \multicolumn command are a complicated combination.

You can find more information about methods to typeset tables in an interesting PracTeX Journal article [2]. This should cover most applications cases.

[1] TeX Frequently Asked Questions – How to change a whole row of a table
[2] The PracTeX Journal – TeX Users Group, Lapo Filippo Mori: Tables in LaTeX2e: Packages and Methods
latexhelp1
Posts: 141
Joined: Sun Jun 12, 2011 6:30 am

Control Table Size

Post by latexhelp1 »

Thank you so much for your last reply! I love that new command with the C that you just wrote for me. It looks beautiful.
localghost wrote: This is a behaviour that you describe best with a proper
My apologies for the confusion! I had just posted an example, I suppose while you were responding to me. As you will see, I cannot get all of the numbers to fit in one row, and the same is true if I use landscape. At the same time, it looks like the width of the page is not being well exploited.

Here is the example:

Code: Select all

\documentclass[a4paper,titlepage]{article}
\usepackage[T1]{fontenc}
\usepackage[labelfont=bf,tableposition=top]{caption}
\usepackage{array,booktabs,tabularx,threeparttable}

% This code is taken from the UK TeX FAQ (http://www.tex.ac.uk/cgi-bin/texfaq2html?label=wholerow)
\newcolumntype{_}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{%
  \gdef\currentrowstyle{#1}%
  #1\ignorespaces
}

\begin{document}
  \begin{table}[!ht]
    \caption{Table caption}\label{tab:dummy}
    \centering
    \begin{threeparttable}
      \begin{tabularx}{\textwidth}{_l^X^X^X^X^X^X^X^X}\toprule
        \rowstyle{\small} & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\\midrule
        \rowstyle{\small}  Variable &  0.011\tnote{***} & 0.026\tnote{***} & -0.003\tnote{***}& -0.004\tnote{***} & -0.005\tnote{***} & -0.006\tnote{***} & -0.007\tnote{***} & -0.008\tnote{***}\\ \bottomrule\addlinespace
      \end{tabularx}
      \begin{tablenotes}
        \scriptsize
        \item[***] Notes:
      \end{tablenotes}
    \end{threeparttable}
  \end{table}
\end{document}
latexhelp1
Posts: 141
Joined: Sun Jun 12, 2011 6:30 am

Control Table Size

Post by latexhelp1 »

In response to our exchange, do you have a suggestion for how to do \multicommand type tables embedded within the table with an X?
localghost wrote:
latexhelp1 wrote:[…] Second, I am having trouble using \multicolumn in the middle of the table if I do have a longer table with some of the numbers filled in. The code simply won't compile, but I will attach what I am attempting to do. […]
This might need a different approach because "X" columns and the \multicolumn command are a complicated combination.
Here is an example of code that is not compiling:

Code: Select all

    \documentclass[a4paper,titlepage]{article}
    \usepackage[T1]{fontenc}
    \usepackage[labelfont=bf,tableposition=top]{caption}
    \usepackage{array,booktabs,tabularx,threeparttable}

    % This code is taken from the UK TeX FAQ (http://www.tex.ac.uk/cgi-bin/texfaq2html?label=wholerow)
    \newcolumntype{_}{>{\global\let\currentrowstyle\relax}}
    \newcolumntype{^}{>{\currentrowstyle}}
    \newcolumntype{C}{>{\centering\arraybackslash}X}
    \newcommand{\rowstyle}[1]{%
      \gdef\currentrowstyle{#1}%
      #1\ignorespaces
    }

\begin{document}

\begin{table}[!ht]
\caption{Table caption}\label{tab:dummy}
\centering
\begin{threeparttable}
\begin{tabularx}{\textwidth}{_l^C^C^C^C^C^C^C^C}\toprule
\rowstyle{\small} & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\\midrule  
\rowstyle{\small} \multicolumn{8}{c}{Panel A: Test} \\
\rowstyle{\small}  Variable &  0.011\tnote{***} & 0.026\tnote{***} & -0.003\tnote{***}& -0.004\tnote{***} & -0.005\tnote{***} & -0.006\tnote{***} & -0.007\tnote{***} & -0.008\tnote{***}\\ \bottomrule\addlinespace
\end{tabularx}
\begin{tablenotes}
\scriptsize
\item[***] Notes:
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Control Table Size

Post by localghost »

Now and then you should listen to the compiler and take a look at what it tells you in the log file. You are getting some warnings about overfull boxes. You can fix them by decreasing the font size to e. g. \footnotesize.

This is a bit confusing. You are now presenting a table where the font size for the complete content is decreased. In this case you won't need the new \rowstyle command and the corresponding column types because a simple switch at the right place would suffice. Would be good if you could clarify that and present a table that is closer to that in your final document.
latexhelp1
Posts: 141
Joined: Sun Jun 12, 2011 6:30 am

Control Table Size

Post by latexhelp1 »

localghost wrote:Now and then you should listen to the compiler and take a look at what it tells you in the log file. You are getting some warnings about overfull boxes. You can fix them by decreasing the font size to e. g. \footnotesize.
Yes, I am well aware that I can decrease the font size, as I originally wrote. As I also originally wrote, I am wondering whether I can just better exploit the width of the page and not decrease the font size. It appears as though there is at least 1-2 inches on both sides of the page (i.e. perhaps 3-4 inches total) that are not being exploited. I could be wrong on that account, but it just seems like there is an awful amount of white space on both sides of the table. And if that is not the case, shouldn't I be able to get more width if I use landscape? I don't think I am, not just because the problem doesn't go away, but because there is a lot of white space between the table and the page number, let alone between the page number and the end of the page.

In plain english, can I set the table so that is an 8.5 inch by 11 inch page, I am using a 1 in by 1 in margin, and the table is using the full 6.5 inches of width? It seems to me right now, the table is using maybe only 4-5 inches of width, at most.

Code: Select all

    \documentclass[a4paper,titlepage]{article}
    \usepackage[T1]{fontenc}
    \usepackage[labelfont=bf,tableposition=top]{caption}
    \usepackage{array,booktabs,tabularx,threeparttable}
    \usepackage{lscape}

    % This code is taken from the UK TeX FAQ (http://www.tex.ac.uk/cgi-bin/texfaq2html?label=wholerow)
    \newcolumntype{_}{>{\global\let\currentrowstyle\relax}}
    \newcolumntype{^}{>{\currentrowstyle}}
    \newcommand{\rowstyle}[1]{%
      \gdef\currentrowstyle{#1}%
      #1\ignorespaces
    }

    \begin{document}

\begin{landscape}
\begin{table}[!ht]
\caption{Table caption}\label{tab:dummy}
\centering
\begin{threeparttable}
\begin{tabularx}{\textwidth}{_l^X^X^X^X^X^X^X^X}\toprule
\rowstyle{\small} & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\\midrule
\rowstyle{\small}  Variable &  0.011\tnote{***} & 0.026\tnote{***} & -0.003\tnote{***}& -0.004\tnote{***} & -0.005\tnote{***} & -0.006\tnote{***} & -0.007\tnote{***} & -0.008\tnote{***}\\ \bottomrule\addlinespace
\end{tabularx}
\begin{tablenotes}
\scriptsize
\item[***] Notes:
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{landscape}
\end{document}
In any event, I do not want a font less than size 10 equivalent in Microsoft Word.

I would very much appreciate any help you could provide. Thank you so much.
Post Reply