2
 \begin{tabularx}{.96\textwidth}{@{\extracolsep{\fill}}|c|c|c| }
 \hline
   \textbf{Xxx1} & 
   \textbf{Xxx2} & 
   \textbf{Xxx3} \\ 
 \hline
   & & \\
 \hline
 \end{tabularx}

Why Xxx1 is centered (correctly) and Xxx2 and Xxx3 are right aligned (incorrectly)?

5
  • 3
    it is hard to know what you have as you have not made your example complete, so we can not run it, but the table is in error, a tabularx should always have an X column, or use tabular instead. Commented Jun 27, 2015 at 20:43
  • it is best not to use | and \extracolsep in the same table as the extra space always goes to the right of the rule. Commented Jun 27, 2015 at 20:51
  • Well, may be I'm going in the wrong way. I just want the table to use all the width. Is there a better approach?
    – oqrxke
    Commented Jun 27, 2015 at 21:16
  • using the full width should be a non-aim, but if you want to do it with ccc use the standard tabular* rather than tabularx and generally the advice is to avoid vertical rules. Commented Jun 27, 2015 at 21:21
  • see this for methods on making the table wide tex.stackexchange.com/questions/245770/… Commented Jun 27, 2015 at 21:30

1 Answer 1

3

enter image description here

\documentclass{article}

\usepackage{tabularx}

\begin{document}
\centering

space is added after the rules;

 \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}|c|c|c|@{}}
 \hline
   \textbf{Xxx1} & 
   \textbf{Xxx2} & 
   \textbf{Xxx3} \\ 
 \hline
   & & \\
 \hline
 \end{tabular*}

\bigskip
without rules:

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ccc@{}}
 \hline
   \textbf{Xxx1} & 
   \textbf{Xxx2} & 
   \textbf{Xxx3} \\ 
 \hline
   & & \\
 \hline
 \end{tabular*}

\bigskip
not stretched (much more readable)

\begin{tabular}{ccc}
 \hline
   \textbf{Xxx1} & 
   \textbf{Xxx2} & 
   \textbf{Xxx3} \\ 
 \hline
   & & \\
 \hline
 \end{tabular}

\bigskip tabularx

\begin{tabularx}{\textwidth}{@{\extracolsep{\fill}}
|*3{>{\centering\arraybackslash}X|}@{}}
 \hline
   \textbf{Xxx1} & 
   \textbf{Xxx2} & 
   \textbf{Xxx3} \\ 
 \hline
   & & \\
 \hline
 \end{tabularx}

\end{document}
4
  • Is it possible to auto adjust column width in respect to the text size (i.e. Xxx3 should be smaller then Xxxxxxxxxxxx4)?
    – oqrxke
    Commented Jun 29, 2015 at 20:20
  • @oqrxke yes that is what latex does, (for all versions except tabularx) . A c column is set according to content, p or X columns fix a width then the content is wrapped to that length. Commented Jun 29, 2015 at 20:21
  • @DavidCarlisle, I just wonder if there is anyway in LaTeX to do the last table BUT without the first and the last vertical lines!
    – doctorate
    Commented Feb 2, 2016 at 12:39
  • 1
    @doctorate yes of course just take them out of the preamble so *2{>{\centering\arraybackslash}X|}>{\centering\arraybackslash}X Commented Feb 2, 2016 at 12:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .