GeneralTable widths as a percentage of the page width

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Table widths as a percentage of the page width

Post by tripwire45 »

Can you specify the size of a table as a percentage of the total width of the page, rather than as an absolute value (such as 12cm)? I am creating a glossary out of a series of table. Each letter (A, B, C, and so on) is a subsection heading and each list of terms under each subsection is a separate table. Problem is, each table ends up being a different width, depending on the length of the lines in the two columns. I'd like to specify the size of the table so that all tables appear the same width.

I've tried using \resizebox which *does* make all the tables a uniform width, but it also changes the font size within each table accordingly. Here's what I've got right now:

Code: Select all

\subsection*{H}
\begingroup
\centering
\rowcolors{1}{webgreen!15}{}
\begin{tabular}{>{\small}l >{\small}p{8cm} } 
\textbf{Host} & This is a bunch of sample text to give you the general idea of what I'm talking about and how this thing looks right now. \\
\end{tabular}
\endgroup

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Table widths as a percentage of the page width

Post by Stefan Kottwitz »

Hi Trip,

try the tabularx package, its designed for tables of certain fixed width. Here ist the documentation.
You could use a width parameter depending on the textwidth, like 0.6\textwidth.

Stefan
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Table widths as a percentage of the page width

Post by tripwire45 »

I'd been reading about tabularc, tabularx, and tabulary, but wasn't sure if they'd fit the bill. Actually, I solved the problem of uniform tables in a completely different way...by specifying the size of both columns in the table thus:

Code: Select all

\subsection*{H}
\begingroup
\centering
\rowcolors{1}{webgreen!15}{}
\begin{tabular}{>{\small}p{3cm} >{\small}p{10cm} } 
\textbf{Host} & This is a bunch of sample text to give you the general idea of what I'm talking about and how this thing looks right now. \\
\end{tabular}
\endgroup
All's well that ends well in the inkwell (if anyone around here's old enough to remember *that* cartoon).
Post Reply