Text FormattingCentering text vertically in tabular

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
bruno88
Posts: 2
Joined: Sat Mar 20, 2010 3:42 pm

Centering text vertically in tabular

Post by bruno88 »

Hi,

I'm creating my first document in LaTeX and I need to create a table with 1 row and 3 columns, where the first and last column must be centered horizontally and vertically. I was able to center the text horizontally but it never centers vertically. I'm using LaTeX2e don't know if this is important though. My code is:

Code: Select all

\begin{tabular}[c]{|c|p{2.8in}|c|} \hline
CO-004 & As comunidades tê\^{e}m sempre um coordenador de entre os U-I. O membro coordenador de uma comunidade pode mudar ao longo da vida de uma comunidade. As comunidades tê\^{e}m sempre um coordenador de entre os U-I. O membro coordenador de uma comunidade pode mudar ao longo da vida de uma comunidade. & M \\ \hline
\end{tabular}
It returns this:
99499626.png
99499626.png (48.81 KiB) Viewed 3382 times
And I want something like this:
65791678.png
65791678.png (27.45 KiB) Viewed 3382 times
Hope you can help me :)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

php1ic
Posts: 192
Joined: Wed Jan 28, 2009 8:17 pm

Centering text vertically in tabular

Post by php1ic »

Looks like the tabularx package can do what you want. You may have to play with the width of the table to get the central column looking 'nice'.

Code: Select all

\documentclass[12pt]{article}

\usepackage{tabularx}

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

\begin{document}

\begin{tabularx}{0.9\textwidth}{|c|X|c|}
\hline
CO-004 & As comunidades tê\^{e}m sempre um coordenador de entre os U-I. O membro coordenador de uma comunidade pode mudar ao longo da vida de uma comunidade. As comunidades tê\^{e}m sempre um coordenador de entre os U-I. O membro coordenador de uma comunidade pode mudar ao longo da vida de uma comunidade. & M \\
\hline
\end{tabularx}

\end{document}
I used this guide

http://www.vision.ime.usp.br/~jmena/mis ... _latex.pdf
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Centering text vertically in tabular

Post by localghost »

Attachments shall be uploaded to the forum server. External links can get lost with time and make a problem incomprehensible.

Load the array package and modify your code as shown below.

Code: Select all

\documentclass{article}
\usepackage{array}

\begin{document}
\begin{tabular}{|c|m{2.8in}|c|} \hline
CO-004 & As comunidades tê\^{e}m sempre um coordenador de entre os U-I. O membro coordenador de uma comunidade pode mudar ao longo da vida de uma comunidade. As comunidades tê\^{e}m sempre um coordenador de entre os U-I. O membro coordenador de uma comunidade pode mudar ao longo da vida de uma comunidade. & M \\ \hline
\end{tabular}
\end{document}

Best regards and welcome to the board
Thorsten
bruno88
Posts: 2
Joined: Sat Mar 20, 2010 3:42 pm

Re: Centering text vertically in tabular

Post by bruno88 »

Both solutions worked.

Thank you very much :D
Post Reply