3

The table is too wide, and I want to make it narrower by wrapping the Second under the First, how should I achieve this?

The latex code looks like this currently:

\begin{table*}[htbp]


 \centering
  \caption{Add caption}
    \begin{tabular}{c|ccccc}
    \hline
    \textbf{\#} & \textbf{Violations} & \textbf{First Second} & \textbf{First Second} & \textbf{First Second} & \textbf{First Second} \bigstrut\\
    \hline
    1   & 0   & 91  & 101 & 507 & 1973.54 \bigstrut[t]\\
    2   & 0   & 102 & 92  & 472 & 1874.65 \\
    3   & 0   & 104 & 92  & 459 & 1856.21 \\
    4   & 0   & 108 & 100 & 407 & 1790.56 \\
    5   & 0   & 112 & 77  & 511 & 1723.66 \\
    $\ldots$   & $\ldots$  & $\ldots$  & $\ldots$   & $\ldots$   & $\ldots$ \\
    \hline
    \end{tabular}%
  \label{tab:addlabel}%
\end{table*}%

enter image description here

2

2 Answers 2

2

You can use the minimalistic makecell package that could adjust the alignment of a specific cell:

enter image description here

\documentclass{article}
\usepackage{makecell}% http://ctan.org/pkg/makecell
\begin{document}
\begin{table}[ht]
  \centering
  \caption{Add caption}
  \begin{tabular}{c|ccccc}
    \hline
    \textbf{\#} & \textbf{Violations} & 
      \bfseries\makecell[c]{First \\ Second} & 
      \bfseries\makecell[c]{First \\ Second} & 
      \bfseries\makecell[c]{First \\ Second} & 
      \bfseries\makecell[c]{First \\ Second} \\
    \hline
    5   & 0   & 112 & 77  & 511 & 1723.66 \\
    $\ldots$   & $\ldots$  & $\ldots$  & $\ldots$   & $\ldots$   & $\ldots$ \\
    \hline
  \end{tabular}%
\end{table}%
\end{document}
1
  • 1
    You could make the code even shorter using the \theadcommand and declaring \renewcommand{\theadfont}{\bfseries} in the preamble.
    – Bernard
    Commented Mar 13, 2014 at 16:29
3

Simplest way would be to just use two lines. To place the single line heading in the center of the row you can use \multirow from the multirow package:

enter image description here

Code:

\documentclass{article}
\usepackage{multirow}

\begin{document}
\begin{table*}[htbp]
 \centering
  \caption{Add caption}
    \begin{tabular}{c|ccccc}
    \hline
    \multirow{2}{*}{\textbf{\#}} & \multirow{2}{*}{\textbf{Violations}} & \textbf{First} & \textbf{First} & \textbf{First } & \textbf{First } \\
                &  & \textbf{Second} & \textbf{Second} & \textbf{Second} & \textbf{Second} \\
    \hline
    5   & 0   & 112 & 77  & 511 & 1723.66 \\
    $\ldots$   & $\ldots$  & $\ldots$  & $\ldots$   & $\ldots$   & $\ldots$ \\
    \hline
    \end{tabular}%
  \label{tab:addlabel}%
\end{table*}%
\end{document}
2
  • But I need the violations to be placed at the centre of the row, is it possible?
    – sweetyBaby
    Commented Mar 13, 2014 at 3:52
  • @sweetyBaby: Have updated solution to do that. Commented Mar 13, 2014 at 3:57

You must log in to answer this question.

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