1
\documentclass{article}
\usepackage{tabularx}
\usepackage{lscape}

\newcolumntype{b}{X}
\newcolumntype{s}{>{\hsize=.2\hsize}X}
\newcolumntype{m}{>{\hsize=.4\hsize}X}

\begin{document}
\begin{landscape}

\noindent\resizebox{\textwidth}{!}{%
\begin{tabularx}{\linewidth}{m s s m b}
Variable Name & Years Available & Model(s) & Source & Notes\\

\end{tabularx}
%}
\end{landscape}
\end{document} 

Edit: I would like to use tabularx because the text in my "Notes" section is long, and I would like the text to wrap easily.

In addition, I have many rows, so I decided to include \resizebox to make all the text fit in one page

  • What is the question? Why you force table (with resizebox) in landscape to be wide only text width (of portrait page)? \textwidth is determined by article orientation which is srill portrait! If you change width of X column types, then the sum of new sizes had to be integer number (what in your case is not: m + s + s + m + b = .4 + .2 +.2 + .4 + 1 = 2.2; for example correct values are .3 + .2 +.2 + .3 + 1 = 2). – Zarko Nov 5 '16 at 8:28
  • 1
    why are you applying \resizebox to the table, scaling tables should only be done as an absolute last resort. – David Carlisle Nov 5 '16 at 9:01
7

I suppose you want the m column type width should be 40 % of the b type width, and the s type width half the m type width. The way you calculated the coefficients is not correct: the sum of the coefficients should be equal to the number of columns, and they should have this relation of proportionality. This yields coefficients approximately equal, in increasing order, to 0.45, 0.90, 2.3.

I do not see why you should use \resizebox. It should be avoided as much as possible, as it also changes the font size and may yield unreadable text. Comment aside, the namers of the new column types is not well chosen, as m and b are already defined by the array package, and you'll have conflicts sooner or later.

\documentclass{article}
\usepackage{tabularx}
\usepackage{lscape}
 \newcolumntype{b}{>{\hsize=2.3\hsize}X}
\newcolumntype{s}{>{\hsize=.45\hsize}X}
\newcolumntype{m}{>{\hsize=.9\hsize}X}

\begin{document}

\begin{landscape}
  \noindent
  \begin{tabularx}{\linewidth}{|m| s| s| m| b|}
    \hline
    Variable Name & Years Available & Model(s) & Source & Notes \\
    \hline
  \end{tabularx}
\end{landscape}

\end{document}

enter image description here

  • could you briefly explain why the choice of 2.3, .45, and .9 is appropriate? As for your question about resizebox, I have many rows in this table and I wanted everything to fit on one page. Is there a better way of doing this? – Zslice Nov 5 '16 at 2:43
  • 1
    @Zslice 2.3+2*0.45+2*0.9=5, the number of X columns, but perhaps a better question is why use tabularx here at all? Your question does not give any indication why it is needed. compared to just using tabular and {lllll} and let the system choose appropriate column widths. – David Carlisle Nov 5 '16 at 9:08
  • 1
    @Zslice: I solved the linear system 2s + 2m + b=5 (with obvious notations), m = 2s, b = 2.5m, then rounded the solutions to sensible values, while keeping a total of 5. – Bernard Nov 5 '16 at 10:31
  • @Zslice, see my comment after your question ... – Zarko Nov 5 '16 at 19:08
  • +1 for "I do not see why you should use \resizebox. It should be avoided as much as possible". – Mico Nov 5 '16 at 20:01
4

Edit: As supplement to Bernard answer and extension of my comments.

With resizing your table to \textwidth in landscape orientation means that you you shrink your table to \textwidth of portrait page and consequently you will have a lot os empti space before and after table.

To be table of full width of landscape orientation, than you need to resize it to \textheight. However, this is already done with

\begin{tabularx}{\linewidth}{...}

so there is no need for use \resizebox.

It seems that (concluding from your MWE) to set table in normal portrait page orientation and eventually reduce font size in table. If table is to tall, than you need considering ltablex package.

Regarding columns width in tabularx see my comment above:

If you change width of X column types, then the sum of new sizes had to be integer number (what in your case is not: m + s + s + m + b = .4 + .2 +.2 + .4 + 1 = 2.2; for example correct values are .3 + .2 +.2 + .3 + 1 = 2)

Considering this rule but with different values, in portrait orientation you table heads looks as follows:

enter code here

\documentclass{article}
\usepackage{tabularx}
\usepackage{geometry}

\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}

\begin{document}
\noindent
\begin{table}
\setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{|>{\hsize=0.5\hsize}X|
                              >{\hsize=0.4\hsize}X|
                              >{\hsize=0.4\hsize}X|
                              >{\hsize=0.3\hsize}X|
                              >{\hsize=1.4\hsize}X|}                        
\hline
Variable Name & Years\newline Available & Model(s) & Source & Notes\\
\hline
\end{tabularx}
\end{table}
\end{document}

In the case of use ltablex package, than above MWE should be extended to the something like this:

\documentclass{article}
\usepackage{geometry}
\usepackage{ltablex}

\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}

\begin{document}
\noindent

{
\setlength\tabcolsep{3pt}
\keepXColumns
\begin{tabularx}{\linewidth}{|>{\hsize=0.5\hsize}X|
                              >{\hsize=0.4\hsize}X|
                              >{\hsize=0.4\hsize}X|
                              >{\hsize=0.3\hsize}X|
                              >{\hsize=1.4\hsize}X|} 
\caption{my table}
\label{my huge tablew}  \\                       
\hline
Variable Name & Years\newline Available & Model(s) & Source & Notes\\
\hline
\endfirsthead
\hline
Variable Name & Years\newline Available & Model(s) & Source & Notes\\
\hline
\endhead
\hline
\multicolumn{5}{r}{continue on the next page}
\endfoot
\hline
\endlastfoot
% table content
a   &   b   &   c   &   d   &   \\ 
a   &   b   &   c   &   d   &  
\end{tabularx}
}
\end{document}

which gives:enter image description here

Above MWE you can use also in landscape orientation. In this case you need to enclose table (all inside curly braces around table in above MWE) in \begin{landscape} ... \end{landscape}

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.