5

I have a longtable setup where to save space, I have to make a column title multi-line and its contents centered while being applied with custom width.

Out of the three I have only successfully applied a custom width because adding \\ or inserting another table inside the column header did not achieve multi-line and c{Xcm} is not permitted for centering a column's contents.

% centering column values
\begin{longtable}{c l l ... }
    % tried to use but does not work
    ... { c{1cm} l l ... }

% long title needs to multi-line, both do not work
\multicolumn{1}{|p{3cm}|}{\textbf{Long Title\\Long Title}} 

\multicolumn{1}{|p{3cm}|}{
    \begin{table}
        \textbf{Long Title}\\
        \textbf{Long Title}
    \end{table}
} 

The situation above is demonstrated in the table on the left but what I want is the one on the right - multi-lined title, centered and compact values of rows.

go-buy-applause-yasss-greninja-goodra-xerneas

I have the sample document in WriteLaTeX.

1 Answer 1

7

You can load array package and define a new column:

\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

and use it like C{2cm}. Adjust the dimensions 2cm as you wish.

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{longtable}

\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\title{Your Paper}
\author{You}

\begin{document}
\begin{center}
\begin{longtable}{|C{2cm}|l|l|}
\caption[Feasible triples for a highly variable Grid]{Feasible triples for
highly variable Grid, MLMMH.} \label{grid_mlmmh} \\

\hline
\textbf{Long Time Title} &
\multicolumn{1}{c|}{\textbf{Triple chosen}} &
\multicolumn{1}{c|}{\textbf{Other feasible triples}} \\ \hline
\endfirsthead

\multicolumn{3}{c}%
{{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
\hline
\textbf{Long Time Title} &
\multicolumn{1}{c|}{\textbf{Triple chosen}} &
\multicolumn{1}{c|}{\textbf{Other feasible triples}} \\ \hline
\endhead

\hline \multicolumn{3}{|r|}{{Continued on next page}} \\ \hline
\endfoot

\hline \hline
\endlastfoot

Your data & again and again \\
\end{longtable}
\end{center}

\end{document}

enter image description here

If you want vertical alignment, use

\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}

Note m{#1} instead of p{#1}.

This will give

enter image description here

Further, if bottom alignment is need, use b{#1}:

enter image description here

2
  • Thank you! How do I vertically center "Triple chosen" as seen in the picture though? Oct 13, 2013 at 13:31
  • @thekalaban See the update. Is it like that?
    – user11232
    Oct 13, 2013 at 13:36

You must log in to answer this question.

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