4

I'm trying to figure out how I can center the columns below a multicolumn statement with a very long text because my current result does not look fine.

I didn't find anything related but it is also very hard to describe by a term so maybe I just did not have the right term.

\documentclass[a4paper, 12pt]{article}
\usepackage[table]{xcolor}
\usepackage{longtable}
\usepackage{booktabs}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}

\ra{1.3}
\begin{document}
\begin{longtable}{>{\kern-\tabcolsep}lll<{\kern-\tabcolsep}}
\toprule
\multicolumn{3}{l}{Long Text  .....}\\
\cmidrule{1-3}
A & B & C \\
\midrule
\endhead
A & B & C \\
A & B & C \\
\end{longtable}
\end{document}

Result

  • How exactly do you want it to look? – cfr Sep 13 '15 at 2:16
  • The A, B and C should be centered below the long text and not somehow left aligned as there – flp Sep 13 '15 at 2:19
  • The negative \kern is shifting the columns left. If you want that, then I don't see how they can be centred. – cfr Sep 13 '15 at 2:20
  • Actually, I also had the problem before with the @{} instead of the kerns – flp Sep 13 '15 at 2:21
3

Something like this? Note that the kerns won't make any difference here, because they are not implemented for the longest row which obviously determines the total width.

Centred

\documentclass[a4paper, 12pt]{article}
\usepackage{longtable,array,calc}
\usepackage{booktabs}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\ra{1.3}
\begin{document}
  \newcolumntype{C}{>{\centering\arraybackslash}p{\shorttextlength}}
\newlength\longtextlength
\newlength\shorttextlength
\settowidth\longtextlength{Long Text \dots.}
\addtolength\longtextlength{-4\tabcolsep}
\setlength\shorttextlength{\longtextlength/3}
\begin{longtable}{CCC}
  \toprule
  \multicolumn{3}{l}{Long Text \dots.}\\
  \cmidrule{1-3}
  A & B & C \\
  \midrule
  \endhead
  A & B & C \\
  A & B & C \\
\end{longtable}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.