[texhax] Q: centering with known width

Martin Heller mr_heller at yahoo.dk
Mon Mar 12 15:30:48 CET 2007


Uwe Lück skrev:
> At 17:37 08.03.07, D. R. Evans wrote:

>> \begin{tabular}{| c | p{0.15\textwidth} |}

>> How do I get the second label (and all the other entries in that
>> column) to be centered?
> 
> At 18:04 08.03.07, Martin Heller wrote:
> 
>> Load the array package and define a new column type.
> 
> I am strongly biased towards trying very hard to avoid
> loading another package. In particular, I have done so
> with tables in recent months. Thought many days,
> learnt a lot, and it still works, without the array package.
> So concerning the posting:
> 
> "p" is not the only way to get a fixed column width
> with "simple" LaTeX (loading packages as pasimoniously
> as possible). Another way is (e.g.):
> 
>    \begin{tabular}{| c | c |}
>    \hline
>    Name & \makebox[.15\textwidth]{\hfill Downstream per-device limit 
> (Mbps)\hfill} \\
>    \hline
>    etc.
> 
> It suffices to use that \makebox in one single row of the table.

This does not work as intended. You can use a \parbox, but I 
don't understand why you want to avoid loading packages?

\documentclass{article}

\begin{document}

% Not working
\begin{tabular}{| c | c |}
    \hline
    Name & \makebox[.15\textwidth]{%
             \hfill
             Downstream per-device limit (Mbps)\hfill}\\
    \hline
\end{tabular}

% Working
\begin{tabular}{| c | c |}
    \hline
    Name & \parbox{.15\textwidth}{%
             \centering
             Downstream per-device limit (Mbps)}\\
    \hline
\end{tabular}

\end{document}



More information about the texhax mailing list