
Ich versuche, eine große Tabelle zu erstellen, in der jedes der Felder mehrere Textzeilen untereinander enthält. Ich habe versucht, \newline
eine \linebreak
neue Zeile zu erstellen, aber beides funktioniert nicht. Der Befehl \\
erzeugt zwar eine neue Zeile, beendet aber die gesamte Zeile in der gesamten Tabelle.
Kann mir jemand einen Tipp geben, wie ich an eine neue Leitung oder vielleicht ein besseres Paket komme?
Antwort1
Verwendung parbox{}{}
wie in:
\documentclass{standalone}
\begin{document}
\begin{tabular}{ll}
\hline
row 1, column 1, line 1 & \parbox{5cm}{row 1, column 2, line 1 \\ row 1, column 2, line 2 \\ row 1, column 2, line 3} \\ \hline
\parbox{5cm}{row 2, column 1, line 1 \\ row 2, column 1, line 2} & row 2, column 2, line 1 \\
\hline
\end{tabular}
\end{document}
Antwort2
Es gibt mehrere mögliche Lösungen. Im Folgenden werden zwei Ansätze gezeigt. Der erste basiert nur auf Standardbefehlen. Obwohl ich booktabs
aus ästhetischen Gründen verwendet habe, ist dies für die Lösung nicht unbedingt erforderlich. Der zweite verwendet tabularx
.
\documentclass{article}
\usepackage{tabularx,booktabs}
\begin{document}
One method involves using the standard \verb|p{<width>}| column specifier. This requires knowing how wide you want the columns but it allows you to use \verb|\newline| and does not require additional packages. Table \ref{tab:standard} does use commands from \verb|booktabs| to improve the tabular's appearance but you could replace with \verb|\hline| etc.\ if preferred.
\begin{table}
\centering
\begin{tabular}{*{2}{p{.285\linewidth}}}
\toprule
row 1, column 1, line 1 & row 1, column 2, line 1\newline row 1, column 2, line 2\newline row 1, column 2, line 3\\\midrule
row 2, column 1, line 1\newline row 2, column 1, line 2 & row 2, column 2, line 1 \\
\bottomrule
\end{tabular}
\caption{Tabular with standard commands}\label{tab:standard}
\end{table}
\bigskip
If you don't know how wide the columns should be and don't wish to figure it out, but you can specify the overall width of the tabular, \verb|tabularx| can be used. This supports the \verb|X| column specifier which figures out the width based on the overall tabular width. It also allows \verb|\newline|. Table \ref{tab:tabularx} again uses \verb|booktabs| but that is for merely aesthetic reasons.
\begin{table}
\centering
\begin{tabularx}{.65\linewidth}{XX}
\toprule
row 1, column 1, line 1 & row 1, column 2, line 1\newline row 1, column 2, line 2\newline row 1, column 2, line 3\\\midrule
row 2, column 1, line 1\newline row 2, column 1, line 2 & row 2, column 2, line 1 \\
\bottomrule
\end{tabularx}
\caption{Tabular with tabularx}\label{tab:tabularx}
\end{table}
\end{document}
Antwort3
Das Paket wurde in den vorherigen Links nicht erwähnt und makecell
definiert die Befehle \makecell
, thead
, diaghead
und \multirowcell
, die die Verwendung von akzeptieren \\
und weiter angepasst werden können (Auswahl der Schriftart, Drehung, vertikale Abstände usw.). Man kann die Dicke der h- und c-Linien ändern.
Sehendieser Threadum ein Beispiel seiner Anwendung zu haben.