Graphics, Figures & TablesLong text inside TABLE

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
kettu_lissa
Posts: 5
Joined: Mon Jun 19, 2023 12:00 am

Long text inside TABLE

Post by kettu_lissa »

Hi! I've been dealing with this table for weeks... It's really pissing me off, but I need to do it wanting or not, for a project.
The last column of my table has long text. I already tried many things and packages recommended by different sources from google (even chatGPT :? ). The less bad solution so far is that one in which I use a \makecell{} to be able to use newlines inside the columns. The "ideal" solution would be to make columns shrink text automatically... But I couldn't find such a thing, even trying different things.

The problem is that even though it seems there's no problem (in my eyes), it bugs when I try to add a new line. I don't know what to do. :(

Code: Select all

\documentclass{article}
\usepackage{array}
\usepackage{tabularx}
\usepackage{adjustbox}

\begin{document}

\begin{adjustbox}{width=\textwidth}
\begin{tabularx}{\linewidth}{@{}c|c|c|c|X}
\hline
Atributo & Nome & Definição & Obrigatório? & Instruções \\
\hline
\makecell[l]{Tipo de \\documento} & dc.type & \makecell[l]{Tipologia do \\documento \\depositado.} & \makecell[l]{Obrigatório} & 
    \makecell[l]{Segue padrão de preenchimento:\\
    \textbf{article} para Artigo \\de periódico\\ 
    \textbf{conferenceObject} para \\Artigo de evento\\ 
    \textbf{masterThesis}para Dissertação\\ 
    \textbf{doctoralThesis} para Tese\\ 
    \textbf{bachelorThesis} para \\Trabalho de conclusão de curso,\\ 
    \textbf{book} para Livro\\ 
    \textbf{bookPart} para Capítulo de livro,\\ 
    \textbf{report} para Relatório científico\\ 
    \textbf{other} para Outros tipos de \\documentos}
\hline

\end{tabularx}
\end{adjustbox}

\end{document}

The error I get this time is "Misplaced \noalign".
Can someone please help me?
Attachments
Screenshot from 2023-07-01 19-23-42.png
Screenshot from 2023-07-01 19-23-42.png (74.02 KiB) Viewed 4314 times
Screenshot from 2023-07-01 19-23-48.png
Screenshot from 2023-07-01 19-23-48.png (62.82 KiB) Viewed 4314 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Long text inside TABLE

Post by Bartman »

Please pay attention to publish a complete Infominimal working example.

You have to start a new table row before the horizontal line is drawn at the end of the table.

Code: Select all

\documentclass{article}
\usepackage[spanish]{babel}
\usepackage{tabularx}% loads array
\usepackage{makecell}% needed to use the \makecell command
\usepackage{showframe}

\begin{document}
\begin{center}
\footnotesize% read about font sizes on latex2e.org
\renewcommand{\cellalign}{cl}% provided by makecell package
\begin{tabularx}{\linewidth}{
  @{} 
  *4{c|}% equivalent to c|c|c|c|
  X
}
\hline
Atributo & Nome & Definição & Obrigatório? & Instruções \\
\hline
\makecell{Tipo de \\documento} & dc.type & 
\makecell{Tipologia do \\documento \\depositado.} & \makecell{Obrigatório} & 
    \makecell{Segue padrão de preenchimento:\\
    \textbf{article} para Artigo \\de periódico\\ 
    \textbf{conferenceObject} para \\Artigo de evento\\ 
    \textbf{masterThesis} para Dissertação\\ 
    \textbf{doctoralThesis} para Tese\\ 
    \textbf{bachelorThesis} para \\Trabalho de conclusão de curso,\\ 
    \textbf{book} para Livro\\ 
    \textbf{bookPart} para Capítulo de livro,\\ 
    \textbf{report} para Relatório científico\\ 
    \textbf{other} para Outros tipos de \\documentos}\\% added
\hline
\end{tabularx}
\end{center}

% An approach without using the \makecell command in the last column.

\begin{center}
\footnotesize
\renewcommand{\cellalign}{cl}
\renewcommand{\tabularxcolumn}[1]{m{#1}}% read tabularx manual for explanation
\begin{tabularx}{\linewidth}{@{} *4{c|} X}
\hline
Atributo & Nome & Definição & Obrigatório? & Instruções \\
\hline
\makecell{Tipo de \\documento} & dc.type & 
\makecell{Tipologia do \\documento \\depositado.} & \makecell{Obrigatório} & 
    Segue padrão de preenchimento:\par
    \textbf{article} para Artigo \par de periódico\par
    \textbf{conferenceObject} para \par Artigo de evento\par
    \textbf{masterThesis} para Dissertação\par
    \textbf{doctoralThesis} para Tese\par
    \textbf{bachelorThesis} para \par Trabalho de conclusão de curso,\par 
    \textbf{book} para Livro\par
    \textbf{bookPart} para Capítulo de livro,\par
    \textbf{report} para Relatório científico\par
    \textbf{other} para Outros tipos de \par documentos\\
\hline
\end{tabularx}
\end{center}
\end{document}
kettu_lissa
Posts: 5
Joined: Mon Jun 19, 2023 12:00 am

Long text inside TABLE

Post by kettu_lissa »

Bartman wrote:Please pay attention to publish a complete Infominimal working example.

You have to start a new table row before the horizontal line is drawn at the end of the table.

Code: Select all

\documentclass{article}
\usepackage[spanish]{babel}
\usepackage{tabularx}% loads array
\usepackage{makecell}% needed to use the \makecell command
\usepackage{showframe}

\begin{document}
\begin{center}
\footnotesize% read about font sizes on latex2e.org
\renewcommand{\cellalign}{cl}% provided by makecell package
\begin{tabularx}{\linewidth}{
  @{} 
  *4{c|}% equivalent to c|c|c|c|
  X
}
\hline
Atributo & Nome & Definição & Obrigatório? & Instruções \\
\hline
\makecell{Tipo de \\documento} & dc.type & 
\makecell{Tipologia do \\documento \\depositado.} & \makecell{Obrigatório} & 
    \makecell{Segue padrão de preenchimento:\\
    \textbf{article} para Artigo \\de periódico\\ 
    \textbf{conferenceObject} para \\Artigo de evento\\ 
    \textbf{masterThesis} para Dissertação\\ 
    \textbf{doctoralThesis} para Tese\\ 
    \textbf{bachelorThesis} para \\Trabalho de conclusão de curso,\\ 
    \textbf{book} para Livro\\ 
    \textbf{bookPart} para Capítulo de livro,\\ 
    \textbf{report} para Relatório científico\\ 
    \textbf{other} para Outros tipos de \\documentos}\\% added
\hline
\end{tabularx}
\end{center}

% An approach without using the \makecell command in the last column.

\begin{center}
\footnotesize
\renewcommand{\cellalign}{cl}
\renewcommand{\tabularxcolumn}[1]{m{#1}}% read tabularx manual for explanation
\begin{tabularx}{\linewidth}{@{} *4{c|} X}
\hline
Atributo & Nome & Definição & Obrigatório? & Instruções \\
\hline
\makecell{Tipo de \\documento} & dc.type & 
\makecell{Tipologia do \\documento \\depositado.} & \makecell{Obrigatório} & 
    Segue padrão de preenchimento:\par
    \textbf{article} para Artigo \par de periódico\par
    \textbf{conferenceObject} para \par Artigo de evento\par
    \textbf{masterThesis} para Dissertação\par
    \textbf{doctoralThesis} para Tese\par
    \textbf{bachelorThesis} para \par Trabalho de conclusão de curso,\par 
    \textbf{book} para Livro\par
    \textbf{bookPart} para Capítulo de livro,\par
    \textbf{report} para Relatório científico\par
    \textbf{other} para Outros tipos de \par documentos\\
\hline
\end{tabularx}
\end{center}
\end{document}
Hi Bartman, thank you for your answer!
I have some questions:

1) What are those empty rectangles on the right of the table and above it?
2) Is there any practical difference between // and /par ?
Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Long text inside TABLE

Post by Bartman »

kettu_lissa wrote:1) What are those empty rectangles on the right of the table and above it?
See the description of the showframe package I added to the preamble.
kettu_lissa wrote:2) Is there any practical difference between \\ and \par?
Read section 15.1 \par
kettu_lissa
Posts: 5
Joined: Mon Jun 19, 2023 12:00 am

Long text inside TABLE

Post by kettu_lissa »

Ok, thanks!
But I didn't get why you did those rectangles.
I don't need those on my project x_x
Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Long text inside TABLE

Post by Bartman »

I loaded the package to check if the content of the last column extends into the right margin. Remove or comment out the command that reduces the font size in your example and you'll see what I mean.
Post Reply