LaTeX forum ⇒ Graphics, Figures & TablesSeveral problem with a small table

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

Several problem with a small table

Postby Cham » Fri Jun 15, 2018 5:51 pm

I'm experiencing three problems with this table, and I don't know how to fix them :
  1. \documentclass[11pt,twoside]{book}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[total={6.25in,10in},left=1.25in,top=0.5in]{geometry}
  4. \usepackage{amsmath}
  5. \usepackage{graphicx}
  6. \usepackage[dvipsnames,table]{xcolor}
  7. \usepackage{float}
  8. \usepackage{tabularx}
  9.  
  10. \begin{document}
  11.  
  12. \begin{table}[H]
  13. \centering
  14. \newcommand{\mystrut}{\rule[-6pt]{0pt}{20pt}}
  15. \begin{tabular}{l|@{}!{\mystrut}>{\centering}m{3.5em}|c|c|!{}>{}m{4em}}
  16. \cline{2-4}
  17. \rowcolor[gray]{0.95} % <--- problem here
  18. & \multicolumn{3}{@{}!{\mystrut}c|}{Some funny title}
  19. \\ \cline{2-4}
  20. & \multicolumn{1}{>{\centering}m{6em}|}{Word 1}
  21. & \multicolumn{1}{>{\centering}m{6em}|}{Word 2}
  22. & \multicolumn{1}{>{\centering}m{6em}|}{Word 3}
  23. &
  24. \\ \cline{1-4}
  25. \multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Disk} & 1 & 2 & 3 & \\ \cline{1-4}
  26. \multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Sphere} & 1 & 2 & 3 & \\ \cline{1-4}
  27. \multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Cylinder} & 1 & 2 & 3 & \\ \cline{1-4}
  28. \end{tabular}
  29. \caption{Some description.}
  30. \end{table}
  31.  
  32. \end{document}


Preview with issues shown in red :
table.jpg
table.jpg (28.09 KiB) Viewed 223 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?

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Fri Jun 15, 2018 6:47 pm

I fixed issues #2 and #3 above :
  1. \documentclass[11pt,twoside]{book}
  2. \usepackage[total={6.25in,10in},left=1.25in,top=0.5in]{geometry}
  3. \usepackage{graphicx}
  4. \usepackage[dvipsnames,table]{xcolor}
  5. \usepackage{float}
  6. \usepackage{tabularx}
  7.  
  8. \begin{document}
  9.  
  10. \begin{table}[H]
  11. \centering
  12. \newcommand{\mystrut}{\rule[-6pt]{0pt}{20pt}}
  13. \begin{tabular}{l|@{}!{\mystrut}>{\centering}m{6em}|!{}>{\centering}m{6em}|!{}>{\centering}m{6em}|l}
  14. \cline{2-4}
  15. \cellcolor[gray]{0.95} % <--- problem here
  16. & \multicolumn{3}{@{}!{\mystrut}c|}{Some funny title}
  17. \\ \cline{2-4}
  18. & Word 1 & Word 2 & Word 3 &
  19. \\ \cline{1-4}
  20. \multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Disk} & 1 & 2 & 3 & \multicolumn{1}{!{\mystrut}>{}m{4em}}{} \\ \cline{1-4}
  21. \multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Sphere} & 1 & 2 & 3 & \\ \cline{1-4}
  22. \multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Cylinder} & 1 & 2 & 3 & \\ \cline{1-4}
  23. \end{tabular}
  24. \caption{Some description.}
  25. \end{table}
  26.  
  27. \end{document}


Preview :
table2.jpg
table2.jpg (23.27 KiB) Viewed 215 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! :oops:

User avatar
Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Fri Jun 15, 2018 8:44 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 :evil:

This code has problems :
  1. \documentclass[11pt,twoside]{book}
  2. \usepackage[total={6.25in,10in},left=1.25in,top=0.5in]{geometry}
  3. \usepackage{graphicx}
  4. \usepackage{tabularx}
  5. \begin{document}
  6.  
  7. \begin{table}
  8. \centering
  9. \newcommand{\mystrut}{\rule[-6pt]{0pt}{20pt}}
  10. \begin{tabular}{l|@{}!{\mystrut}>{\centering}m{6em}|!{}>{\centering}m{6em}|!{}>{\centering}m{6em}|}
  11. \cline{2-4}
  12. & Word 1 & Word 2 & Word 3
  13. \\ \cline{1-4}
  14. \multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Disk} & 1 & 2 & 3
  15. \\ \cline{1-4}
  16. \multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Sphere} & 1 & 2 & 3
  17. \\ \cline{1-4}
  18. \multicolumn{1}{|!{\mystrut}>{}m{4em}|}{Cylinder} & 1 & 2 & 3
  19. \\ \cline{1-4}
  20. \end{tabular}
  21. \caption{Some description.}
  22. \end{table}
  23.  
  24. \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?


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 9 guests