1

my table right now looks like this:
enter image description here

I want to center-align the text in the first two columns like how it is done with the other columns (sorry for the quick and dirty photoshop job):

enter image description here

I noticed that when I add vertical divider after the first and second column that the second column is much wider than the first column. To me that seems weird because the text in the columns is the same and also the Alignment.

My LaTex:

\documentclass{article}
\usepackage{booktabs}
\usepackage{makecell}

\begin{document}
\begin{table}
\renewcommand{\arraystretch}{1.2}
\centering
\begin{tabular}{@{}ccccccc@{}}
\toprule
 \multicolumn{2}{r}{Long Word} & \phantom{a} & \multicolumn{4}{c}{Another Word} \\\cmidrule{1-2}\cmidrule{4-7}
\makecell[c]{\\a} & \makecell[c]{\\a} & & \makecell[c]{word\\a} & \makecell[c]{word\\a} & \makecell[c]{word\\a}  & \makecell[c]{word\\ a} \\
\midrule
a & a & & a & a & a & a \\
a & a & & a & a & a & a \\
a & a & & a & a & a & a \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

Why aren't the two cells under "Long Word" together as wide as the "Long Word" cell? How can I achieve this?

Thanks for help!

DropArt
  • 11
  • 3

2 Answers2

1
\documentclass[french]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{makecell, array, booktabs, arydshln}
\usepackage[a4paper]{geometry}
\usepackage[english]{babel}
\begin{document}

\begin{table}
\renewcommand{\arraystretch}{1.2}
\centering
\begin{tabular}{@{}ccccccc@{}}
\toprule
 \multicolumn{2}{c}{Long Word} & {\phantom{a}} & \multicolumn{4}{c}{Another Word} \\\cmidrule{1-2}\cmidrule{4-7}
\makecell[c]{\phantom{word}\\a} & \makecell[c]{\phantom{word}\\a} & & \makecell[c]{word\\a} & \makecell[c]{word\\a} & \makecell[c]{word\\a}  & \makecell[c]{word\\ a} \\
\midrule
a & a & & a & a & a & a \\\hdashline
a & a & & a & a & a & a \\\hdashline
a & a & & a & a & a & a \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

sergiokapone
  • 5,578
  • 1
  • 16
  • 39
  • +1, but you should probably explain that the column's width was not sufficient and that you adjusted it. – TeXnician Jan 28 '18 at 18:57
  • It works, but only if the length of \phantom{word} and \phantom{word} is as long or longer than "Long Word". I think there is a better/cleaner solution to this. This seems more like a hack. – DropArt Jan 28 '18 at 19:06
  • @DropArt if you use \begin{tabular}{ccccccc} the result result will look better – sergiokapone Jan 28 '18 at 19:08
  • @sergiokapone Yeah it may look better in your opinion but that doesn't change that the two cells under "Long Word" together aren't as wide as the "Long Word" cell and the text in the cells isn't centered. – DropArt Jan 28 '18 at 19:12
0

I propose some improvements and simplifications. First I use only 6 columns, increasing the horizontal spacing between columns 2 and 3 and playing with the l and r keys of \cmidrule. Also, you don't need tu use the [c] option of \makecell, as it is the default (both vertically and horizontally). Last, I removed the modification of ``\arraystretch, since the rules frombooktabshave some vertical paddind, and I think replacing the dashed lines ofarydshlnwith\addlinespace` loks nicer.

\documentclass{article}

\usepackage{array, booktabs, makecell}
\usepackage{calc} 

\begin{document}

 \begin{table}
\centering
 %\newlength\LWwidth
\settowidth{\LWwidth}{LongWord}
\begin{tabular}{@{}rc!{\hspace*{1pc}}*{4}{c}@{}}
\toprule
 \multicolumn{2}{l}{ Long Word } & \multicolumn{4}{c}{Another Word} \\\cmidrule(r{0.9pc}){1-2}\cmidrule(l{0.5pc}){3-6}
\makecell[r]{\hspace*{0.5\LWwidth}\\a} & \makecell {\hspace*{0.5\LWwidth}\\a} & \makecell {word\\a} & \makecell {word\\a} & \makecell {word\\a} & \makecell {word\\ a} \\
\midrule
a & a & a & a & a & a \\
\addlinespace
a & a & a & a & a & a \\
\addlinespace
a & a & a & a & a & a \\
\bottomrule
\end{tabular}
\end{table}

\end{document} 

enter image description here

Bernard
  • 271,350