Text Formattingproblem with justifying text in table

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
mahmood
Posts: 26
Joined: Sun Oct 31, 2010 11:42 am

problem with justifying text in table

Post by mahmood »

Hi,
I have created a table with this header:

Code: Select all

\begin{tabular}{| c | c | p{6cm} | p{6cm} |}
problem with that is the two last columns are not justified center. I have tried

Code: Select all

\begin{tabular}{| c | c | cp{6cm} | cp{6cm} |}
but it doesn't work. Any solution to that? thank
Last edited by mahmood on Sun Mar 13, 2011 11:20 am, edited 1 time in total.

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

problem with justifying text in table

Post by localghost »

From your last try I assume that you want horizontal alignment of the text. This will require at least the array package to assign a certain alignment to these columns.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{array}

\newcommand*{\filltext}{The quick brown fox jumps over the lazy dog.}

\begin{document}
  \begin{tabular}{|c|c|>{\centering}p{6cm}|>{\centering\arraybackslash}p{6cm}|}\hline
    Head & Head & Head & Head \\\hline
    Values & Values & \filltext & \filltext \\\hline
    Values & Values & \filltext & \filltext \\\hline
  \end{tabular}
\end{document}
For more information refer to the package manual. Hyphenation could be improved by using the ragged2e package. You may also take a look at the quite new tabu package, which seems to be an allrounder regarding tables. It is advisable to drop vertical lines for better legibility of tables.


Thorsten
mahmood
Posts: 26
Joined: Sun Oct 31, 2010 11:42 am

Re: problem with justifying text in table

Post by mahmood »

Thanks for that. It worked however I didn't thought it has a such complex syntax
Post Reply