3

my table is overflowing my page horizontally. I need it to stay within my defined margin for the document and still be displayed completely.

I already tried the following links, but I did not succeed:

Latex table goes out of page border

Horizontal page overflow of tables

table overflow page

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

\begin{table}
\centering
\caption{Requisitos Funcionais e Não-Funcionais do Sistema}
\label{requisitosfuncionais}
\begin{tabular}{|l|l|l|l|} 
\hline
\multicolumn{1}{|c|}{\textbf{Nome}} & \multicolumn{1}{c|}{\textbf{Descrição}}                                                                                      & \multicolumn{1}{c|}{\textbf{Prioridade}} & \multicolumn{1}{c|}{\textbf{Tipo}}  \\ 
\hline
Geração Automática~                 & \begin{tabular}[c]{@{}l@{}}Capacidade de entregar ao usuário \\avaliações geradas de forma automática\end{tabular}           & Essencial                                & Funcional                           \\ 
\hline
Cadastro de Questões                & \begin{tabular}[c]{@{}l@{}}Capacidade de armazenar questões\\em um banco de dados\end{tabular}                               & Essencial                                & Funcional                           \\ 
\hline
Língua: Português                   & O Sistema deve ser todo em Português                                                                                         & Importante                               & Não-Funcional                       \\ 
\hline
Cadastro de Assuntos                & \begin{tabular}[c]{@{}l@{}}Capacidade de armazenar assuntos em\\um banco de dados\end{tabular}                               & Essencial                                & Funcional                           \\ 
\hline
Autenticação                        & \begin{tabular}[c]{@{}l@{}}Sistema só poderá ser acessado por\\usuários logados\end{tabular}                                 & Essencial                                & Não-Funcional                       \\ 
\hline
Editor de Texto                     & \begin{tabular}[c]{@{}l@{}}Capacidade de inserir questões estilizadas\\e formatas através de um editor de texto\end{tabular} & Desejável                                & Não-Funcional                       \\ 
\hline
Geração de Gabaritos                & \begin{tabular}[c]{@{}l@{}}Sistema deve entregar ao usuário um~\\gabarito para cada avaliação gerada\end{tabular}            & Importante                               & Funcional                           \\ 
\hline
Acesso Multiplataforma              & \begin{tabular}[c]{@{}l@{}}Sistema deve ser compatível com os\\diversos sistemas e softwares disponíveis\end{tabular}        & Desejável                                & Não-Funcional                       \\ 
\hline
Integridade do Dados                & \begin{tabular}[c]{@{}l@{}}Dados devem ser armazenados com\\precisão e consistência\end{tabular}                             & Essencial                                & Não-Funcional                       \\ 
\hline
Avaliações Editáveis                & \begin{tabular}[c]{@{}l@{}}Sistema deve permitir que usuário edite\\a avaliação antes de imprimir\end{tabular}               & Desejável                                & Funcional                           \\ 
\hline
Controle de Acesso                  & \begin{tabular}[c]{@{}l@{}}Cada usuário só deverá ter acesso a dados\\pertinentes a ele\end{tabular}                         & Essencial                                & Não-Funcional                       \\ 
\hline
Avaliações diferentes               & \begin{tabular}[c]{@{}l@{}}O sistema deverá ser capaz de gerar\\avaliações diferentes a cada vez~\end{tabular}               & Importante                               & Funcional                           \\
\hline
\end{tabular}
\end{table}
\end{document}
  • @Werner - I've reopened this posting as it touches on some interesting issues in addition to the main stated objective, viz., to make the tabular material fit inside the width of the textblock. – Mico Jun 27 '19 at 22:38
  • @Mico: "Interesting issues"? I still feel it's a duplicate. – Werner Jun 27 '19 at 23:26
  • @Werner - The main issue, viz., using a tabularx environment instead of a tabular environment (and X columns instead of l columns), in order to make the tabular material fit inside the textblock is definitely a duplicate. The additional issues -- maybe it's too much to call them "interesting"...-- are (a) using two different widths for the two columns of type X and (b) the deliberate non-use of vertical lines and of most horizontal lines. Handling these issues in a deft and sure manner will very much determine the overall visual appeal of the table. – Mico Jun 27 '19 at 23:34

1 Answers1

5

You've set the tabularx tab, so I will assume that you're familiar with this package and its main user environment, also called tabularx.

Some suggestions:

  • Employ a tabularx environment instead of a tabular environment, and set the overall width to \textwidth.

  • Don't use the l column type, which doesn't allow automatic line breaks, for all four columns. Instead, use l only for columns 3 and 4; use a modified form of the X column type for columns 1 and 2. That way, LaTeX will automatically find all suitable line-breaks in the first two columns automatically -- no need for those additional tabular environments...

  • Since the cells in column 2 contain much more material than those in column 1, make the width of column 2 roughly twice that of column 1. (See the code below for how to accomplish this.)

  • Don't use vertical lines; they're not needed -- really! Moreover, use only few, but well-spaced, horizontal lines. I suggest you load the booktabs package for the macros \toprule, \midrule, \bottomrule, and \addlinespace. That way, you'll create a table with a much more open and inviting "look". Your readers will be deeply grateful to you.

  • While on the subject of making the table look "open" and reader-friendly: Don't over-use bold-facing. Bold-facing is rarely, if ever, needed in a well-designed table.

enter image description here

\documentclass{article} % or some other suitable document class
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[portuguese]{babel}
\usepackage{tabularx,booktabs,ragged2e}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X} % modified 'X' col. type
\usepackage[skip=0.333\baselineskip]{caption} % optional

\begin{document}

\begin{table}[htpb]
\caption{Requisitos Funcionais e Não-Funcionais do Sistema}
\label{requisitosfuncionais}
\setlength\tabcolsep{4pt} % default: 6pt
\begin{tabularx}{\textwidth}{@{} >{\hsize=0.65\hsize}L >{\hsize=1.35\hsize}L l l @{}} 
   %% Note: 0.65+1.35 = 2 = # of columns of type X
\toprule
Nome & Descrição & Prioridade & Tipo \\ 
\midrule
Geração Automática & 
Capacidade de entregar ao usuário avaliações geradas de forma automática 
& Essencial & Funcional \\ 
\addlinespace
Cadastro de Questões & 
Capacidade de armazenar questões em um banco de dados 
& Essencial & Funcional \\ 
\addlinespace
Língua: Português & 
O Sistema deve ser todo em Português                                                                                         & Importante & Não-Funcional \\ 
\addlinespace
Cadastro de Assuntos & 
Capacidade de armazenar assuntos em um banco de dados                            
& Essencial & Funcional \\ 
\addlinespace
Autenticação & 
Sistema só poderá ser acessado por usuários logados 
& Essencial & Não-Funcional \\ 
\addlinespace
Editor de Texto &
Capacidade de inserir questões estilizadas e formatas através de um editor de texto
& Desejável & Não-Funcional \\ 
\addlinespace
Geração de Gabaritos &
Sistema deve entregar ao usuário um gabarito para cada avaliação gerada
& Importante & Funcional \\ 
\addlinespace
Acesso Multiplataforma &
Sistema deve ser compatível com os diversos sistemas e softwares disponíveis
& Desejável & Não-Funcional \\ 
\addlinespace
Integridade do Dados & 
Dados devem ser armazenados com precisão e consistência
& Essencial & Não-Funcional \\ 
\addlinespace
Avaliações Editáveis &
Sistema deve permitir que usuário edite a avaliação antes de imprimir
& Desejável & Funcional \\ 
\addlinespace
Controle de Acesso &
Cada usuário só deverá ter acesso a dados pertinentes a ele
& Essencial & Não-Funcional \\ 
\addlinespace
Avaliações diferentes &
O sistema deverá ser capaz de gerar avaliações diferentes a cada vez
& Importante & Funcional \\ 
\bottomrule
\end{tabularx}
\end{table}
\end{document}
Mico
  • 506,678
  • 1
    thanks a lot @Mico. This works very well. – Bruno Camarda Jun 27 '19 at 23:09
  • @BrunoCamarda - You're most welcome. Just out of idle curiosity: Which document class do you employ, which font and font size do you employ, and how wide is the textblock of your document? – Mico Jun 27 '19 at 23:40