# Fix table cells width and alignment

TeX - LaTeX Asked by Mubeen on December 21, 2020

hope you all feeling well and safe

please help with the code below, the issue is with the cell width of last 3 column (3rd row onward), I want them to have similar width. please find attached code and picture

begin{table}[t]
centering
caption{Ranges and levels on independent variables}
label{tab:activation ranges}
begin{tabular}{|c|c|c|c|}
hline
multirow{2}{*}{textbf{Independent Variable}} & multicolumn{3}{c}{textbf{Ranges and Coded Levels}} \ cline{2-4}
& textbf{-1}      & textbf{0}      & textbf{+1}     \ hline
Acid concentration (%)                        &25               & 55              & 85              \ hline
Temperature (°C)                               & 45               & 80              & 115             \ hline
Residence time (min)                           & 60               & 120             & 180             \ hline
end{tabular}
end{table}


One can measure the width of the string textbf{Ranges and Coded Levels} and set the widths of columns 2 thru 4 to take up (roughly) one third of that width.

A separate recommendation: Do get rid of all vertical rules, and do replace the basic hline and cline directives with fewer but better-spaced lines using the macros of the booktabs package: toprule, midrule, cmidrule, and bottomrule.

documentclass{article}
usepackage{booktabs}
usepackage{array} % for 'w' column type
newlengthmylen
settowidthmylen{textbf{Ranges and Coded Levels}}
setlength{mylen}{dimexprmylen/3relax}

begin{document}
begin{table}[t]
centering
caption{Ranges and levels on independent variablesstrut}
label{tab:activation ranges}

begin{tabular}{@{} l *{3}{w{c}{mylen}} @{}}
toprule
textbf{Independent Variable} &
multicolumn{3}{[email protected]{}}{textbf{Ranges and Coded Levels}} \
cmidrule(l){2-4}
& $mathbf{-1}$ & textbf{0} & $mathbf{+1}$ \
midrule
Acid concentration (%) & 25 &  55 &  85 \ %hline
Temperature (°C)        & 45 &  80 & 115 \ %hline
Residence time (min)    & 60 & 120 & 180 \
bottomrule %hline
end{tabular}
end{table}
end{document}


Correct answer by Mico on December 21, 2020

I propose this layout with siunitx, so the numbers be right-aligned, and a well-chosen column-width. I added some improvements, such as loading caption to have a more sensible verical space between caption and table, and the first column left-aligned, which looks better in my opinion:

documentclass{article}

usepackage[table]{xcolor}
usepackage{booktabs}
usepackage{tabularx, multirow, caption, siunitx}
usepackage{makecell}

begin{document}

begin{table}[t]
setlength{extrarowheight}{2pt}
sisetup{table-format=3.0, table-number-alignment=center, table-column-width=12mm}
captionsetup{skip=4pt}
centering
caption{Ranges and levels on independent variables}
label{tab:activation ranges}
begin{tabular}{|l|S|S|S|}
hline
multirow{2}{*}{textbf{Independent Variable}} & multicolumn{3}{@{}[email protected]{}|}{textbf{Ranges and Coded Levels}} \ cline{2-4}
& {$mathbf{-1}$} & {textbf{0}} & {$mathbf{+1}$} \ hline
Acid concentration (%) &25 & 55 & 85 \ hline
Temperature (°C) & 45 & 80 & 115 \ hline
Residence time (min) & 60 & 120 & 180 \ hline
end{tabular}
end{table}

end{document}


Answered by Bernard on December 21, 2020

## Related Questions

### How to create different types of changebars

1  Asked on June 4, 2021

### Table text overlaps while using p

1  Asked on June 4, 2021

### How can I use LaTeX to build my website?

6  Asked on June 4, 2021 by prabhanjan-naib

### How to run spell check in Overleaf?

0  Asked on June 4, 2021 by finstats

### Why is it necessary to specify textnormal?

1  Asked on June 4, 2021

### Store the expanded version of a macro into another macro in the plain format

4  Asked on June 4, 2021

### Help with bar accent

1  Asked on June 4, 2021 by swashbuckl3r666

### Stretchable space that allows line-break but doesn’t allow page-break

0  Asked on June 4, 2021

### Image not showing In LaTex

1  Asked on June 4, 2021 by nuno-ferreira

### Format Using TColorbox

1  Asked on June 4, 2021 by nick-bennett

### Trajan font not displayed properly

1  Asked on June 4, 2021

### How can I get something like this in the book class?

1  Asked on June 4, 2021 by brazilianaeronautics

### What is causing (and how can I fix) “Misplaced cr” and “Misplaced alignment tab” errors in an array environment when trying to compile my .dtx?

1  Asked on June 4, 2021

### How to eliminate the indent in reference

0  Asked on June 4, 2021 by aquariumday

### Miktex 2.9 for windows 10

0  Asked on June 4, 2021

### Rotating surface in z axis

1  Asked on June 4, 2021

### package arydshln breaks package vhistory

1  Asked on June 4, 2021

### pgfplots: 2D contour plot of 3D function: placement of axes labels

2  Asked on June 4, 2021 by peutch

### How to create a macro that manipulates the author’s name?

2  Asked on June 4, 2021

### What to do when in-text citations are not returning ordered numbers (one not appearing correctly)?

0  Asked on June 3, 2021 by fzm