TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

When I put X in column specifier, how can I define column formatting? How can I get center alignment? Currently I am putting \centering, but that is not a proper solution.

This is my code:

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\usepackage{booktabs,tabularx}
\usepackage[margin=1in]{geometry}% http://ctan.org/pkg/geometry


\begin{document}

\begin{table}[t]
\caption{Case studies}
\centering
 \begin{tabularx}{\textwidth}{p{4cm}*{5}{X}}
    \toprule
\centering Nature of unreliability & \centering Sender SST & \centering Receiver SST & \centering Implementation SST &  Retransmission Bound \\


\midrule

Noisy (Single fixed error message) & DSST & DSST & DSST & Unbounded \\
\bottomrule
\end{tabularx}
\label{case-studies}
\end{table}



\end{document}
share|improve this question

marked as duplicate by Joseph Wright Jul 21 '14 at 6:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
\centering is the proper solution. But if you use it in the last column you should use \tabularnewline to end the row of the tabular. – Ulrike Fischer Feb 7 '13 at 12:27
2  
If you want it to apply to the whole column you can use >{\centering \arraybackslash}X as it suggests in the tabularx manual. – David Carlisle Feb 7 '13 at 12:41
    
Please, clarify if you need to center align only one row or all of them. – egreg Feb 7 '13 at 13:41
    
@DavidCarlisle Please check my answer -- for whatever reason, >{\centering \arraybackslash}X does not suffice. – lockstep Feb 7 '13 at 14:20
up vote 10 down vote accepted

My answer to Fixed width column with text centered/raggedright/raggedleft in tabular? can also be applied in slightly modified form to X columns. (Note that omitting \let\newline\\ will result in text that is not properly centered.)

\documentclass{article}

\usepackage{tabularx}

\usepackage{array}
\newcolumntype{Z}{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}X}

\begin{document}

\begin{tabularx}{\linewidth}{| c | c | Z |}
Abc & Bcd & Cde \\
Abc & Bcd & A long cell with text that is centered \newline
    and allows manual line breaks \\
\end{tabularx}

\end{document}

enter image description here

share|improve this answer
1  
yes \centering only redefines \` not \newline` so if you need manual breaks you can do as here, or don't use \arraybackslash and use \` for centering break and \tabularnewline` for end of table row, or perhaps simplest you can use a blank line to force a new centred parapgraph – David Carlisle Feb 7 '13 at 16:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.