LaTeX forum ⇒ Graphics, Figures & Tableshow to nicely wrap and center text in table cell?

Information and discussion about graphics, figures & tables in LaTeX documents.
crobar
Posts: 12
Joined: Mon Nov 16, 2009 4:41 pm

how to nicely wrap and center text in table cell?

Postby crobar » Wed Jul 07, 2010 1:18 pm

Hello,

Can anyone tell me how to horizontally center the wrapped text in the second header cell of the table in the following example without screwing up the row height or otherwise making it look ugly? I just can't figure it out. In general, is it possible wrap text in one table cell, center it vertically and horizontally in the cell, and also have text in the other cells of the same row vertically centred as well?

  1. \documentclass{article}
  2.  
  3. \usepackage{booktabs}
  4.  
  5. \begin{document}
  6.  
  7. \begin{table}
  8. \begin{tabular}{c c p{6cm}} \toprule
  9. \multicolumn{1}{c}{Name}
  10. & \multicolumn{1}{p{2.3cm}}{Variable Form In Code}
  11. & \multicolumn{1}{c}{Meaning} \\
  12. \midrule
  13. x & \verb|x| & Thickness of the back iron on part 1 \\
  14. x & \verb|x| & Thickness of the magnet on part 1 \\
  15. \bottomrule
  16. \end{tabular}
  17. \end{table}
  18.  
  19. \end{document}


Thanks!

User avatar
Stefan Kottwitz
Site Admin
Posts: 9523
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Wed Jul 07, 2010 1:35 pm

Hi crobar,

you could use m-columns with the array package and \centering in cells, like:
  1. \documentclass{article}
  2.  
  3. \usepackage{array}
  4. \usepackage{booktabs}
  5.  
  6. \begin{document}
  7.  
  8. \begin{table}
  9. \begin{tabular}{c c p{6cm}} \toprule
  10. \multicolumn{1}{m{2cm}}{\centering Name}
  11. & \multicolumn{1}{m{2.3cm}}{\centering Variable Form In Code}
  12. & \multicolumn{1}{m{6cm}}{\centering Meaning} \\
  13. \midrule
  14. x & \verb|x| & Thickness of the back iron on part 1 \\
  15. x & \verb|x| & Thickness of the magnet on part 1 \\
  16. \bottomrule
  17. \end{tabular}
  18. \end{table}
  19.  
  20. \end{document}


Stefan
Site admin

crobar
Posts: 12
Joined: Mon Nov 16, 2009 4:41 pm

Postby crobar » Wed Jul 07, 2010 1:42 pm

Thank you! That's great.


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Stefan Kottwitz and 6 guests