1

I need some help creating a table with the following properties:

  1. Wide(er) headings
  2. Thin(er) text in columns
  3. Column contents should be right aligned
  4. Column contents should be centred with the column heading

This is an almost working table:

\documentclass{article}
\begin{document}
\begin{tabular}{rr}
\multicolumn{1}{c}{\textbf{Wide header 1}} & \multicolumn{1}{c}{\textbf{Wide header 1}}\\
1 & a\\
222 & bb\\
33 & cccc\\
\end{tabular}
\end{document}

But the desired output is like this: enter image description here

I have seen this (Alignment of numbers in table with wide columns) but refers specifically to aligning numbers and not text).

Simpler solutions will be valued. Thank you.

3
  • 1
    Welcome to TeX SX! An minimal example would be nice to play with,a s there are several solutions: splitting headers into several lines, playing with the intercolumn space, or rotating column heads.
    – Bernard
    Jun 10, 2015 at 22:35
  • Added a small (almost working) example as suggested. Jun 10, 2015 at 23:16
  • I stumbled upon this problem again, and revisited this question and the answers. The solutions below are based on a \hspace{...} that needs to be "hand customized" for the width of the header text. It puzzles me both that this type of alignment is not required by more people! Do any of the "tabular-in-steroids" packages may help producing a fully-automated solution? Jul 7, 2020 at 23:19

2 Answers 2

4

enter image description here

\documentclass{article}
\begin{document}
\begin{tabular}{
r@{\hspace{3.5em}}
r@{\hspace{3.5em}}
}
\multicolumn{1}{c}{\textbf{Wide header 1}}&
\multicolumn{1}{c}{\textbf{Wide header 1}}\\
1 & a\\
222 & bb\\
33 & cccc\\
\end{tabular}
\end{document}
3

Here is a solution with tabulary, mathtools for its \clap command, playing with tabcolsep:

\documentclass{article}
\usepackage[sfdefault]{cabin} 

\usepackage{tabulary, booktabs}
\usepackage{mathtools}

\begin{document}

{\setlength\tabcolsep{3.5em}
\begin{tabulary}{\linewidth}{RR}
  \toprule
  \multicolumn{1}{c}{\clap{\textbf{Wide header 1}}} & \multicolumn{1}{c}{\clap{\textbf{Wide header 2}}}\\
  \cmidrule(lr){1-1}\cmidrule(lr){2-2}
  1 & a\\
  222 & bb\\
  33 & cccc\\
  \bottomrule
\end{tabulary}}
\end{document} 

enter image description here

You must log in to answer this question.

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