3

I got the following example:

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

\usepackage{array,ragged2e}

\begin{document}

\section{Riscos}

    \begin{tabular}{|p{2.5cm}|p{2.5cm}|p{2.0cm}|p{2.0cm}|p{2.5cm}|p{2.5cm}|}

    \hline Riscos                       & Probabilidade & Impacto & Prioridade & Resposta            & Prevenção                    \\ \hline
    \hline Problemas com notebook       & Baixa         & Médio   & Alta       & Usar desktop        & Manutenção preventiva        \\
    \hline Problemas com o desktop      & Baixa         & Alto    & Alta       & Usar o labUFSC      & Manutenção preventiva        \\
    \hline Problemas com perda de dados & Baixa         & Alto    & Alta       & Uso do backup       & Backup periódicos            \\
    \hline Problemas de Saúde           & Baixa         & Alto    & Alta       & Tratamento adequado & Cuidados diários apropriados \\ \hline

    \end{tabular}

\end{document}

Which generates this PDF:

enter image description here

The letter o as pointed on the image, must not be placed/justified on the right of the space. I think latex should be able to identify such aberration.

My question is, are there some way to force latex automatically not justify the text when the words are too much sparse like on the example just above?

I searched a lot and found that I can manually force some words to not be badly justified, however I do not like the idea to do such manually because it could be done automatically by latex itself, when certain conditions are meet, i.e. certain spacing limits are crossed.


Update

Answering the comment, I would to like latex to not justify the words if they go beyond a minimum width, and accordingly to the character count of the current line.

For example, if the line has less than 50 characters and the justification will create a hole bigger than something as 30 pixels or 6 characters, therefore the justification must not be applied for that line.

  • I’d say that TeX avoids taking this kind of decision “automatically” by design. Could you specify in greater detail what behavior you’d like to implement? By “greater detail” I mean a precise description of the different courses of action that you want to be taken and of the conditions under which each of them should be applied. – GuM Apr 20 '17 at 23:19
  • I updated the answer. What do you think about such criteria? Is it valid? Can latex do so? – user Apr 20 '17 at 23:31
  • 1
    In other words, you’d want TeX to automatically retypeset a paragraph using \raggedright (or \RaggedRight) if and only if the justification gets “too much” bad, with “too much” specified in same (even rigorous) way. Unfortunately, I’m afraid that this clashes with a known limitation of TeX: that it provides no primitive to know, at run time, the total cost of line breaking in the most recent paragraph… See @gernot’s answer for a solution that always uses \raggedright/\RaggedRight. – GuM Apr 20 '17 at 23:46
  • 1
    In TeX by Topic (eijkhout.net/texbytopic/texbytopic.html) there is an example of getting lines in a paragraph to be raggedright if they are too underful. See section 5.9.6. Perhaps this method would be suitable? – David Purton Apr 20 '17 at 23:50
  • Oww, Thanks @DavidPurton, seems to be exactly what I want to, but sadly it seems not to be done automatically by latex. I could not understand how to use it, thought. – user Apr 21 '17 at 0:00
2

Here are three versions of the table using

  • the packages array and ragged2e to insert \RaggedRight at the beginning of each cell; this leads to more possibilities for line breaks, which is useful for narrow columns.

  • the package array to insert \raggedright at the beginning of each cell; this leads to less line breaks, but the text is flush left.

  • the packages array and booktabs; this is like the second version, but without vertical lines.


array, ragged2e and \RaggedRight

enter image description here

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

\usepackage{array,ragged2e}

\begin{document}

\noindent
\begin{tabular}{|*2{>{\RaggedRight\arraybackslash}p{2.5cm}|}
                 *2{>{\RaggedRight\arraybackslash}p{2.0cm}|}
                 *2{>{\RaggedRight\arraybackslash}p{2.5cm}|}}

    \hline Riscos                       & Probabilidade & Impacto & Prioridade & Resposta            & Prevenção                    \\ \hline
    \hline Problemas com notebook       & Baixa         & Médio   & Alta       & Usar desktop        & Manutenção preventiva        \\
    \hline Problemas com o desktop      & Baixa         & Alto    & Alta       & Usar o labUFSC      & Manutenção preventiva        \\
    \hline Problemas com perda de dados & Baixa         & Alto    & Alta       & Uso do backup       & Backup periódicos            \\
    \hline Problemas de Saúde           & Baixa         & Alto    & Alta       & Tratamento adequado & Cuidados diários apropriados \\ \hline

\end{tabular}

\end{document}

array and \raggedright

enter image description here

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

\usepackage{array}

\begin{document}

\noindent
\begin{tabular}{|*2{>{\raggedright\arraybackslash}p{2.5cm}|}
                 *2{>{\raggedright\arraybackslash}p{2.0cm}|}
                 *2{>{\raggedright\arraybackslash}p{2.5cm}|}}

    \hline Riscos                       & Probabilidade & Impacto & Prioridade & Resposta            & Prevenção                    \\ \hline
    \hline Problemas com notebook       & Baixa         & Médio   & Alta       & Usar desktop        & Manutenção preventiva        \\
    \hline Problemas com o desktop      & Baixa         & Alto    & Alta       & Usar o labUFSC      & Manutenção preventiva        \\
    \hline Problemas com perda de dados & Baixa         & Alto    & Alta       & Uso do backup       & Backup periódicos            \\
    \hline Problemas de Saúde           & Baixa         & Alto    & Alta       & Tratamento adequado & Cuidados diários apropriados \\ \hline

\end{tabular}

\end{document}

array, booktabs, and \raggedright

enter image description here

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

\usepackage{array,booktabs}

\begin{document}

\noindent
\begin{tabular}{*2{>{\raggedright\arraybackslash}p{2.5cm}}
                *2{>{\raggedright\arraybackslash}p{2.0cm}}
                *2{>{\raggedright\arraybackslash}p{2.5cm}}}
\toprule
    Riscos                       & Probabilidade & Impacto & Prioridade & Resposta            & Prevenção                    \\
\midrule
    Problemas com notebook       & Baixa         & Médio   & Alta       & Usar desktop        & Manutenção preventiva        \\
\midrule
    Problemas com o desktop      & Baixa         & Alto    & Alta       & Usar o labUFSC      & Manutenção preventiva        \\
\midrule
    Problemas com perda de dados & Baixa         & Alto    & Alta       & Uso do backup       & Backup periódicos            \\
\midrule
    Problemas de Saúde           & Baixa         & Alto    & Alta       & Tratamento adequado & Cuidados diários apropriados \\
\bottomrule
\end{tabular}

\end{document}
  • It is nice to know, but I do not like hyphenations as they broken some acronyms and uncommon words. It prefer latex to left justify it, instead of. – user Apr 20 '17 at 23:45
  • @user See the second version that I just uploaded. – gernot says Reinstate Monica Apr 20 '17 at 23:46
  • @user I'd choose the third version without vertical lines. Looks just nicer. – gernot says Reinstate Monica Apr 20 '17 at 23:50
  • I prefer the version 2. I like the vertical lines, as without them seems something is missing. – user Apr 21 '17 at 0:02

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.