I am creating a two-column document using latex. I use the option \columnwidth
to autofit a table to the column width, as shown in the following figure. The second column Value
is too wide. How do I set equal width for two columns?
Here is my source code.
\begin{table}
\centering
\caption{Simulation parameters}
\begin{tabular}{l|l}
\hline
Key & Value \\
\hline
simulation duration & 12 hours \\
update interval & 1s \\
time-to-live & 12 hours \\
buffer size & infinite \\
message interval & 20s \\
\hline
\end{tabular}
\end{table}
\begin{table}
\centering
\caption{Simulation parameters}
\begin{tabularx}{\columnwidth}{l|l}
\hline
Key & Value \\
\hline
simulation duration & 12 hours \\
update interval & 1s \\
time-to-live & 12 hours \\
buffer size & infinite \\
message interval & 20s \\
\hline
\end{tabularx}
\label{table: simulation parameters}
\end{table}
Best Answer
EDIT
@Mico pointed out a much better solution to this problem, as
tabularx
already comes with the column typeX
, which automatically does what you want:As you already know the total width of your table, you can define the width of the columns as a fraction of
\columnwidth