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 align a specific content of a single cell. For example,

\begin{tabular}{|r|r|}
   \hline
   1 & 2
   \hline
   right & to_the_left
   \hline
   1 & 2
   \hline
\end{tabular}

Is it possible to_the_left to be aligned to the left, but to leave all others on the right? Is it even possible to align (cell contents) inside an already defined tabular environment?

share|improve this question
    
Instead of posting code snippets, it is always best to compose a MWE that includes \documentclass and any packages, so that those trying to help don't have to recreate it. –  Peter Grill Nov 2 '11 at 19:59
    
Good advice. Thank you. –  aksr Nov 2 '11 at 20:41

2 Answers 2

up vote 23 down vote accepted

You can use \multicolumn{1}{l}{<content>} for to_the_left to switch the cell alignment just for this cell. If you want to have a vertical line you need to use l| instead, otherwise the line is missing for this cell.

\documentclass{article}
\begin{document}
\begin{tabular}{|r|r|}
   \hline
   111111 & 222222 \\
   \hline
   right & \multicolumn{1}{l|}{left} \\
   \hline
   1 & 2 \\
   \hline
\end{tabular}
\end{document}

Result

share|improve this answer
2  
Yes, I already tried this solution, but it's a bit hack-ish, though. Is there more 'elegant' solution? If not, it would be nice to have better solution in upcoming LaTeX. –  aksr Nov 2 '11 at 20:46
    
LaTeX3 won't be around for another while and I don't think it will handle that any better. Tables use TeX primitives to format the cells and you need some form of interface to control that. I don't think there is a simpler way than \multicolumn. You could define yourself a shorter macro for this, but that's all. –  Martin Scharrer Nov 2 '11 at 20:49
    
Is there a variant of this solution that does not depend on whether the cell is adjacent to a vertical line or not? –  Joachim Breitner Mar 15 at 15:56

There is a "solution" that avoids \multicolumn{1}{l}{...} but it's really a hack:

right & left\hfill\vadjust{} \\

The \hfill alone won't do, because LaTeX works hard to remove all space from the end part of a cell. Instead of \vadjust{} also \penalty0 or \nobreak can be used.

A \multicolumn{1}{l}{...} is, probably, more visible and easier to change in case it's not needed any more.

share|improve this answer

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.