4

I'm trying to create a table that has 2 rows: 25% and 75% of the \textwidth

I also want the left column to be bold and right aligned by default. The second column is also right aligned.

Now I want some cells in the left column to be left aligned, I searched for this and this should be how to do it: \multicolumn{1}{l}{Left}

This is my code with some dummy rows

\noindent
\begin{tabularx}{\textwidth}{|>{\raggedleft\hsize=.5\hsize\bfseries}X|>{\raggedleft\hsize=1.5\hsize}X|}
\hline
\multicolumn{1}{l}{Left} & Right\\
\hline
Right & Right\\
\hline
Right & Right\\
\hline
\end{tabularx}

But I'm having some problems:

  1. It's not correctly 25 and 75 %, the last column ends too quick.
  2. It's not compiling, I get errors about my alignment tabs.
3

You're almost there: Add the command \arraybackslash to the specification of the second X column:

\begin{tabularx}{\textwidth}{|>{\raggedleft\hsize=.5\hsize\bfseries}X|
    >{\raggedleft\arraybackslash\hsize=1.5\hsize}X|}

It doesn't hurt (but it's not essential) to add \arraybackslash to the specification of the first column as well.

Separately, be sure to write

\multicolumn{1}{|l|}{Left}

rather than just \multicolumn{1}{l}{Left} if you want vertical bars to the left and right of that cell.

  • 1
    Thanks! Now that I saw 25 and 75%, I think 35 and 65% should be better. What do I need for hsize then, 0.35 and 1.65? Also, is it possible to automically break text if it leaves the column? – Aaron Dec 12 '13 at 20:38
  • 1
    Choose 0.7 and 1.3: The two \hsize numbers have to add up to the number of columns, which is 2 in the present case. To verify: 0.7/2=0.35=35% and 1.3/2=0.65=65%. :-) Yes, the X column type will wrap text automatically if it's wider than the column it's assigned to. – Mico Dec 12 '13 at 20:43
  • 1
    Indeed, 0.7 and 1.3 works and looks better. The text in the second column goes out of my page though, instead of wrapping. – Aaron Dec 12 '13 at 20:48
  • @Aaron - That's odd. Please double-checke that the second column is defined as >{\raggedleft\arraybackslash\hsize=1.3\hsize}X. Separately, what's the nature of the text you have in the second column: Is it something, e.g., a long URL string, that LaTeX may not want to break up into shorter chunks? – Mico Dec 12 '13 at 20:52
  • 1
    Yup, it was like that. Anyway, I added more text to other rows and some other things, and now its working. Don't know why it didn't work before. Anyway, thanks for your answers! – Aaron Dec 12 '13 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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