15 Comments

  1. Dirk

    \newcolumntype{x}[1]{%
    >{\raggedleft\hspace{0pt}}p{#1}%

    leaves me with error message:

    Paragraph ended before (backslash)newcol@ was complete

    Any ideas?

  2. stefan08

    Hi Tom,

    \\ would work like \tabularnewline again if you insert the command \arraybackslash, for instance:

    \newcolumntype{x}[1]{%
    >{\raggedleft\arraybackslash}p{#1}}%

    It’s defined in array.sty: \def\arraybackslash{\let\\\tabularnewline}

    Stefan

  3. nguyenminhhaivn

    I have a problem with tables in LaTeX. I want the text in the first row to be centered and the text in the second row to be flushed left. Hope you can help me. Thanks in advance.

  4. Hi,

    You can control the alignment within a cell using “\multicolumn”. Let me give you a simple example:

    \begin{table}[ht]
    \centering
    \begin{tabular}{lrr}
    & \multicolumn{1}{c}{Exp. 1}
    & \multicolumn{1}{c}{Exp. 2}\\
    Setting A& 5.43498289 & 4.309872395\\
    Setting B& 5.7098429109890 & 4.10983901\\
    \end{tabular}
    \end{table}%

    If you need separation lines, you have to use \vline and \hline between cells.

    Tom.

  5. Norm

    Thanks for this post; I’ve been trying to figure this out for a while and you’re the only person who has had an answer so far.

  6. Al

    Thanks a lot! It really helped me. But can you explain what should I do, if I want to center my text not only horizontally but vertically?

    • Thanks for this question. That’s an easy one :-). Use ‘m’ instead of ‘p’ to vertically align your text within a cell. Hence your column type definition would look like this:

      \newcolumntype{x}[1]{%
      >{\raggedleft\hspace{0pt}}m{#1}}%

      Cheers,
      Tom.

Leave a Reply