Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to create a document showing how two numbers are added, focusing on moving from the ones column on up, but for some reason, my tabular environment's columns are not matching up with my actual input. I've declared three columns, yet my second declaration is adjusting my third column.

\begin{center}
\begin{tabular}{rp{1cm} rp{1cm} rp{1cm} }
2{\color{red}{2}} &  & {\color{red}{2}}2 \\
+1{\color{red}{3}} & $\longrightarrow$ & +{\color{red}{1}}3 \\
\cline{1-1} \cline{3-3}
{\color{red}{5}} & & {\color{red}{3}}5
\end{tabular}
\end{center}

I'm trying to use the right arrow to show how we move from the ones column to the tens, so I figured I'd just assign it its own column. Yet the spacing is a little off, and when I try to turn the second rp{1cm} into c{1cm}, it messes up my third column. What's even weirder is that the \cline command places the line in the right place...

share|improve this question
    
Welcome to TeX.SE. Sorry, am not understanding the exact problem here. But you might want to add @{} before and after some columns to remove the inter column spacing, and perhaps change {\color{red}{2}} to \textcolor{red}{2}. –  Peter Grill Aug 12 '12 at 5:04
2  
Rereading your question it seems that you are specifying 6 columns, not 3. The r specifies a right aligned column, and a p{} specifies a \parbox column that can contain multiple lines. But your table only has 3 columns, so the only specifications that matter are the r p{1cm} r columns. Don't think there is any reason in this case to be using the p{} column type for this specific example. So, when you changed the second rp{1cm} (of which only the r column type was used) into a c column, you changed the third column form right aligned to center aligned. –  Peter Grill Aug 12 '12 at 5:18
add comment

1 Answer

up vote 7 down vote accepted

You have six column specifications, but using three, the first and third are right justified, the column in the middle centered:

\documentclass{article}
\usepackage{color}
\begin{document}
\begin{center}
\begin{tabular}{rcr}
2\textcolor{red}{2} & & \textcolor{red}{2}2 \\
+1\textcolor{red}{3} & $\longrightarrow$ & +\textcolor{red}{1}3 \\
\cline{1-1} \cline{3-3}
\textcolor{red}{5} & & \textcolor{red}{3}5
\end{tabular}
\end{center}
\end{document}

This yields (image added by azetina):

table with coloured columns

The difference {\color{red}{...}} to \textcolor{red}{...} does not matter, I have only used \textcolor because it is easier to read (less braces).

share|improve this answer
    
That solved it perfectly! Thanks so much. I was typing this document from someone else's tex document, and when I saw he had rp{1cm}, I assumed this created a parbox column that was also aligned to the right (if that makes sense...). And I'll definitely switch to \textcolor{red}[{...} haha. Thanks for the help everyone! –  aklingensmith Aug 13 '12 at 1:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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