Graphics, Figures & Tablestabularx | Specify Width of two right aligned Columns

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
MrJingles
Posts: 1
Joined: Tue Aug 09, 2011 8:31 pm

tabularx | Specify Width of two right aligned Columns

Post by MrJingles »

Hi everyone

I'm pretty new to the tabularx package and I haven't been able to find the needed information in its documentation:
My goal is, to create a table with two columns, each of which has a width of 3cm and the contained text must be right aligned:

Code: Select all

\documentclass[a4paper, oneside, final]{scrartcl}
\usepackage{tabularx}
\begin{document}
\section{start}
\begin{tabularx}{6cm}{|>{\raggedleft}p{3cm}>{\raggedleft}p{3cm}|}
bla1 & bla2 \\
bla3 & bla4 \\
\end{tabularx}
\end{document}
it's giving my errors like
Extra alignment tab has been changed to \cr.
Would be great if someone could tell me where I went wrong.
Thanks a lot
Cheers
Mischa

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

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

tabularx | Specify Width of two right aligned Columns

Post by localghost »

You have to restore the function of \\ with the \arraybackslash command for the last column.

Code: Select all

\documentclass[paper=a4]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{array,tabularx}

\begin{document}
  \begin{tabularx}{6cm}{|>{\raggedleft}p{3cm}>{\raggedleft\arraybackslash}p{3cm}|}
    bla1 & bla2 \\
    bla3 & bla4 \\
  \end{tabularx}
\end{document}
See Section 7 of the array manual. This package is loaded subsequently by the tabularx package.

And by the way, note the warning in the log file. Your table width is a bit to small. You have to take the separating space between the columns into account.


Best regards and welcome to the board
Thorsten
Post Reply