4

I am trying to do a awesome sized table, however there are some difficulties I listed on the picture below:

enter image description here

  1. On 1 we my notice the word is not hyphenating automatically. The other ones are, but it is because I put the breakers \- on the text, despite I am using \RaggedRight on its line *3{>{\centering\RaggedRight\arraybackslash}p{0.9cm}|}.

  2. On 2 the word should be centered as the others, but it is not. Despite I specifically put on the code \centering, for the 3 middle columns. Line: *3{>{\centering\RaggedRight\arraybackslash}p{0.9cm}|}.

This is the code for the table, I created it based on the How to automatically force latex to not justify the text when it is not wise?'s table:

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[brazil]{babel}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage[utf8]{inputenc}

\usepackage{mathptmx}
\usepackage{hyperref}
\usepackage{xspace}
\usepackage{microtype}
\usepackage{indentfirst}
\usepackage{lettrine}
\usepackage{graphicx}
\usepackage{float}
\usepackage{array,ragged2e}

\usepackage{tabularx}
\usepackage{multirow}

\begin{document}

\section{Riscos}

    % \slash
    \noindent\makebox[\textwidth]{%
    \resizebox{1.1\linewidth}{!}{%
    \begin{tabular}{|
                     *1{>{\raggedright\arraybackslash}p{4.0cm}|} % Riscos
                     *3{>{\centering\RaggedRight\arraybackslash}p{0.9cm}|} % Probabilidade, Impacto, Prioridade
                     *2{>{\raggedright\arraybackslash}p{4.0cm}|} % Resposta, Prevenção
                    }
    \hline Riscos  & Pro\-ba\-bi\-li\-da\-de & Im\-pac\-to & Prioridade & Es\-tra\-té\-gia de res\-pos\-ta & Ações de pre\-ven\-ção \\ \hline

    % Row 1
    % Riscos
    \hline Problemas com perda de dados &

    % Probabilidade
    Baixa &

    % Impacto
    Alto &

    % Prioridade
    Alta &

    % Estratégia de resposta
    Uso do backup &

    % Ações de prevenção
    Backup periódicos \\ \hline


    % Row 2
    % Riscos
    \hline Alteração do cronograma ou descontinuidade do projeto na empresa/laboratório onde recebo uma bolsa &

    % Probabilidade
    Média &

    % Impacto
    Alto &

    % Prioridade
    Alta &

    % Estratégia de resposta
    Redefinição da data de entrega do trabalho &

    % Ações de prevenção
    Monitoramento contínuo das informações obtidas com superiores imediatos \\ \hline

    \hline \end{tabular}
    }%
    }%

\end{document}

Currently I split each column by line, therefore I can easily ready the table while reading the latex, then would this be the best readable way to build such table in plain text, keeping in mind to allow it to be easy to edit and extend?

Also this text is generating these warnings:

D:\main2.tex:73: Overfull \hbox (23.38434pt too wide) in paragraph at lines 73--73
D:\main2.tex:73: Overfull \hbox (1.82845pt too wide) in paragraph at lines 73--73
D:\main2.tex:73: Overfull \hbox (4.43913pt too wide) in paragraph at lines 73--73

Can they be fixed, while keeping my table a little more larger than the usual page size?

  • 1
    there's no reason to make that table bigger than the text width. – David Carlisle Apr 23 '17 at 7:23
  • Well, my table was very verbose so, I figure out that eating a little all that margin free space is very helpful. – user Apr 23 '17 at 20:00
  • for a personal document it doesn't really matter anyway (you could alternatively enlarge the text width for the whole document, but in most published journals or books the margin is a hard requirement. – David Carlisle Apr 23 '17 at 20:07
  • Thanks for explaining. Yeah, this document is for internal use. Would not be published on a paper. But I would not like to enlarge all the margins. For my understand of aesthetics, just that big table more specifically. – user Apr 23 '17 at 20:15
4

If you have problems with hyphenation, see if you have proper installed babel.

With manual hyphenation as you have in MWE, I obtain (after correction of columns definition) the following result:

enter image description here

I made the following changes:

  • add package changepage and with its macro adjustwidth* extend table out of outer text border
  • reduce font size to \small (this allow better hyphenation of text in cells)
  • change definition >{\centering\RaggedRight\arraybackslash}p{0.9cm} (which is wrong) to >{\Centering\arraybackslash}p{0.9cm}
  • for table use tabularx environment
  • change coulmn widths

MWE:

\documentclass[12pt]{article}
\usepackage[a4paper, margin=2cm, showframe]{geometry}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}

\usepackage{mathptmx}
\usepackage{xspace}
\usepackage{microtype}
\usepackage{indentfirst}
\usepackage{lettrine}
\usepackage{graphicx}
\usepackage{float}

\usepackage{ragged2e}
\usepackage{array, multirow, tabularx}
\usepackage[strict]{changepage}% <-- added

\usepackage{hyperref}

\begin{document}

\section{Riscos}

\begin{adjustwidth*}{}{-\marginparwidth}
    \small
    \begin{tabularx}{\linewidth}{|
                 *1{>{\RaggedRight\arraybackslash\hsize=1.1\hsize}X|} 
                 *3{>{\Centering\arraybackslash}p{1.1cm}|} % <-- corrected
                 *2{>{\RaggedRight\arraybackslash\hsize=0.95\hsize}X|} 
                    }
    \hline 
Riscos  & Pro\-ba\-bi\-li\-da\-de  & Impa\-cto & Prio\-ridade & Es\-tra\-té\-gia de res\-pos\-ta & Ações de pre\-ven\-ção \\ \hline
    % Row 1
    % Riscos
Problemas com perda de dados &
    % Probabilidade
    Baixa &

    % Impacto
    Alto &

    % Prioridade
    Alta &

    % Estratégia de resposta
    Uso do backup &

    % Ações de prevenção
    Backup periódicos \\ \hline

    % Row 2
    % Riscos
    \hline Alteração do cronograma ou descontinuidade do projeto na empresa/laboratório onde recebo uma bolsa &

    % Probabilidade
    Média &

    % Impacto
    Alto &

    % Prioridade
    Alta &

    % Estratégia de resposta
    Redefinição da data de entrega do trabalho &

    % Ações de prevenção
    Monitoramento contínuo das informações obtidas com superiores imediatos \\ 
        \hline\hline 
    \end{tabularx}
\end{adjustwidth*}%

\end{document}

Note: hyphenate text in such narrow columns is not good idea. Better solution is use some shortness and add explanation of its meaning in table caption or in footnote at end of table (for example by using threeparttable).

Addendum: in case, that you prefer symmetric expansion of table width (and not to my opinion better asymmetric to outside page border), as you can see here:

enter image description here

than you need to change only adjustwidth* macro to for example:

\begin{adjustwidth}{-0.5\marginparwidth}{-0.5\marginparwidth}
...
\end{adjustwidth}
  • Thanks, it got almost everything. It would be possible center the table, i.e., make it go out of the page border at the left and right side simultaneously? Currently it is going out of the page only for the right side, causing the table not being centered on the page. – user Apr 23 '17 at 5:33
  • of course it s possible: (i) as you have in your MWE (ii) with use of \begin{adjustwidth}{-0.5\marginparwidth}{-0.5\marginparwidth} I will add this to answer, but to my opinion, the proposed asymmetric expansion of table width is better. Inner (binding) side of table is with this solution better visible. – Zarko Apr 23 '17 at 5:45
6

I would strongly recommend that you not make a habit of making the tables any wider than the text block -- except in extreme circumstances, which do not appear to apply for the table at hand. This recommendation is all the more urgent for your current document as you're using fairly narrow narrow margins (2cm) to begin with.

Instead, you should (a) use the tabularx environment and its X column type to ensure that the table fits within the textblock, and (b) (re)define all column types suitably, as needed, to obtain a good-looking table. In addition, do omit all vertical lines and do use the booktabs package to generate well-spaced horizontal lines.

enter image description here

\documentclass[12pt]{article}
% I've tried to reduce the preamble to a bare minimum.
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[brazil]{babel}
\usepackage{newtxtext,newtxmath} % more up-to-date than 'mathptmx'
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{microtype,ragged2e,tabularx,booktabs}

\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\Centering\arraybackslash\hspace{0pt}}p{#1}}
    % the '\hspace{0pt}' directive enables hyphenation of first word of cell
\newlength\medlength
\settowidth{\medlength}{Média} % width of word "Média"

\begin{document}
\section{Riscos}

\noindent
\begin{tabularx}{\textwidth}{@{}
    *1{>{\hangafter1\hangindent1em}P{4cm}}
    *3{C{\medlength}} % or: C{1.4cm} C{0.9cm} C{1.1cm}
    *2{Y}
    @{}}
\toprule 
    Riscos & Probabilidade & Impacto & Prioridade & 
    Estratégia de resposta & Ações de prevenção \\ 
\midrule

    % Row 1
    % Riscos 
    Problemas com perda de dados &
    % Probabilidade
    Baixa &
    % Impacto
    Alto &
    % Prioridade
    Alta &
    % Estratégia de resposta
    Uso do backup &
    % Ações de prevenção
    Backup periódicos \\

\addlinespace

    % Row 2
    % Riscos
    Alteração do cronograma ou descontinuidade do projeto 
    na empresa\slash laboratório onde recebo uma bolsa &
    % Probabilidade
    Média &
    % Impacto
    Alto &
    % Prioridade
    Alta &
    % Estratégia de resposta
    Redefinição da data de entrega do trabalho &
    % Ações de prevenção
    Monitoramento contínuo das informações obtidas 
    com superiores imediatos \\ 
\bottomrule
\end{tabularx}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.