# How to set column width such that the vertical size is as small as possible?

For example, in Word, if two columns are at 50% linewidth each, it would give:

After playing around with the column widths, I can minimise the vertical size of the table:

Is there a way to implement this in Latex?

Edit: a MWE:

\documentclass{article}

\usepackage{booktabs}
\usepackage{tabularx}

\begin{document}

\section*{Variables}

\begin{table}
\centering
\begin{tabularx}{\textwidth}{X|X}
\toprule
Variables & Treatment \\
\midrule
Independent & \\
The angle between the ramp and the flat surface & The ramp is elevated by placing books underneath one end of the ramp, and the angle is fine-tuned using the screws in the feet. The angle is measured using the protractor, which is attached to the ramp. The angles used were 10, 15, 20, 25 and 30.\\
\bottomrule
\end{tabularx}
\caption{List of variables and treatment}
\label{tab:my_label}
\end{table}

\end{document}

• Please make a minimal working example (MWE) – samcarter_is_at_topanswers.xyz Sep 4 '18 at 11:36
• @samcarter Done – George Tian Sep 4 '18 at 11:39
• An automatic process would be difficult and time consuming, and at most should be done once. Also, for a range of ratios which produce the same number of lines, you probably want the one closest to 1. – John Kormylo Sep 4 '18 at 12:10
• your example produces ! Package inputenc Error: Unicode character ° (U+B0) – David Carlisle Sep 4 '18 at 12:23
• @DavidCarlisle Sorry, I have edited and removed the degree symbols – George Tian Sep 4 '18 at 12:26

tabulary is closer to what you need than tabularx

\documentclass{article}

\usepackage{booktabs}
\usepackage{tabulary}

\begin{document}

\section*{Variables}

\begin{table}
\centering
\begin{tabulary}{\textwidth}{L|L}
\toprule
Variables & Treatment \\
\midrule
Independent & \\
The angle between the ramp and the flat surface & The ramp is elevated by placing books underneath one end of the ramp, and the angle is fine-tuned using the screws in the feet. The angle is measured using the protractor, which is attached to the ramp. The angles used were 10, 15, 20, 25 and 30.\\
\bottomrule
\end{tabulary}
\caption{List of variables and treatment}
\label{tab:my_label}
\end{table}

\end{document}


Normally all X of a tabularx are set to the same width. You could shift the ratio by using >{\hsize=0.45\hsize}X>{\hsize=1.55\hsize}X (make sure that the sum of all the \hsize equals to the number of X columns). This needs some manual adjustment of the exact values.

Another option could be to use tabulary as in the second example below.

\documentclass{article}

\usepackage{booktabs}
\usepackage{tabulary}
\usepackage{tabularx}

\begin{document}

\begin{table}
\centering
\begin{tabularx}{\textwidth}{@{}>{\hsize=0.35\hsize}X>{\hsize=1.65\hsize}X@{}}
\toprule
Variables & Treatment \\
\midrule
The angle between the ramp and the flat surface & The ramp is elevated by placing books underneath one end of the ramp, and the angle is fine-tuned using the screws in the feet. The angle is measured using the protractor, which is attached to the ramp. The angles used were 10, 15, 20, 25 and 30.\\
\bottomrule
\end{tabularx}
\caption{List of variables and treatment}
\label{tab:my_label1}
\end{table}

\begin{table}
\centering
\begin{tabulary}{\textwidth}{@{}LJ@{}}
\toprule
Variables & Treatment \\
\midrule

• Thank you, the second method seems to automatically adjust the widths, which solves my problem. I've been trying to decipher the following: {@{}LJ@{}}. Could you please explain what this snippet does? – George Tian Sep 4 '18 at 12:07
• @GeorgeTian The @{} makes the rules the same length as the text, L make the cells in this column left aligned (looks IMHO better for such short lines) and J makes the content of this column justified. – samcarter_is_at_topanswers.xyz Sep 4 '18 at 12:09
• @GeorgeTian perhaps a better explanation of what @ does is, it changes the content added automatically at this side of the column (or in between two columns, if it is used between two column specifications) to the stuff you give it as its argument. So @{} changes the padding from \hskip\tabcolsep to nothing, while @{a} would insert an a in each line. – Skillmon Sep 4 '18 at 14:04