wie kann man Wörter in mehreren Zeilen in eine Zelle einfügen?

wie kann man Wörter in mehreren Zeilen in eine Zelle einfügen?

Die Tabelle ist zu breit und ich möchte sie schmaler machen, indem ich das Secondunter das umschließe First. Wie erreiche ich dies?

Der Latex-Code sieht derzeit folgendermaßen aus:

\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*}%

Bildbeschreibung hier eingeben

Antwort1

Sie können die minimalistischemakecellPaketmit dem die Ausrichtung einer bestimmten Zelle angepasst werden kann:

Bildbeschreibung hier eingeben

\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}

Antwort2

Am einfachsten wäre es, nur zwei Zeilen zu verwenden. Um die einzeilige Überschrift in die Mitte der Zeile zu setzen, können Sie verwenden \multirowvonDas multirowPaket:

Bildbeschreibung hier eingeben

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}

verwandte Informationen