4

Is there a simple and robust way to achieve what is illustrated by the two black arrows below, i.e., shifting the title in a right-aligned column right by a fixed amount.

\documentclass[12pt]{article}\usepackage{array}
\begin{document}

\begin{tabular}{l>{\raggedleft}p{3.5cm}@{}}
Coltitle1 & Coltitle2 \tabularnewline
AB & 5 \tabularnewline
A & 11 \tabularnewline
AC & 10 \tabularnewline
\end{tabular}

\begin{tabular}{l>{\raggedleft}p{3.5cm}@{}}
Coltitle1 & LongColtitle2 \tabularnewline
AB & 5 \tabularnewline
A & 11 \tabularnewline
AC & 10 \tabularnewline
\end{tabular}
\end{document}

I'd like to avoid bad box(es)-warnings. Also, I would prefer (=not absolutely necessary) if the right end of the table would stay where it is, i.e., directly adjacent to the numbers. I.e.,

Coltitl|e2         instead of       Coltitle2|
      5|                                  5  |
     10|                                 10  |
    ...|                                  ...|

where | marks the right end of the table.

1 Answer 1

5

You can say

\makebox[\dimexpr(\width-2em)][l]{LongColTitle2}

However, the table width will not take into account the shift. That may be done with a suitable table preamble such as

\begin{tabular}{l>{\raggedleft}p{3.5cm}@{\hspace{2em}}}
1
  • 1
    @Frank: \dimexpr allows you to subtract 2em from the \width. I normally write it as \dimexpr\width-2em\relax. Mar 26, 2011 at 22:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .