LaTeX forum ⇒ Graphics, Figures & TablesHow to vertically center all elements in a table ? Topic is solved

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

How to vertically center all elements in a table ?

Postby Cham » Sun Nov 05, 2017 11:35 pm

Here's a MWE code reproducing my problem. I need all elements to be centered vertically inside their cell. How to do that ?

  1. \documentclass[11pt,letterpaper,twoside]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{lmodern}
  4. \raggedbottom
  5. \usepackage{microtype}
  6. \usepackage[dvipsnames,table]{xcolor}
  7. \usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
  8. \usepackage{hhline}
  9. \usepackage{tabularx}
  10.  
  11. \begin{document}
  12.  
  13. \begin{center}
  14. \small
  15. \renewcommand{\arraystretch}{1.5}
  16. \begin{tabularx}{\textwidth}{|>{\centering\arraybackslash}m{1cm}|>{\centering\arraybackslash}m{1cm}|>{\centering\arraybackslash}m{2cm}|>{\centering\arraybackslash}m{1.5cm}|>{\centering\arraybackslash}m{1.5cm}|>{\centering\arraybackslash}X|}
  17. \hline
  18. \multicolumn{1}{|c|}{\normalsize\textsf{Day}}
  19. & \multicolumn{1}{c|}{\normalsize\textsf{Month}}
  20. & \multicolumn{1}{c|}{\normalsize\textsf{Hour}}
  21. & \multicolumn{1}{c|}{\normalsize\textsf{Group}}
  22. & \multicolumn{1}{c|}{\normalsize\textsf{Room}}
  23. & \multicolumn{1}{c|}{\normalsize\textsf{Lab title}}
  24. \\ \hhline{======}
  25. 1 & 09 & 9h to 11h & 20114 & L-2630 &
  26. \textbf{Some title} \par (some comment)
  27. \\ \hline
  28. 1 & 09 & 14h to 16h & 20115 & L-2640 &
  29. \textbf{Another title} \par (some comment)
  30. \\ \hline
  31. \end{tabularx}
  32. \end{center}
  33.  
  34. \end{document}


Here's a preview of what this code is doing. I've shown the problem in red :
table.jpg
table.jpg (34.63 KiB) Viewed 116 times

User avatar
Stefan Kottwitz
Site Admin
Posts: 8537
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Mon Nov 06, 2017 3:52 pm

Hi Cham,

quick solution:

\renewcommand{\tabularxcolumn}[1]{m{#1}}

Use it in the preamble to have it for all X cells, or just within the center environment to keep the change local there.

Stefan
Site admin

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

Postby Cham » Mon Nov 06, 2017 5:24 pm

It's working great. Thanks Stefan !


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 4 guests