Graphics, Figures & Tables ⇒ Control Table Size
-
- Posts: 141
- Joined: Sun Jun 12, 2011 6:30 am
Control Table Size
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}
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
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Control Table Size
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}
Code: Select all
texdoc tabularx
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
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 141
- Joined: Sun Jun 12, 2011 6:30 am
Re: Control Table Size
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?
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Control Table Size
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 wrote:[…] I do not understand what you mean in your comment about textdoc tabularx. Are you suggesting that I download something from the internet?
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 141
- Joined: Sun Jun 12, 2011 6:30 am
Control Table Size
localghost wrote: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 wrote:[…] I do not understand what you mean in your comment about textdoc tabularx. Are you suggesting that I download something from the internet?
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
_
Code: Select all
^
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}
My apologies for such a long message. I am deeply grateful for your help!
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Control Table Size
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'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. […]
latexhelp1 wrote:[…] I have some questions about.Code: Select all
{\textwidth}{_l^X^X^X}
What do theandCode: 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. […]Code: Select all
^
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.
Define a new column type, e. g. "C", and replace all "X" columns with it.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. […]
Code: Select all
\newcolumntype{C}{>{\centering\arraybackslash}X}
This is a behaviour that you describe best with a proper minimal example. Please follow the link and obey the instructions.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 might need a different approach because "X" columns and the \multicolumn command are a complicated combination.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. […]
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
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 141
- Joined: Sun Jun 12, 2011 6:30 am
Control Table Size
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.localghost wrote: This is a behaviour that you describe best with a proper
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}
-
- Posts: 141
- Joined: Sun Jun 12, 2011 6:30 am
Control Table Size
Here is an example of code that is not compiling:localghost wrote:This might need a different approach because "X" columns and the \multicolumn command are a complicated combination.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. […]
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}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Control Table Size
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.
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 141
- Joined: Sun Jun 12, 2011 6:30 am
Control Table Size
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.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.
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}
I would very much appreciate any help you could provide. Thank you so much.