
Estou tentando fazer uma tabela grande onde cada uma das caixas tenha várias linhas de texto uma embaixo da outra. Eu tentei \newline
entrar \linebreak
em uma nova linha, mas nenhum dos dois funcionou. O comando \\
fornece uma nova linha, mas encerra a linha inteira na tabela inteira.
Alguém pode sugerir como posso conseguir uma nova linha ou talvez um pacote melhor para usar?
Responder1
Use parbox{}{}
como em:
\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}
Responder2
Existem várias soluções possíveis. O seguinte demonstra 2 abordagens. O primeiro depende apenas de comandos padrão. Embora eu tenha usado booktabs
por questões estéticas, isso não é essencial para a solução. O segundo usa 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}
Responder3
Não mencionado nos links anteriores, o makecell
pacote define \makecell
, thead
e comandos que aceitam o uso e podem ser ainda mais customizados (escolha de fonte, rotação, espaços diaghead
verticais , etc.). Pode-se alterar as linhas e a espessura das linhas.\multirowcell
\\
Vereste tópicopara ter um exemplo de seu uso.