## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Several problem with a small table

Information and discussion about graphics, figures & tables in LaTeX documents.
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

### Several problem with a small table

I'm experiencing three problems with this table, and I don't know how to fix them :
\documentclass[11pt,twoside]{book}\usepackage[T1]{fontenc}\usepackage[total={6.25in,10in},left=1.25in,top=0.5in]{geometry}\usepackage{amsmath}\usepackage{graphicx}\usepackage[dvipsnames,table]{xcolor}\usepackage{float}\usepackage{tabularx} \begin{document} \begin{table}[H]	\centering	\newcommand{\mystrut}{\rule[-6pt]{0pt}{20pt}}	\begin{tabular}{l|@{}!{\mystrut}>{\centering}m{3.5em}|c|c|!{}>{}m{4em}}	\cline{2-4}		\rowcolor[gray]{0.95} % <--- problem here		& \multicolumn{3}{@{}!{\mystrut}c|}{Some funny title}		\\ \cline{2-4}		& \multicolumn{1}{>{\centering}m{6em}|}{Word 1}		& \multicolumn{1}{>{\centering}m{6em}|}{Word 2}		& \multicolumn{1}{>{\centering}m{6em}|}{Word 3}		&		\\ \cline{1-4}		\multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Disk} & 1 & 2 & 3 & \\ \cline{1-4}		\multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Sphere} & 1 & 2 & 3 & \\ \cline{1-4}		\multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Cylinder} & 1 & 2 & 3 & \\ \cline{1-4}	\end{tabular}	\caption{Some description.}\end{table} \end{document}

Preview with issues shown in red :
table.jpg (28.09 KiB) Viewed 222 times

1. I need the title to be on a gray background, but currently the gray rectangle is too large at the left side. How to remove that part?

2. The "1" in the second column aren't properly centered in their column. How to fix that?

3. I need the main part of the table to be centered on the page, so I added an empty column to the right. Something is wrong in my code, since the last vertical line isn't at the proper position. How to fix it?

Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm
I fixed issues #2 and #3 above :
\documentclass[11pt,twoside]{book}\usepackage[total={6.25in,10in},left=1.25in,top=0.5in]{geometry}\usepackage{graphicx}\usepackage[dvipsnames,table]{xcolor}\usepackage{float}\usepackage{tabularx} \begin{document} \begin{table}[H]	\centering	\newcommand{\mystrut}{\rule[-6pt]{0pt}{20pt}}	\begin{tabular}{l|@{}!{\mystrut}>{\centering}m{6em}|!{}>{\centering}m{6em}|!{}>{\centering}m{6em}|l}	\cline{2-4}		\cellcolor[gray]{0.95} % <--- problem here		& \multicolumn{3}{@{}!{\mystrut}c|}{Some funny title}		\\ \cline{2-4}		& Word 1 & Word 2 & Word 3 &		\\ \cline{1-4}		\multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Disk} & 1 & 2 & 3 & \multicolumn{1}{!{\mystrut}>{}m{4em}}{} \\ \cline{1-4}		\multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Sphere} & 1 & 2 & 3 & \\ \cline{1-4}		\multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Cylinder} & 1 & 2 & 3 & \\ \cline{1-4}	\end{tabular}	\caption{Some description.}\end{table} \end{document}

Preview :
table2.jpg (23.27 KiB) Viewed 214 times

But then I need to fix the gray background under the title. Using the command \cellcolor in the title cell correctly doesn't fix that issue, since the top horizontal bar becomes very very thin (almost invisible). I need help there!

Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm
I removed the title and its gray background for simplicity. And I want the full table to be horizontally centered on the page. Now the problem is getting worst!
I'll never be able to understand tables in LaTeX

This code has problems :
\documentclass[11pt,twoside]{book}\usepackage[total={6.25in,10in},left=1.25in,top=0.5in]{geometry}\usepackage{graphicx}\usepackage{tabularx}\begin{document} \begin{table}	\centering	\newcommand{\mystrut}{\rule[-6pt]{0pt}{20pt}}	\begin{tabular}{l|@{}!{\mystrut}>{\centering}m{6em}|!{}>{\centering}m{6em}|!{}>{\centering}m{6em}|}	\cline{2-4}		& Word 1 & Word 2 & Word 3		\\ \cline{1-4}		\multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Disk} & 1 & 2 & 3		\\ \cline{1-4}		\multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Sphere} & 1 & 2 & 3		\\ \cline{1-4}		\multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Cylinder} & 1 & 2 & 3		\\ \cline{1-4}	\end{tabular}	\caption{Some description.}\end{table} \end{document}

What is wrong here? I want all items to be centered in its cell (vertically and horizontally). I need all the columns to have the same width, except the first one. What am I doing wrong?