4

Approach 1:
Using tabularx with flexible columns

  1. I am using tabularx with two X columns and 8 columns total. Why am I still getting Overfull \hbox warnings?

  2. How can I make a LaTeX table with long well names and API numbers fit within \textwidth using tabularx?

  3. Is there a way to allow tabularx columns to wrap text aggressively to prevent overlapping?

\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{tabularx,ragged2e,booktabs,caption,float,array} \begin{document} \begin{table}[h] \centering \renewcommand{\arraystretch}{1.2} % a little more row spacing \begin{tabularx}{\textwidth}{|c|X|X|c|c|c|c|c|} \hline \textbf{\#} & \textbf{Well Name} & \textbf{API Number} & \textbf{Location} & \textbf{Date} & \textbf{Event} & \textbf{Top (ft)} & \textbf{Bottom (ft)} \\ \hline 1 & PRITCHARD SWD \#001 & 30-045-28351 & NM & 01/01/1994 & Perf & 8383 & 8560 \\ \hline 2 & SALTY DOG SWD \#003R & 30-045-31274 & NM & 04/01/2003 & Perf & 6961 & 7038 \\ \hline 3 & STANOLIND GAS COM SWD \#001 & 30-045-23779 & NM & 05/01/2004 & Perf & 7254 & 7400 \\ \hline 4 & BIG FIELD SWD \#009 & 30-045-32258 & NM & 12/01/2004 & Perf & 7176 & 7323 \\ \hline 5 & SALTY DOG SWD \#005 & 30-045-29000 & NM & 03/01/2006 & Perf & 6494 & 6657 \\ \hline 6 & SALTY DOG SWD \#006 & 30-045-32943 & NM & 07/01/2006 & Perf & 6756 & 6898 \\ \hline 7 & SPONGE BOB SWD \#001 & 30-045-33927 & NM & 11/01/2006 & Perf & 7075 & 7220 \\ \hline 8 & WASTE DISPOSAL WELL \#002 & 30-045-35747 & NM & 03/01/2017 & Perf & 7323 & 7484 \\ \hline \end{tabularx} \caption{Details of saltwater disposal wells used for hydrodynamic model calibration.} \label{table:wells} \end{table} \end{document} 

Approach 2:
Using Fixed-width p{} columns I set fixed widths for some columns (p{2cm} and p{1cm}), but my table still produces overfull \hbox warnings. How can I adjust the column widths correctly?

How can I balance widths for a table with long well names and short numeric columns in LaTeX?

\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{tabularx,ragged2e,booktabs,caption,float,array} \begin{document} \begin{table}[H] \centering \renewcommand{\arraystretch}{1.2} % more row spacing \begin{tabular}{|c|p{2cm}|p{1cm}|c|c|c|c|c|} \hline \textbf{\#} & \textbf{Well Name} & \textbf{API Number} & \textbf{Location} & \textbf{Date} & \textbf{Event} & \textbf{Top (ft)} & \textbf{Bottom (ft)} \\ \hline 1 & PRITCHARD SWD \#001 & 30-045-28351 & NM & 01/01/1994 & Perf & 8383 & 8560 \\ \hline 2 & SALTY DOG SWD \#003R & 30-045-31274 & NM & 04/01/2003 & Perf & 6961 & 7038 \\ \hline 3 & STANOLIND GAS COM SWD \#001 & 30-045-23779 & NM & 05/01/2004 & Perf & 7254 & 7400 \\ \hline 4 & BIG FIELD SWD \#009 & 30-045-32258 & NM & 12/01/2004 & Perf & 7176 & 7323 \\ \hline 5 & SALTY DOG SWD \#005 & 30-045-29000 & NM & 03/01/2006 & Perf & 6494 & 6657 \\ \hline 6 & SALTY DOG SWD \#006 & 30-045-32943 & NM & 07/01/2006 & Perf & 6756 & 6898 \\ \hline 7 & SPONGE BOB SWD \#001 & 30-045-33927 & NM & 11/01/2006 & Perf & 7075 & 7220 \\ \hline 8 & WASTE DISPOSAL WELL \#002 & 30-045-35747 & NM & 03/01/2017 & Perf & 7323 & 7484 \\ \hline \end{tabular} \caption{Details of saltwater disposal wells used for hydrodynamic model calibration.} \label{table:wells} \end{table} \end{document} 

3 Answers 3

7

Try and save some space. The problematic column can be set to have width as the widest word, in this case “PRITCHARD”.

With \small size this fits in a standard textwidth.

\documentclass{article} %\usepackage[utf8]{inputenc} % no longer necessary \usepackage[T1]{fontenc} \usepackage{ragged2e,booktabs,array} \newlength{\tabwidth} \begin{document} \begin{table}[htp] \centering \small \renewcommand{\arraystretch}{1.2} % a little more row spacing \newcommand{\splitcell}[1]{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}} \settowidth{\tabwidth}{PRITCHARD} \begin{tabular}{@{}c >{\raggedright}p{\tabwidth}cccccc@{}} \toprule \# & Well Name & API Number & Loc. & Date & Event & \splitcell{Top \\ (ft)} & \splitcell{Bottom \\ (ft)} \\ \midrule 1 & PRITCHARD SWD \#001 & 30-045-28351 & NM & 01/01/1994 & Perf & 8383 & 8560 \\ 2 & SALTY DOG SWD \#003R & 30-045-31274 & NM & 04/01/2003 & Perf & 6961 & 7038 \\ 3 & STANOLIND GAS COM SWD \#001 & 30-045-23779 & NM & 05/01/2004 & Perf & 7254 & 7400 \\ 4 & BIG FIELD SWD \#009 & 30-045-32258 & NM & 12/01/2004 & Perf & 7176 & 7323 \\ 5 & SALTY DOG SWD \#005 & 30-045-29000 & NM & 03/01/2006 & Perf & 6494 & 6657 \\ 6 & SALTY DOG SWD \#006 & 30-045-32943 & NM & 07/01/2006 & Perf & 6756 & 6898 \\ 7 & SPONGE BOB SWD \#001 & 30-045-33927 & NM & 11/01/2006 & Perf & 7075 & 7220 \\ 8 & WASTE DISPOSAL WELL \#002 & 30-045-35747 & NM & 03/01/2017 & Perf & 7323 & 7484 \\ \bottomrule \end{tabular} \caption{Details of saltwater disposal wells used for hydrodynamic model calibration.} \label{table:wells} \end{table} \end{document} 

output

You can make the table caged, if you so prefer. I wouldn't.

\begin{table}[htp] \centering \small \renewcommand{\arraystretch}{1.2} % a little more row spacing \newcommand{\splitcell}[1]{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}} \settowidth{\tabwidth}{PRITCHARD} \addtolength{\tabcolsep}{-1pt} \begin{tabular}{|c| |>{\raggedright}p{\tabwidth}|c|c|c|c|c|c|} \hline \# & Well Name & API Number & Loc. & Date & Event & \splitcell{Top \\ (ft)} & \splitcell{Bottom \\ (ft)} \\ \hline 1 & PRITCHARD SWD \#001 & 30-045-28351 & NM & 01/01/1994 & Perf & 8383 & 8560 \\ \hline 2 & SALTY DOG SWD \#003R & 30-045-31274 & NM & 04/01/2003 & Perf & 6961 & 7038 \\ \hline 3 & STANOLIND GAS COM SWD \#001 & 30-045-23779 & NM & 05/01/2004 & Perf & 7254 & 7400 \\ \hline 4 & BIG FIELD SWD \#009 & 30-045-32258 & NM & 12/01/2004 & Perf & 7176 & 7323 \\ \hline 5 & SALTY DOG SWD \#005 & 30-045-29000 & NM & 03/01/2006 & Perf & 6494 & 6657 \\ \hline 6 & SALTY DOG SWD \#006 & 30-045-32943 & NM & 07/01/2006 & Perf & 6756 & 6898 \\ \hline 7 & SPONGE BOB SWD \#001 & 30-045-33927 & NM & 11/01/2006 & Perf & 7075 & 7220 \\ \hline 8 & WASTE DISPOSAL WELL \#002 & 30-045-35747 & NM & 03/01/2017 & Perf & 7323 & 7484 \\ \hline \end{tabular} \caption{Details of saltwater disposal wells used for hydrodynamic model calibration.} \label{table:wells} \end{table} 

caged

A different approach:

\documentclass{article} %\usepackage[utf8]{inputenc} % no longer necessary \usepackage[T1]{fontenc} \usepackage{ragged2e,booktabs,array} \begin{document} \begin{table}[htp] \centering \setlength{\tabcolsep}{0pt} \newcommand{\well}[2]{\multicolumn{7}{@{}l@{}}{Well #1: \itshape #2}\\} \begin{tabular*}{\textwidth}{@{}>{\hspace*{4em}}c@{\extracolsep{\fill}}cccccc@{}} \toprule & API Number & Location & Date & Event & Top (ft) & Bottom (ft) \\ \midrule \well{1}{PRITCHARD SWD \#001} & 30-045-28351 & NM & 01/01/1994 & Perf & 8383 & 8560 \\ \addlinespace \well{2}{SALTY DOG SWD \#003R} & 30-045-31274 & NM & 04/01/2003 & Perf & 6961 & 7038 \\ \addlinespace \well{3}{STANOLIND GAS COM SWD \#001} & 30-045-23779 & NM & 05/01/2004 & Perf & 7254 & 7400 \\ \addlinespace \well{4}{BIG FIELD SWD \#009} & 30-045-32258 & NM & 12/01/2004 & Perf & 7176 & 7323 \\ \addlinespace \well{5}{SALTY DOG SWD \#005} & 30-045-29000 & NM & 03/01/2006 & Perf & 6494 & 6657 \\ \addlinespace \well{6}{SALTY DOG SWD \#006} & 30-045-32943 & NM & 07/01/2006 & Perf & 6756 & 6898 \\ \addlinespace \well{7}{SPONGE BOB SWD \#001} & 30-045-33927 & NM & 11/01/2006 & Perf & 7075 & 7220 \\ \addlinespace \well{8}{WASTE DISPOSAL WELL \#002} & 30-045-35747 & NM & 03/01/2017 & Perf & 7323 & 7484 \\ \bottomrule \end{tabular*} \caption{Details of saltwater disposal wells used for hydrodynamic model calibration.} \label{table:wells} \end{table} \end{document} 

alternative approach

7

Something like this?

enter image description here

Your table is quit wide so you have problem to fit it in default textwidth. If possible, enlarge \textwidth by use of the geometry package and reduce font size in table as I do in MWE below. For table i use tblr of tabularray package and for the second and third column use X column type with width ration 1.15:0.85. Also for numbers in the first column is employed row numbering:

\documentclass{article} \usepackage{geometry} \usepackage[T1]{fontenc} \usepackage{tabularray} \usepackage[font=small, labelfont=bf, skip=1ex]{caption} \begin{document} \begin{table}[ht] \centering \small \begin{tblr}{hlines, vlines, colsep=4pt, colspec = {c X[1.15, l] X[0.85, l] *{5}{c}}, cell{2-Z}{1} = {cmd=\the\numexpr\arabic{rownum}-1.},% <--- row{1} = {font=\bfseries} } \# & Well Name & API Number & Location & Date & Event & Top (ft) & Bottom (ft) \\ & PRITCHARD SWD \#001 & 30-045-28351 & NM & 01/01/1994 & Perf & 8383 & 8560 \\ & SALTY DOG SWD \#003R & 30-045-31274 & NM & 04/01/2003 & Perf & 6961 & 7038 \\ & STANOLIND GAS COM SWD \#001 & 30-045-23779 & NM & 05/01/2004 & Perf & 7254 & 7400 \\ & BIG FIELD SWD \#009 & 30-045-32258 & NM & 12/01/2004 & Perf & 7176 & 7323 \\ & SALTY DOG SWD \#005 & 30-045-29000 & NM & 03/01/2006 & Perf & 6494 & 6657 \\ & SALTY DOG SWD \#006 & 30-045-32943 & NM & 07/01/2006 & Perf & 6756 & 6898 \\ & SPONGE BOB SWD \#001 & 30-045-33927 & NM & 11/01/2006 & Perf & 7075 & 7220 \\ & WASTE DISPOSAL WELL \#002 & 30-045-35747 & NM & 03/01/2017 & Perf & 7323 & 7484 \\ \end{tblr} \caption{Details of saltwater disposal wells used for hydrodynamic model calibration.} \label{table:wells} \end{table} \end{document} 

Addendum A:
If you enable to write some column headers in two rows and use for example lmodern font, table can be fit in default \textwidth. See MWE below:

\documentclass{article} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage{tabularray} \usepackage[font=small, labelfont=bf, skip=1ex]{caption} \begin{document} \begin{table}[ht] \centering \small \begin{tblr}{hlines, vlines, colsep=4pt, colspec = {c X[1.15, l] X[0.75, l] *{5}{c}}, cell{2-Z}{1} = {cmd=\the\numexpr\arabic{rownum}-1.},% <--- row{1} = {font=\bfseries, m} } \# & Well Name & API Number & Location & Date & Event & {Top\\ (ft)} & {Bottom\\ (ft)} \\ & PRITCHARD SWD \#001 & 30-045-28351 & NM & 01/01/1994 & Perf & 8383 & 8560 \\ & SALTY DOG SWD \#003R & 30-045-31274 & NM & 04/01/2003 & Perf & 6961 & 7038 \\ & STANOLIND GAS COM SWD \#001 & 30-045-23779 & NM & 05/01/2004 & Perf & 7254 & 7400 \\ & BIG FIELD SWD \#009 & 30-045-32258 & NM & 12/01/2004 & Perf & 7176 & 7323 \\ & SALTY DOG SWD \#005 & 30-045-29000 & NM & 03/01/2006 & Perf & 6494 & 6657 \\ & SALTY DOG SWD \#006 & 30-045-32943 & NM & 07/01/2006 & Perf & 6756 & 6898 \\ & SPONGE BOB SWD \#001 & 30-045-33927 & NM & 11/01/2006 & Perf & 7075 & 7220 \\ & WASTE DISPOSAL WELL \#002 & 30-045-35747 & NM & 03/01/2017 & Perf & 7323 & 7484 \\ \end{tblr} \caption{Details of saltwater disposal wells used for hydrodynamic model calibration.} \label{table:wells} \end{table} \end{document} 

enter image description here

Addendum B:
In case when you change table preamble and table's column headers in the second example to:

\begin{tblr}{hline{1,Z} = {0.8pt}, hline{2}={0.2pt}, colsep=3pt, colspec = {@{} c X[l] l *{5}{c} @{}}, cell{2-Z}{1} = {cmd=\the\numexpr\arabic{rownum}-1.},% <--- row{1} = {font=\bfseries,c, m} } \# & Well Name & {API\\ Number}& Loc. & Date & Event & {Top\\ (ft)} 

than your table will become as follows:

enter image description here

6

I suggest you keep the tabularx setup but (a) not bold-face the contents of the header row and (b) organize the header row more clearly. That way, only column 2 needs to given the X column type.

Aside: What's the purpose of rendering the words in column 2 in ALL-UPPERCASE?

enter image description here

\documentclass{article} %\usepackage[utf8]{inputenc} % that's the default nowadays \usepackage[T1]{fontenc} \usepackage{tabularx,ragged2e,booktabs,caption,float} \newcolumntype{L}{>{\RaggedRight}X} \begin{document} \begin{table}[h] % \centering % redundant \setlength\tabcolsep{3pt} % default: 6pt %\renewcommand{\arraystretch}{1.2} % a little more row spacing \begin{tabularx}{\textwidth}{@{} lLlccccc @{}} \toprule \# & Well name & API no. & Location & Date & Event & Top & Bottom \\ & & & & & & (ft) & (ft) \\ \midrule 1 & PRITCHARD SWD \#001 & 30-045-28351 & NM & 01/01/1994 & Perf & 8383 & 8560 \\ \addlinespace 2 & SALTY DOG SWD \#003R & 30-045-31274 & NM & 04/01/2003 & Perf & 6961 & 7038 \\ \addlinespace 3 & STANOLIND GAS COM SWD \#001 & 30-045-23779 & NM & 05/01/2004 & Perf & 7254 & 7400 \\ \addlinespace 4 & BIG FIELD SWD \#009 & 30-045-32258 & NM & 12/01/2004 & Perf & 7176 & 7323 \\ \addlinespace 5 & SALTY DOG SWD \#005 & 30-045-29000 & NM & 03/01/2006 & Perf & 6494 & 6657 \\ \addlinespace 6 & SALTY DOG SWD \#006 & 30-045-32943 & NM & 07/01/2006 & Perf & 6756 & 6898 \\ \addlinespace 7 & SPONGE BOB SWD \#001 & 30-045-33927 & NM & 11/01/2006 & Perf & 7075 & 7220 \\ \addlinespace 8 & WASTE DISPOSAL WELL \#002 & 30-045-35747 & NM & 03/01/2017 & Perf & 7323 & 7484 \\ \bottomrule \end{tabularx} \caption{Details of saltwater disposal wells used for hydrodynamic model calibration.} \label{table:wells} \end{table} \end{document} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.